diff --git a/ext/opentelemetry-ext-grpc/src/opentelemetry/ext/grpc/__init__.py b/ext/opentelemetry-ext-grpc/src/opentelemetry/ext/grpc/__init__.py index 8f2ee896a4..1e187913a0 100644 --- a/ext/opentelemetry-ext-grpc/src/opentelemetry/ext/grpc/__init__.py +++ b/ext/opentelemetry-ext-grpc/src/opentelemetry/ext/grpc/__init__.py @@ -24,43 +24,41 @@ from wrapt import ObjectProxy from wrapt import wrap_function_wrapper as _wrap -class GrpcInstrumentorServer (BaseInstrumentor): + + +class GrpcInstrumentorServer(BaseInstrumentor): def _instrument(self, **kwargs): - tracer = self.get_trace(kwargs) - _wrap(grpc,'server', server_interceptor(tracer_provider = get_tracer_provider(kwargs))) - _wrap(grpc, 'secure_channel',server_interceptor(tracer_provider= get_tracer_provider(kwargs))) + # tracer = self.get_trace(kwargs) - + _wrap(grpc, 'server', server_interceptor(tracer_provider=get_tracer_provider(**kwargs))) + _wrap(grpc, 'secure_channel', server_interceptor(tracer_provider=get_tracer_provider(**kwargs))) def _uninstrument(self, **kwargs): _unwrap(grpc, 'server') - -class GrpcInstrumeentorClient (BaseInstrumentor): +class GrpcInstrumentorClient(BaseInstrumentor): def _instrument(self, **kwargs): - tracer = self.get_trace(kwargs) - _wrap(grpc,'insecure_channel', client_interceptor(tracer_provider = get_tracer_provider(kwargs))) - _wrap(grpc, 'secure_channel',client_interceptor(tracer_provider= get_tracer_provider(kwargs))) - - - + # tracer = get_tracer_provider(kwargs) + _wrap(grpc, 'insecure_channel', client_interceptor(tracer_provider=get_tracer_provider(**kwargs))) + _wrap(grpc, 'secure_channel', client_interceptor(tracer_provider=get_tracer_provider(**kwargs))) def _uninstrument(self, **kwargs): - _unwrap(grpc, 'secure_channel') _unwrap(grpc, 'insecure_channel') + def _unwrap(obj, attr): - func = getattr(obj,attr, None) + func = getattr(obj, attr, None) + + if func and isinstance(func, ObjectProxy) and hasattr(func, "__wrapped__"): + setattr(obj, attr, func.__wrapped__) - if func and isinstance(func, ObjectProxy) and hasattr(func,"__wrapped__"): - setattr(obj,attr,func.__wrapped__) -def get_tracer_provider (**kwargs): - return kwargs.get("tracer_provider") +def get_tracer_provider(**kwargs): + return kwargs.get("tracer_provider") def client_interceptor(tracer_provider=None):