This release is a pre-release and may not be stable for production use.
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) |
Agent runs (invoke_agent) and tool calls (execute_tool) are not instrumented yet. A model call made inside an agent run still gets a chat span, but no agent span sits above it.
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 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.
Installation
pip install opentelemetry-instrumentation-genai-smolagents
Usage
from opentelemetry.instrumentation.genai.smolagents import (
SmolagentsInstrumentor,
)
from smolagents import TransformersModel
SmolagentsInstrumentor().instrument()
model = TransformersModel(model_id="HuggingFaceTB/SmolLM2-135M-Instruct")
model.generate(
[
{
"role": "user",
"content": [
{"type": "text", "text": "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
Download files
Download the file for your platform. If you're not sure which to choose, learn more about installing packages.
Source Distribution
Built Distribution
Filter files by name, interpreter, ABI, and platform.
If you're not sure about the file name format, learn more about wheel file names.
Copy a direct link to the current filters
File details
Details for the file opentelemetry_instrumentation_genai_smolagents-1.1b0.tar.gz.
File metadata
- Download URL: opentelemetry_instrumentation_genai_smolagents-1.1b0.tar.gz
- Upload date:
- Size: 30.6 kB
- Tags: Source
- Uploaded using Trusted Publishing? Yes
- Uploaded via:
twine/7.0.0 CPython/3.13.14
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
e18d0b9a848f2cc0694741c56589515fad819b672d112425fb5951179723454c
|
|
| MD5 |
410aeb34f5ad078bacc541e94849e0dc
|
|
| BLAKE2b-256 |
fd6da7115cb0327e479d0081d60a96913582adacce2acdd8f7d73e0f5051c09b
|
Provenance
The following attestation bundles were made for opentelemetry_instrumentation_genai_smolagents-1.1b0.tar.gz:
Publisher:
release-all.yml on open-telemetry/opentelemetry-python-genai
-
Statement:
-
Statement type:
https://in-toto.io/Statement/v1 -
Predicate type:
https://docs.pypi.org/attestations/publish/v1 -
Subject name:
opentelemetry_instrumentation_genai_smolagents-1.1b0.tar.gz -
Subject digest:
e18d0b9a848f2cc0694741c56589515fad819b672d112425fb5951179723454c - Sigstore transparency entry: 2535567901
- Sigstore integration time:
-
Permalink:
open-telemetry/opentelemetry-python-genai@8476682703b0b72f107bc3b58998a77dacc0d1d3 -
Branch / Tag:
refs/heads/main - Owner: https://github.com/open-telemetry
-
Access:
public
-
Token Issuer:
https://token.actions.githubusercontent.com -
Runner Environment:
self-hosted -
Publication workflow:
release-all.yml@8476682703b0b72f107bc3b58998a77dacc0d1d3 -
Trigger Event:
pull_request
-
Statement type:
File details
Details for the file opentelemetry_instrumentation_genai_smolagents-1.1b0-py3-none-any.whl.
File metadata
- Download URL: opentelemetry_instrumentation_genai_smolagents-1.1b0-py3-none-any.whl
- Upload date:
- Size: 20.1 kB
- Tags: Python 3
- Uploaded using Trusted Publishing? Yes
- Uploaded via:
twine/7.0.0 CPython/3.13.14
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
79124fd8ef40c0cdd33d91af423e8697d297f9a7c09e1f3dd20466afa7e9908e
|
|
| MD5 |
00fd4f82ccdc8d65b66281414c5c11c2
|
|
| BLAKE2b-256 |
e78536f732a65ee171d35cc6de8021e7d40c5eb61dcfe3f248afdcddc3cdf1ca
|
Provenance
The following attestation bundles were made for opentelemetry_instrumentation_genai_smolagents-1.1b0-py3-none-any.whl:
Publisher:
release-all.yml on open-telemetry/opentelemetry-python-genai
-
Statement:
-
Statement type:
https://in-toto.io/Statement/v1 -
Predicate type:
https://docs.pypi.org/attestations/publish/v1 -
Subject name:
opentelemetry_instrumentation_genai_smolagents-1.1b0-py3-none-any.whl -
Subject digest:
79124fd8ef40c0cdd33d91af423e8697d297f9a7c09e1f3dd20466afa7e9908e - Sigstore transparency entry: 2535568454
- Sigstore integration time:
-
Permalink:
open-telemetry/opentelemetry-python-genai@8476682703b0b72f107bc3b58998a77dacc0d1d3 -
Branch / Tag:
refs/heads/main - Owner: https://github.com/open-telemetry
-
Access:
public
-
Token Issuer:
https://token.actions.githubusercontent.com -
Runner Environment:
self-hosted -
Publication workflow:
release-all.yml@8476682703b0b72f107bc3b58998a77dacc0d1d3 -
Trigger Event:
pull_request
-
Statement type: