Skip to content
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.

Commit a955218

Browse files
committedSep 2, 2022
Fix assorted CI issues
This fixes assorted issues highlighted by CI, like unused imports, import ordering, "malformed" docstrings, etc
1 parent ff4403c commit a955218

File tree

5 files changed

+47
-60
lines changed

5 files changed

+47
-60
lines changed
 

‎instrumentation/opentelemetry-instrumentation-grpc/src/opentelemetry/instrumentation/grpc/__init__.py

+2-2
Original file line numberDiff line numberDiff line change
@@ -119,7 +119,7 @@ def serve():
119119
interceptors = [server_interceptor()])
120120
121121
Usage Aio Client
122-
------------
122+
----------------
123123
.. code-block:: python
124124
125125
import logging
@@ -172,7 +172,7 @@ async def run():
172172
173173
174174
Usage Aio Server
175-
------------
175+
----------------
176176
.. code-block:: python
177177
178178
import logging

‎instrumentation/opentelemetry-instrumentation-grpc/src/opentelemetry/instrumentation/grpc/_aio_client.py

+6-10
Original file line numberDiff line numberDiff line change
@@ -12,24 +12,21 @@
1212
# See the License for the specific language governing permissions and
1313
# limitations under the License.
1414

15-
from collections import OrderedDict
1615
import functools
16+
from collections import OrderedDict
1717

1818
import grpc
1919
from grpc.aio import ClientCallDetails
2020

21-
from opentelemetry import context, trace
22-
from opentelemetry.semconv.trace import SpanAttributes
23-
from opentelemetry.propagate import inject
24-
from opentelemetry.instrumentation.utils import _SUPPRESS_INSTRUMENTATION_KEY
25-
from opentelemetry.instrumentation.grpc.version import __version__
26-
27-
from opentelemetry.trace.status import Status, StatusCode
28-
21+
from opentelemetry import context
2922
from opentelemetry.instrumentation.grpc._client import (
3023
OpenTelemetryClientInterceptor,
3124
_carrier_setter,
3225
)
26+
from opentelemetry.instrumentation.utils import _SUPPRESS_INSTRUMENTATION_KEY
27+
from opentelemetry.propagate import inject
28+
from opentelemetry.semconv.trace import SpanAttributes
29+
from opentelemetry.trace.status import Status, StatusCode
3330

3431

3532
def _unary_done_callback(span, code, details):
@@ -55,7 +52,6 @@ def callback(call):
5552
class _BaseAioClientInterceptor(OpenTelemetryClientInterceptor):
5653
@staticmethod
5754
def propagate_trace_in_details(client_call_details):
58-
method = client_call_details.method.decode("utf-8")
5955
metadata = client_call_details.metadata
6056
if not metadata:
6157
mutable_metadata = OrderedDict()

‎instrumentation/opentelemetry-instrumentation-grpc/src/opentelemetry/instrumentation/grpc/_aio_server.py

+9-9
Original file line numberDiff line numberDiff line change
@@ -16,8 +16,8 @@
1616

1717
from ._server import (
1818
OpenTelemetryServerInterceptor,
19-
_wrap_rpc_behavior,
2019
_OpenTelemetryServicerContext,
20+
_wrap_rpc_behavior,
2121
)
2222

2323

