Skip to content

Commit b6cf2e3

Browse files
aidandjAidan Jensen
authored andcommitted
Fix formatting
Signed-off-by: Aidan Jensen <[email protected]>
1 parent 9bdf76a commit b6cf2e3

File tree

3 files changed

+29
-29
lines changed

3 files changed

+29
-29
lines changed

instrumentation/opentelemetry-instrumentation-grpc/src/opentelemetry/instrumentation/grpc/_client.py

Lines changed: 12 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -25,6 +25,7 @@
2525
from typing import Callable, MutableMapping
2626

2727
import grpc
28+
2829
from opentelemetry import trace
2930
from opentelemetry.instrumentation.grpc import grpcext
3031
from opentelemetry.instrumentation.grpc._utilities import RpcInfo
@@ -77,11 +78,12 @@ def _safe_invoke(function: Callable, *args):
7778
"Error when invoking function '%s'", function_name, exc_info=ex
7879
)
7980

81+
8082
class OpenTelemetryClientInterceptor(
8183
grpcext.UnaryClientInterceptor, grpcext.StreamClientInterceptor
8284
):
8385
def __init__(
84-
self, tracer, filter_=None, request_hook=None, response_hook=None
86+
self, tracer, filter_=None, request_hook=None, response_hook=None
8587
):
8688
self._tracer = tracer
8789
self._filter = filter_
@@ -135,10 +137,10 @@ def _intercept(self, request, metadata, client_info, invoker):
135137
else:
136138
mutable_metadata = OrderedDict(metadata)
137139
with self._start_span(
138-
client_info.full_method,
139-
end_on_exit=False,
140-
record_exception=False,
141-
set_status_on_exception=False,
140+
client_info.full_method,
141+
end_on_exit=False,
142+
record_exception=False,
143+
set_status_on_exception=False,
142144
) as span:
143145
result = None
144146
try:
@@ -192,16 +194,15 @@ def intercept_unary(self, request, metadata, client_info, invoker):
192194
# the span across the generated responses and detect any errors, we wrap
193195
# the result in a new generator that yields the response values.
194196
def _intercept_server_stream(
195-
self, request_or_iterator, metadata, client_info, invoker
197+
self, request_or_iterator, metadata, client_info, invoker
196198
):
197199
if not metadata:
198200
mutable_metadata = OrderedDict()
199201
else:
200202
mutable_metadata = OrderedDict(metadata)
201203

202204
with self._start_span(
203-
client_info.full_method,
204-
end_on_exit=False
205+
client_info.full_method, end_on_exit=False
205206
) as span:
206207
inject(mutable_metadata, setter=_carrier_setter)
207208
metadata = tuple(mutable_metadata.items())
@@ -222,7 +223,8 @@ def done_callback(future, span_):
222223
except grpc.FutureCancelledError:
223224
span_.set_status(Status(StatusCode.OK))
224225
span_.set_attribute(
225-
RPC_GRPC_STATUS_CODE, grpc.StatusCode.CANCELLED.value[0]
226+
RPC_GRPC_STATUS_CODE,
227+
grpc.StatusCode.CANCELLED.value[0],
226228
)
227229
except grpc.RpcError as err:
228230
span_.set_status(Status(StatusCode.ERROR))
@@ -236,7 +238,7 @@ def done_callback(future, span_):
236238
return stream
237239

238240
def intercept_stream(
239-
self, request_or_iterator, metadata, client_info, invoker
241+
self, request_or_iterator, metadata, client_info, invoker
240242
):
241243
if not is_instrumentation_enabled():
242244
return invoker(request_or_iterator, metadata)

instrumentation/opentelemetry-instrumentation-grpc/tests/test_client_interceptor.py

Lines changed: 11 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -12,10 +12,8 @@
1212
# See the License for the specific language governing permissions and
1313
# limitations under the License.
1414
# pylint:disable=cyclic-import
15-
import logging
1615

1716
import threading
18-
import time
1917
from unittest import mock
2018

2119
import grpc
@@ -64,32 +62,32 @@ def __init__(self):
6462
pass
6563

