OpenTelemetry Threading Instrumentation

Instrument threading to propagate OpenTelemetry context.

Usage

from opentelemetry.instrumentation.threading import ThreadingInstrumentor

ThreadingInstrumentor().instrument()

This library provides instrumentation for the threading module to ensure that the OpenTelemetry context is propagated across threads. It is important to note that this instrumentation does not produce any telemetry data on its own. It merely ensures that the context is correctly propagated when threads are used.

When instrumented, new threads created using threading.Thread, threading.Timer, or within futures.ThreadPoolExecutor will have the current OpenTelemetry context attached, and this context will be re-activated in the thread’s run method or the executor’s worker thread.”

class opentelemetry.instrumentation.threading.ThreadingInstrumentor(*args, **kwargs)[source]

Bases: BaseInstrumentor

instrumentation_dependencies()[source]

Return a list of python packages with versions that the will be instrumented.

The format should be the same as used in requirements.txt or pyproject.toml.

For example, if an instrumentation instruments requests 1.x, this method should look like: :rtype: Collection[str]

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

return [‘requests ~= 1.0’]

This will ensure that the instrumentation will only be used when the specified library is present in the environment.