@@ -40,21 +40,21 @@ async def intercept_service(self, continuation, handler_call_details):
4040
def telemetry_wrapper(behavior, request_streaming, response_streaming):
4141
# handle streaming responses specially
4242
if response_streaming:
43-
return self._intercept_server_stream(
44-
behavior,
45-
handler_call_details,
46-
)
47-
else:
48-
return self._intercept_server_unary(
43+
return self._intercept_aio_server_stream(
4944
behavior,
5045
handler_call_details,
5146
)
5247

48+
return self._intercept_aio_server_unary(
49+
behavior,
50+
handler_call_details,
51+
)
52+
5353
next_handler = await continuation(handler_call_details)
5454

5555
return _wrap_rpc_behavior(next_handler, telemetry_wrapper)
5656

57-
def _intercept_server_unary(self, behavior, handler_call_details):
57+
def _intercept_aio_server_unary(self, behavior, handler_call_details):
5858
async def _unary_interceptor(request_or_iterator, context):
5959
with self._set_remote_context(context):
6060
with self._start_span(
@@ -80,7 +80,7 @@ async def _unary_interceptor(request_or_iterator, context):
8080

8181
return _unary_interceptor
8282

83-
def _intercept_server_stream(self, behavior, handler_call_details):
83+
def _intercept_aio_server_stream(self, behavior, handler_call_details):
8484
async def _stream_interceptor(request_or_iterator, context):
8585
with self._set_remote_context(context):
8686
with self._start_span(

‎instrumentation/opentelemetry-instrumentation-grpc/tests/test_aio_client_interceptor.py

+11-20
Original file line numberDiff line numberDiff line change
@@ -11,44 +11,34 @@
1111
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
1212
# See the License for the specific language governing permissions and
1313
# limitations under the License.
14-
import pytest
1514
from unittest import IsolatedAsyncioTestCase
1615

17-
import asyncio
1816
import grpc
19-
from grpc.aio import ClientCallDetails
17+
import pytest
2018

2119
import opentelemetry.instrumentation.grpc
2220
from opentelemetry import context, trace
2321
from opentelemetry.instrumentation.grpc import (
24-
aio_client_interceptors,
2522
GrpcAioInstrumentorClient,
23+
aio_client_interceptors,
24+
)
25+
from opentelemetry.instrumentation.grpc._aio_client import (
26+
UnaryUnaryAioClientInterceptor,
2627
)
27-
from opentelemetry.semconv.trace import SpanAttributes
2828
from opentelemetry.instrumentation.utils import _SUPPRESS_INSTRUMENTATION_KEY
2929
from opentelemetry.propagate import get_global_textmap, set_global_textmap
3030
from opentelemetry.semconv.trace import SpanAttributes
31-
3231
from opentelemetry.test.mock_textmap import MockTextMapPropagator
3332
from opentelemetry.test.test_base import TestBase
3433

35-
from tests.protobuf import ( # pylint: disable=no-name-in-module
36-
test_server_pb2_grpc,
37-
test_server_pb2,
38-
)
39-
from .protobuf.test_server_pb2 import Request
40-
4134
from ._aio_client import (
42-
simple_method,
43-
server_streaming_method,
44-
client_streaming_method,
4535
bidirectional_streaming_method,
36+
client_streaming_method,
37+
server_streaming_method,
38+
simple_method,
4639
)
4740
from ._server import create_test_server
48-
49-
from opentelemetry.instrumentation.grpc._aio_client import (
50-
UnaryUnaryAioClientInterceptor,
51-
)
41+
from .protobuf import test_server_pb2_grpc # pylint: disable=no-name-in-module
5242

5343

5444
class RecordingInterceptor(grpc.aio.UnaryUnaryClientInterceptor):
@@ -280,6 +270,7 @@ async def test_error_stream_stream(self):
280270
trace.StatusCode.ERROR,
281271
)
282272

273+
# pylint:disable=no-self-use
283274
async def test_client_interceptor_trace_context_propagation(self):
284275
"""ensure that client interceptor correctly inject trace context into all outgoing requests."""
285276

@@ -347,7 +338,7 @@ async def test_stream_unary_with_suppress_key(self):
347338
finally:
348339
context.detach(token)
349340

350-
async def test_stream_unary_with_suppress_key(self):
341+
async def test_stream_stream_with_suppress_key(self):
351342
token = context.attach(
352343
context.set_value(_SUPPRESS_INSTRUMENTATION_KEY, True)
353344
)

‎instrumentation/opentelemetry-instrumentation-grpc/tests/test_aio_server_interceptor.py

+19-19
Original file line numberDiff line numberDiff line change
@@ -11,34 +11,32 @@
1111
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
1212
# See the License for the specific language governing permissions and
1313
# limitations under the License.
14-
15-
# pylint:disable=unused-argument
16-
# pylint:disable=no-self-use
17-
import pytest
14+
import asyncio
1815
from unittest import IsolatedAsyncioTestCase
1916

20-
import asyncio
2117
import grpc
2218
import grpc.aio
23-
from concurrent.futures.thread import ThreadPoolExecutor
19+
import pytest
2420

25-
from time import sleep
26-
from opentelemetry.test.test_base import TestBase
27-
from opentelemetry import trace
2821
import opentelemetry.instrumentation.grpc
29-
from opentelemetry.semconv.trace import SpanAttributes
22+
from opentelemetry import trace
23+
from opentelemetry.instrumentation.grpc import (
24+
GrpcAioInstrumentorServer,
25+
aio_server_interceptor,
26+
)
3027
from opentelemetry.sdk import trace as trace_sdk
28+
from opentelemetry.semconv.trace import SpanAttributes
29+
from opentelemetry.test.test_base import TestBase
3130
from opentelemetry.trace import StatusCode
3231

3332
from .protobuf.test_server_pb2 import Request, Response
3433
from .protobuf.test_server_pb2_grpc import (
3534
GRPCTestServerServicer,
3635
add_GRPCTestServerServicer_to_server,
3736
)
38-
from opentelemetry.instrumentation.grpc import (
39-
GrpcAioInstrumentorServer,
40-
aio_server_interceptor,
41-
)
37+
38+
# pylint:disable=unused-argument
39+
# pylint:disable=no-self-use
4240

4341

4442
class Servicer(GRPCTestServerServicer):
@@ -351,6 +349,7 @@ async def test_span_lifetime(self):
351349
class SpanLifetimeServicer(GRPCTestServerServicer):
352350
# pylint:disable=C0103
353351
async def SimpleMethod(self, request, context):
352+
# pylint:disable=attribute-defined-outside-init
354353
self.span = trace.get_current_span()
355354

356355
return Response(
@@ -394,7 +393,9 @@ async def sequential_requests(channel):
394393
spans_list = self.memory_exporter.get_finished_spans()
395394
self.assertEqual(len(spans_list), 2)
396395

397-
span1, span2 = spans_list
396+
span1 = spans_list[0]
397+
span2 = spans_list[1]
398+
398399
# Spans should belong to separate traces
399400
self.assertNotEqual(span1.context.span_id, span2.context.span_id)
400401
self.assertNotEqual(span1.context.trace_id, span2.context.trace_id)
@@ -453,7 +454,9 @@ async def concurrent_requests(channel):
453454
spans_list = self.memory_exporter.get_finished_spans()
454455
self.assertEqual(len(spans_list), 2)
455456

456-
span1, span2 = spans_list
457+
span1 = spans_list[0]
458+
span2 = spans_list[1]
459+
457460
# Spans should belong to separate traces
458461
self.assertNotEqual(span1.context.span_id, span2.context.span_id)
459462
self.assertNotEqual(span1.context.trace_id, span2.context.trace_id)
@@ -501,9 +504,6 @@ async def request(channel):
501504
await run_with_test_server(request, servicer=AbortServicer())
502505

503506
spans_list = self.memory_exporter.get_finished_spans()
504-
self.assertEqual(len(spans_list), 1)
505-
child_span = spans_list[0]
506-
507507
self.assertEqual(len(spans_list), 1)
508508
span = spans_list[0]
509509

0 commit comments

Comments
 (0)
Please sign in to comment.