This release is a pre-release and may not be stable for production use.
OpenTelemetry smolagents Instrumentation
This library provides OpenTelemetry instrumentation for smolagents. It wraps the model classes that run inference in your own process and emits a GenAI semantic-convention chat span and the matching metrics through opentelemetry-util-genai:
TransformersModel
VLLMModel
MLXModel
The API-backed model classes are not instrumented here. Each one calls a client library that carries its own instrumentation. Emitting a span at the smolagents layer as well would produce two chat spans for one model call, and would count the token-usage and duration metrics twice. Install the instrumentation for the client library instead:
smolagents model class |
Instrument this instead |
|---|---|
OpenAIModel, AzureOpenAIModel |
|
AmazonBedrockModel |
|
InferenceClientModel, LiteLLMModel, LiteLLMRouterModel |
the instrumentation or built-in telemetry of the client library the model calls (huggingface_hub, litellm) |
TransformersModel is the only instrumented class with a generate_stream. A streamed call gets a chat span that stays open until the caller drains the deltas. This covers both stream_outputs=True on an agent and a direct generate_stream call. The span carries gen_ai.request.stream, and the call also records the gen_ai.client.operation.time_to_first_chunk and gen_ai.client.operation.time_per_output_chunk metrics.
Known gaps:
A managed agent called from the generated code of a CodeAgent runs in a worker thread of the local Python executor. That worker does not carry the calling context, so the managed agent’s invoke_agent span starts a trace of its own instead of nesting under the manager’s span.
A subclass that inherits generate or generate_stream from one of the three classes above is instrumented. A subclass that overrides one is not: the override shadows the patched method, so the call produces no chat span.
A chat span reports no gen_ai.response.id, no gen_ai.response.model, no gen_ai.response.finish_reasons and no server.address. A runtime in this process returns the generated text and the token counts, nothing more. It also listens on no socket.
Tool calls (execute_tool) are not instrumented yet.
Installation
pip install opentelemetry-instrumentation-genai-smolagents
Usage
from opentelemetry.instrumentation.genai.smolagents import (
SmolagentsInstrumentor,
)
from smolagents import CodeAgent, TransformersModel
SmolagentsInstrumentor().instrument()
model = TransformersModel(model_id="HuggingFaceTB/SmolLM2-135M-Instruct")
agent = CodeAgent(tools=[], model=model)
agent.run("How many seconds are in a week?")
Configuration
Capture Message Content
By default, prompts and completions are not captured. To capture message content, set the environment variable OTEL_INSTRUMENTATION_GENAI_CAPTURE_MESSAGE_CONTENT to one of NO_CONTENT, SPAN_ONLY, EVENT_ONLY, or SPAN_AND_EVENT:
export OTEL_INSTRUMENTATION_GENAI_CAPTURE_MESSAGE_CONTENT=SPAN_AND_EVENT
Uploading Content to External Storage
Captured prompt and completion content can be forwarded to external storage through a completion hook instead of being recorded inline. Select the built-in upload hook and point it at a destination:
export OTEL_INSTRUMENTATION_GENAI_COMPLETION_HOOK=upload export OTEL_INSTRUMENTATION_GENAI_UPLOAD_BASE_PATH=/path/to/prompts # or gs://my_bucket
The upload hook is provided by opentelemetry-util-genai and requires its [upload] extra. See the opentelemetry-util-genai README for the other content-capture and upload options it owns.
You can also pass a hook programmatically, which takes precedence over the environment variable:
from opentelemetry.instrumentation.genai.smolagents import (
SmolagentsInstrumentor,
)
SmolagentsInstrumentor().instrument(completion_hook=my_hook)
Conformance
The scenarios that check this package against the GenAI semantic conventions live under tests/conformance/.
References
Release files for opentelemetry-instrumentation-genai-smolagents 1.2b0
For a detailed explanation of source distributions (sdists) and built distributions (wheels), please see the package formats documentation.
Source distribution (sdist)
| File | Size | Uploaded | |
|---|---|---|---|
| opentelemetry_instrumentation_genai_smolagents-1.2b0.tar.gz | 51.6 kB | Details |
Built distribution (wheel)
| File | Interpreter | ABI | Platform | Reset |
|---|---|---|---|---|
| opentelemetry_instrumentation_genai_smolagents-1.2b0-py3-none-any.whl | Python 3 | none | any | Details |
Total release size: 73.3 kB
Release files / opentelemetry_instrumentation_genai_smolagents-1.2b0.tar.gz
| Download URL | opentelemetry_instrumentation_genai_smolagents-1.2b0.tar.gz |
|---|---|
| Size | 51.6 kB |
| Tags | Source |
|
SHA-256 checksum How to use checksums |
016a9075eb54132e0244c789a2f54aaf4d4b1843dc9f9ae163f7e4e8870745e3
|
|
BLAKE2b-256 checksum How to use checksums |
0e8842d7527f363cce54df7ccc2241be57ed7bd2fb2523391271f09afe01279f
|
| Upload date | |
|
Uploaded using Trusted Publishing? What is trusted publishing? |
Yes |
| Uploaded via |
twine/7.0.0 CPython/3.13.14
|
Provenance
Provenance describes where a file came from. On PyPI, provenance is shared via attestations, which provide a verifiable record of the build or publishing details. View details, limitations and caveats.
PyPI Publish Attestation
PyPI verified that this artifact, at this checksum, originated from the publisher listed below.
Signed by GitHub Actions, verified by PyPI on Sep 24, 2026.
Transparency logRelease files / opentelemetry_instrumentation_genai_smolagents-1.2b0-py3-none-any.whl
| Download URL | opentelemetry_instrumentation_genai_smolagents-1.2b0-py3-none-any.whl |
|---|---|
| Size | 21.7 kB |
| Tags | Python 3 |
|
SHA-256 checksum How to use checksums |
5d55799ab36000d39df8fb41b24087a35938dc626c39fada577b50b94a1b349a
|
|
BLAKE2b-256 checksum How to use checksums |
2a9cb4b98738f5d22597cbb5aa15d1e292d051994c87c301b2ec4d6b92997113
|
| Upload date | |
|
Uploaded using Trusted Publishing? What is trusted publishing? |
Yes |
| Uploaded via |
twine/7.0.0 CPython/3.13.14
|
Provenance
Provenance describes where a file came from. On PyPI, provenance is shared via attestations, which provide a verifiable record of the build or publishing details. View details, limitations and caveats.
PyPI Publish Attestation
PyPI verified that this artifact, at this checksum, originated from the publisher listed below.
Signed by GitHub Actions, verified by PyPI on Sep 24, 2026.
Transparency log