6664
def intercept_unary_unary(
67-
self, continuation, client_call_details, request
65+
self, continuation, client_call_details, request
6866
):
6967
return self._intercept_call(continuation, client_call_details, request)
7068

7169
def intercept_unary_stream(
72-
self, continuation, client_call_details, request
70+
self, continuation, client_call_details, request
7371
):
7472
return self._intercept_call(continuation, client_call_details, request)
7573

7674
def intercept_stream_unary(
77-
self, continuation, client_call_details, request_iterator
75+
self, continuation, client_call_details, request_iterator
7876
):
7977
return self._intercept_call(
8078
continuation, client_call_details, request_iterator
8179
)
8280

8381
def intercept_stream_stream(
84-
self, continuation, client_call_details, request_iterator
82+
self, continuation, client_call_details, request_iterator
8583
):
8684
return self._intercept_call(
8785
continuation, client_call_details, request_iterator
8886
)
8987

9088
@staticmethod
9189
def _intercept_call(
92-
continuation, client_call_details, request_or_iterator
90+
continuation, client_call_details, request_or_iterator
9391
):
9492
return continuation(client_call_details, request_or_iterator)
9593

@@ -202,9 +200,7 @@ def test_unary_stream_can_be_cancel(self):
202200
RPC_METHOD: "ServerStreamingMethod",
203201
RPC_SERVICE: "GRPCTestServer",
204202
RPC_SYSTEM: "grpc",
205-
RPC_GRPC_STATUS_CODE: grpc.StatusCode.CANCELLED.value[
206-
0
207-
],
203+
RPC_GRPC_STATUS_CODE: grpc.StatusCode.CANCELLED.value[0],
208204
},
209205
)
210206

@@ -272,7 +268,9 @@ def test_stream_stream_can_be_cancel(self):
272268
self.assertEqual(len(spans), 1)
273269
span = spans[0]
274270

275-
self.assertEqual(span.name, "/GRPCTestServer/BidirectionalStreamingMethod")
271+
self.assertEqual(
272+
span.name, "/GRPCTestServer/BidirectionalStreamingMethod"
273+
)
276274
self.assertIs(span.kind, trace.SpanKind.CLIENT)
277275

278276
# Check version and name in span's instrumentation info
@@ -286,13 +284,10 @@ def test_stream_stream_can_be_cancel(self):
286284
RPC_METHOD: "BidirectionalStreamingMethod",
287285
RPC_SERVICE: "GRPCTestServer",
288286
RPC_SYSTEM: "grpc",
289-
RPC_GRPC_STATUS_CODE: grpc.StatusCode.CANCELLED.value[
290-
0
291-
],
287+
RPC_GRPC_STATUS_CODE: grpc.StatusCode.CANCELLED.value[0],
292288
},
293289
)
294290

295-
296291
def test_error_simple(self):
297292
with self.assertRaises(grpc.RpcError):
298293
simple_method(self._stub, error=True)
@@ -368,7 +363,7 @@ def invoker(_request, _metadata):
368363
self.assertEqual(span_end_mock.call_count, 1)
369364

370365
def test_client_interceptor_trace_context_propagation(
371-
self,
366+
self,
372367
): # pylint: disable=no-self-use
373368
"""ensure that client interceptor correctly inject trace context into all outgoing requests."""
374369
previous_propagator = get_global_textmap()

instrumentation/opentelemetry-instrumentation-grpc/tests/test_client_interceptor_filter.py

Lines changed: 6 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -101,9 +101,12 @@ def setUp(self):
101101
self.server.start()
102102
# use a user defined interceptor along with the opentelemetry client interceptor
103103
interceptors = [Interceptor()]
104-
self.channel = grpc.insecure_channel("localhost:25565",options=[
105-
(grpc.experimental.ChannelOptions.SingleThreadedUnaryStream, 1)
106-
])
104+
self.channel = grpc.insecure_channel(
105+
"localhost:25565",
106+
options=[
107+
(grpc.experimental.ChannelOptions.SingleThreadedUnaryStream, 1)
108+
],
109+
)
107110
self.channel = grpc.intercept_channel(self.channel, *interceptors)
108111
self._stub = test_server_pb2_grpc.GRPCTestServerStub(self.channel)
109112

0 commit comments

Comments
 (0)