Registry /
observability / opentelemetry-instrumentation-transformers
Install & Compatibility
Where this runs
tested against v0.62.3 · pip install
no network on importno background threads
Install × environment matrix
Each cell = how many times install + import succeeded across repeated harness runs. Partial = flaky.
glibc = Debian/Ubuntu slim · musl = Alpine Linux
muslpy 3.10–3.95 runs
installs and imports cleanly · install 0.0s · import 3.684s · 266.1MB
glibcpy 3.10–3.95 runs
installs and imports cleanly · install 15.3s · import 3.398s · 245MB
268MB installed
● package 268MB
Code
Verified usage
Verified import paths — ran on the pinned version, not inferred.
TransformersInstrumentor
✓ from opentelemetry.instrumentation.transformers import TransformersInstrumentor
This example sets up a basic OpenTelemetry SDK with a console exporter, then instruments the Hugging Face Transformers library. It then runs a sentiment analysis pipeline, generating traces that will be printed to the console.
import os
from opentelemetry import trace
from opentelemetry.sdk.resources import Resource
from opentelemetry.sdk.trace import TracerProvider
from opentelemetry.sdk.trace.export import (
ConsoleSpanExporter,
SimpleSpanProcessor,
)
from opentelemetry.instrumentation.transformers import TransformersInstrumentor
from transformers import pipeline
# Configure OpenTelemetry SDK
# In production, use OTLPExporter to send traces to a collector.
resource = Resource.create({"service.name": "transformers-app"})
provider = TracerProvider(resource=resource)
processor = SimpleSpanProcessor(ConsoleSpanExporter())
provider.add_span_processor(processor)
trace.set_tracer_provider(provider)
# Instrument the transformers library
TransformersInstrumentor().instrument()
# Use a transformers pipeline
print("Running transformers pipeline...")
pipe = pipeline("sentiment-analysis")
result = pipe("I love OpenTelemetry!")
print("Pipeline result:", result)
# Ensure traces are flushed before exit
provider.shutdown()
Debug
Known issues
breakingFrequent updates to OpenTelemetry Generative AI semantic conventions (semconv) may introduce breaking changes in the names and structure of span attributes. Applications consuming these traces should be prepared for attribute schema changes.fixConsult the OpenTelemetry GenAI Semantic Conventions documentation and the `opentelemetry-instrumentation-transformers` changelog to adapt to updated attribute names and structures.
affects: 0.53.0 and newer
gotchaThe `transformers` library must be installed and importable *before* `TransformersInstrumentor().instrument()` is called. If `transformers` is not present, instrumentation will fail silently or not apply.fixEnsure `pip install transformers` is executed and `import transformers` can successfully run in your environment before initializing the instrumentor.
affects: All versions
gotchaTo observe traces, a complete OpenTelemetry SDK setup (including a `TracerProvider`, `Resource`, and `SpanProcessor` with an `Exporter`) is required. Without a configured exporter, traces will be generated but not sent anywhere.fixRefer to the OpenTelemetry Python SDK documentation for proper setup of `TracerProvider`, `Resource`, and a suitable `SpanExporter` (e.g., `OTLPSpanExporter` for sending to an OTel collector).
affects: All versions
Upgrade
Version history
0.62.3latest on PyPI · released Aug 10, 2026
Audit
Dependencies
transformersrequiredThe library being instrumented by this package.
opentelemetry-apirequiredCore OpenTelemetry API for tracing.
opentelemetry-sdkrequiredOpenTelemetry SDK for provider and exporter setup.