Skip to content

Commit

Permalink
adding grpc instrumentor class
Browse files Browse the repository at this point in the history
  • Loading branch information
aravinsiva committed Jun 8, 2020
1 parent 71ce915 commit 17741ab
Showing 1 changed file with 17 additions and 19 deletions.
36 changes: 17 additions & 19 deletions ext/opentelemetry-ext-grpc/src/opentelemetry/ext/grpc/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -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):
Expand Down

0 comments on commit 17741ab

Please sign in to comment.