Registry / observability / opentelemetry-instrumentation-transformers

opentelemetry-instrumentation-transformers

JSON →
library0.62.3pypypi✓ verified 23d ago

The `opentelemetry-instrumentation-transformers` library provides OpenTelemetry instrumentation for the Hugging Face Transformers library. It automatically captures traces for operations performed using Transformers models, helping to monitor and observe AI/ML application performance and behavior. The current version is 0.58.0, and it follows a rapid release cadence, often aligning with updates to OpenTelemetry's Generative AI semantic conventions.

pip install opentelemetry-instrumentation-transformers transformers
INSTALL
IMPORT
SIG · OPENTELEMETRY-INST
O
opentelemetry-instrumentation-transformers
observabilitypythonv0.62.3
Install
15.3s avg
Import
3541ms
Disk
268MB
Pass rate
10/ 10
Env Coverage10 / 10
glibc
3.93.13
musl
3.93.13
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
musl
py 3.103.95 runs
installs and imports cleanly · install 0.0s · import 3.684s · 266.1MB
glibc
py 3.103.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.
fix
Consult 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.
fix
Ensure `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.
fix
Refer 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.
Agent activity
27 hits · last 30 days
node
24
OpenAI (training)
1
Resources
opentelemetry-instrumentation-transformers — pip install opentelemetry-instrumentation-transformers · libregistry