Skip to content

Commit 76368f2

Browse files
committed
Move the tracer to be an attribute of the instrumentor instead of the channel
1 parent a7f118a commit 76368f2

File tree

1 file changed

+3
-3
lines changed
  • instrumentation/opentelemetry-instrumentation-pika/src/opentelemetry/instrumentation/pika

1 file changed

+3
-3
lines changed

instrumentation/opentelemetry-instrumentation-pika/src/opentelemetry/instrumentation/pika/pika_instrumentor.py

+3-3
Original file line numberDiff line numberDiff line change
@@ -83,7 +83,6 @@ def instrument_channel(
8383
)
8484
return
8585
tracer = trace.get_tracer(__name__, __version__, tracer_provider)
86-
channel.__setattr__("__opentelemetry_tracer", tracer)
8786
if not hasattr(channel, "_impl"):
8887
_LOG.error("Could not find implementation for provided channel!")
8988
return
@@ -110,8 +109,6 @@ def uninstrument_channel(channel: Channel) -> None:
110109
if hasattr(callback, "_original_callback"):
111110
channel._impl._consumers[key] = callback._original_callback
112111
PikaInstrumentor._uninstrument_channel_functions(channel)
113-
if hasattr(channel, "__opentelemetry_tracer"):
114-
delattr(channel, "__opentelemetry_tracer")
115112

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

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

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

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

0 commit comments

Comments
 (0)