Skip to content

Commit

Permalink
Move the tracer to be an attribute of the instrumentor instead of the…
Browse files Browse the repository at this point in the history
… channel
  • Loading branch information
oxeye-nikolay committed Sep 22, 2021
1 parent a7f118a commit 76368f2
Showing 1 changed file with 3 additions and 3 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -83,7 +83,6 @@ def instrument_channel(
)
return
tracer = trace.get_tracer(__name__, __version__, tracer_provider)
channel.__setattr__("__opentelemetry_tracer", tracer)
if not hasattr(channel, "_impl"):
_LOG.error("Could not find implementation for provided channel!")
return
Expand All @@ -110,8 +109,6 @@ def uninstrument_channel(channel: Channel) -> None:
if hasattr(callback, "_original_callback"):
channel._impl._consumers[key] = callback._original_callback
PikaInstrumentor._uninstrument_channel_functions(channel)
if hasattr(channel, "__opentelemetry_tracer"):
delattr(channel, "__opentelemetry_tracer")

def _decorate_channel_function(
self, tracer_provider: Optional[TracerProvider]
Expand All @@ -125,9 +122,12 @@ def wrapper(wrapped, instance, args, kwargs):

def _instrument(self, **kwargs: Dict[str, Any]) -> None:
tracer_provider: TracerProvider = kwargs.get("tracer_provider", None)
channel.__setattr__("__opentelemetry_tracer", tracer)
self._decorate_channel_function(tracer_provider)

def _uninstrument(self, **kwargs: Dict[str, Any]) -> None:
if hasattr(channel, "__opentelemetry_tracer"):
delattr(channel, "__opentelemetry_tracer")
unwrap(BlockingConnection, "channel")

def instrumentation_dependencies(self) -> Collection[str]:
Expand Down

0 comments on commit 76368f2

Please sign in to comment.