Skip to content

Commit

Permalink
adding instrumentors to grpc autoinstrumentor
Browse files Browse the repository at this point in the history
  • Loading branch information
aravinsiva committed Jun 5, 2020
1 parent b108596 commit 71ce915
Show file tree
Hide file tree
Showing 2 changed files with 46 additions and 1 deletion.
3 changes: 3 additions & 0 deletions ext/opentelemetry-ext-grpc/setup.cfg
Original file line number Diff line number Diff line change
Expand Up @@ -50,3 +50,6 @@ test =

[options.packages.find]
where = src

opentelemetry_instrumentor =
grpc = opentelemetry.ext.grpc:GrpcInstrumentor
Original file line number Diff line number Diff line change
Expand Up @@ -16,9 +16,51 @@
# pylint:disable=import-self
# pylint:disable=no-name-in-module
# pylint:disable=relative-beyond-top-level

import grpc
from opentelemetry import trace
from opentelemetry.ext.grpc.version import __version__
from opentelemetry.auto_instrumentation.instrumentor import BaseInstrumentor
from opentelemetry.trace import get_tracer
from wrapt import ObjectProxy
from wrapt import wrap_function_wrapper as _wrap

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)))



def _uninstrument(self, **kwargs):
_unwrap(grpc, 'server')



class GrpcInstrumeentorClient (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)))




def _uninstrument(self, **kwargs):

_unwrap(grpc, 'secure_channel')
_unwrap(grpc, 'insecure_channel')

def _unwrap(obj, attr):
func = getattr(obj,attr, None)

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 client_interceptor(tracer_provider=None):
Expand Down

0 comments on commit 71ce915

Please sign in to comment.