pip install mistralai-otel-observability==0.3.1 Copy PIP instructions
Manual, OTLP-first observability helpers for GenAI applications.
The package installs into mistralai.observability.otel and owns private OpenTelemetry providers for traces, metrics, and logs. It does not install global tracer or meter providers and does not configure Python logging.
from mistralai.observability.otel import ObservabilityConfig, observability from mistralai.observability.otel import semconv_constants as genai observability.configure( ObservabilityConfig( service_name="my-app", endpoint="http://localhost:4318", protocol="http/protobuf", ) ) with observability.operation( genai.OPERATION_NAME_CHAT, model="mistral-large-latest", provider=genai.PROVIDER_NAME_MISTRAL_AI, include_content=True, ) as chat: chat.completion( response_model="mistral-large-latest", output_messages=[{"role": "assistant", "content": "Bonjour!"}], input_tokens=12, output_tokens=4, ) observability.shutdown() The first argument to observability.operation(...) is the GenAI operation name from the semantic conventions. For a chat completion, genai.OPERATION_NAME_CHAT is recorded as gen_ai.operation.name on the operation span, inference detail log, token usage metric, and operation duration metric. The high-level Mistral helper keeps using that same operation context:
with observability.operation( genai.OPERATION_NAME_CHAT, model="mistral-large-latest", provider=genai.PROVIDER_NAME_MISTRAL_AI, include_content=True, ) as chat: response = client.chat.complete(model="mistral-large-latest", messages=messages) chat.mistral_completion(response, messages=messages) In that example:
By default, completion helpers are metadata-only on the span: gen_ai.input.messages and gen_ai.output.messages are omitted unless the operation is created with include_content=True. operation.inference_details(...) is different: it is always explicit and emits the messages, prompt, or completion content that you pass to it.
The same Operation object can also be managed explicitly:
Agent, tool, and plan spans are specialized Operation helpers:
with observability.agent("Support Agent", model="mistral-large-latest") as agent: with observability.plan("Support Agent", parent=agent): pass with observability.tool( "lookup_customer", parent=agent, tool_type=genai.TOOL_TYPE_FUNCTION, arguments={"customer_id": "cus_123"}, result={"tier": "enterprise"}, ): pass observability.agent(...) records an invoke_agent span. By default it is INTERNAL, which matches in-process agent frameworks. Pass remote=True for remote hosted agent calls, which records a CLIENT span. observability.create_agent(...) records a create_agent CLIENT span for hosted agent creation. observability.tool(...) records an execute_tool INTERNAL span with tool name, call id, type, arguments, result, description, and the executing agent name when provided. observability.plan(...) records a plan INTERNAL span for an agent planning or task-decomposition phase. It does not emit a duration metric because the GenAI semantic conventions do not define one for plan spans. Workflow spans are intentionally not exposed as a high-level helper yet. The semantic convention says to use invoke_workflow only when instrumentation can reliably distinguish a coordinated multi-agent workflow from an agent invocation, and that boundary is application/framework-specific. Use observability.span(...) for arbitrary local work that should appear in traces but is not a GenAI operation:
Callers that reconstruct a span's identity from serialized or stored records can emit it without a live span handle, including across process boundaries. Create the operation with its parent's trace_id and parent_span_id, start it with set_current_context=False, a stable 16-hex span_id, and start_time_unix_nano, then call end(end_time_unix_nano=...). Each emission of the same record exports a span with the same span id, so backends can deduplicate repeats. The duration metric uses the recorded timestamps. For a root operation, pass a 32-hex trace_id to start() instead of a parent, and links to relate it to the span that caused it.
ObservabilityConfig.sampler replaces the default parent-based sampler, for example ALWAYS_ON for an isolated user-facing pipeline whose explicit parents may be unsampled operationally.
To prevent known secrets and PII from reaching OpenTelemetry accidentally, the SDK enables RegexRedactionPolicy by default. It inspects operation data before it is serialized into span attributes or passed to any other OpenTelemetry recording API. Hosts can replace it with another policy:
observability.configure( ObservabilityConfig(service_name="my-app"), operation_data_transformers=[], ) The built-in policies:
The default pattern and key sets are exported as DEFAULT_PII_SECRET_PATTERNS, DEFAULT_TOKEN_PATTERNS, DEFAULT_SENSITIVE_ATTRIBUTE_KEYS, DEFAULT_SENSITIVE_ATTRIBUTE_FRAGMENTS, and DEFAULT_SAFE_ATTRIBUTE_KEYS, so hosts can extend the shared catalogue instead of replacing it.
Policies receive structured values before the SDK serializes them into span attributes or creates OTel logs. Policy failures omit only the affected value. The chain applies to operation spans, child spans, logs, events, metrics, and exception details. It does not apply to standalone low-level observability.span(...) or ObservabilitySDK.record_* calls that are not scoped to an Operation.
Configure the SDK with the Mistral telemetry OTLP HTTP endpoint:
With protocol="http/protobuf", the SDK sends the three OTLP signals to:
The base package installs HTTP/protobuf export support. For custom collectors that require OTLP/gRPC, install the grpc extra and set protocol="grpc" in ObservabilityConfig.
Call observability.shutdown() when the application is done with the SDK. It performs a final flush before closing the owned OpenTelemetry providers. Use observability.flush() directly only when the process should keep running but you need telemetry exported at a specific checkpoint.
The helper is equivalent to this explicit OTLP configuration:
import os from mistralai.observability.otel import ObservabilityConfig, observability observability.configure( ObservabilityConfig( service_name="my-genai-service", service_version="1.2.3", endpoint="https://api.mistral.ai/telemetry", protocol="http/protobuf", headers={"Authorization": f"Bearer {os.environ['MISTRAL_API_KEY']}"}, ) ) Run a live Mistral completion and record it through this SDK:
MISTRAL_API_KEY=... uv run --extra mistral python examples/mistral_completion.py Explicit dataclasses such as Operation, InferenceDetails, and TokenUsage are also available for code that needs the full OpenTelemetry shape, including distinct request and response model attributes.
Use standard OpenTelemetry propagation helpers, such as opentelemetry.propagate.extract(...), when reading inbound trace context. When no explicit context is passed to SDK methods, the current OpenTelemetry context is used so upstream traceparent values are preserved.
Releases run from the OTLP Observability SDK workflow via Run workflow (workflow_dispatch), not by pushing a tag. The package version is not stored in code: it is derived from the release tag through uv-dynamic-versioning (tag prefix otel-observability-sdk/) and stamped onto the build at release time, so cutting a release never needs a version-bump PR.
The workflow validates the ref and version, fails fast if otel-observability-sdk/v already exists, then builds the package once. A reviewer must approve the observability-publish GitHub Environment before the same artifact is published to the selected indexes (Gemfury and/or public PyPI); PyPI publishes from a clean job via trusted publishing. Once at least one selected index publishes successfully, the workflow creates the otel-observability-sdk/v tag to record the released commit.
For dogfooding, publish an rc version (for example 1.0.0rc1) to Gemfury only by unticking publish_pypi; the rc is still tagged so the build is traceable to a commit. The otel-observability-sdk/vX.Y.Z tag prefix is intentionally distinct from the older observability-sdk/vX.Y.Z release line used by the AI Studio observability SDK, and this package does not publish to Cloudsmith.
The mistralconv module includes JSON-dict converters between Mistral chat completion messages and the OpenTelemetry GenAI gen_ai.input.messages / gen_ai.output.messages shape:
ai llm mistral observability opentelemetry otlp
For a detailed explanation of source distributions (sdists) and built distributions (wheels), please see the package formats documentation.
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 verified that this artifact, at this checksum, originated from the publisher listed below.
Signed by GitHub Actions, verified by PyPI on Oct 15, 2026.




