Registry / observability / opentelemetry-instrumentation-mistralai

opentelemetry-instrumentation-mistralai

JSON →
library0.62.3pypypi✓ verified 23d ago

This library provides OpenTelemetry auto-instrumentation for the official Mistral AI Python SDK, allowing for tracing of LLM calls, capturing performance, token usage, and other observability data. It is part of the broader OpenLLMetry project and sees frequent releases, often on a weekly or bi-weekly basis, to keep up with changes in semantic conventions and underlying LLM SDKs.

pip install opentelemetry-instrumentation-mistralai mistralai
INSTALL
IMPORT
SIG · OPENTELEMETRY-INST
O
opentelemetry-instrumentation-mistralai
observabilitypythonv0.62.3
Install
6.9s avg
Import
2400ms
Disk
53MB
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 0.518s · 53.5MB
glibc
py 3.103.95 runs
installs and imports cleanly · install 6.9s · import 0.442s · 53MB
53MB installed
● package 53MB
Code
Verified usage

Verified import paths — ran on the pinned version, not inferred.

MistralAiInstrumentor
from opentelemetry.instrumentation.mistralai import MistralAiInstrumentor
from opentelemetry.instrumentation.mistralai import MistralAIInstrumentor
The class name uses 'Ai' (lowercase 'i'), not 'AI' (uppercase 'I').

This quickstart demonstrates how to initialize the OpenTelemetry SDK with a console exporter and then apply the `MistralAiInstrumentor` to automatically trace calls made through the Mistral AI Python SDK. Ensure `MISTRAL_API_KEY` is set in your environment for successful API calls. The `ConsoleSpanExporter` prints telemetry data directly 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.mistralai import MistralAiInstrumentor from mistralai.client import MistralClient from mistralai.models.chat_completion import ChatMessage # Configure OpenTelemetry SDK resource = Resource.create({"service.name": "mistralai-app"}) tracer_provider = TracerProvider(resource=resource) tracer_provider.add_span_processor(SimpleSpanProcessor(ConsoleSpanExporter())) trace.set_tracer_provider(tracer_provider) # Instrument the Mistral AI library MistralAiInstrumentor().instrument() # Set your Mistral AI API key (replace with your actual key or env var) mistral_api_key = os.environ.get("MISTRAL_API_KEY", "YOUR_MISTRAL_API_KEY") if mistral_api_key == "YOUR_MISTRAL_API_KEY": print("Warning: MISTRAL_API_KEY environment variable not set. Using a placeholder.") print("Please set MISTRAL_API_KEY to run a real Mistral AI call.") else: client = MistralClient(api_key=mistral_api_key) try: # Example Mistral AI API call chat_response = client.chat( model="mistral-tiny", messages=[ ChatMessage(role="user", content="What is the capital of France?") ] ) print(f"Mistral AI Response: {chat_response.choices[0].message.content}") except Exception as e: print(f"Error making Mistral AI call: {e}") print("Instrumentation initialized. Check console for OpenTelemetry spans.")
Debug
Known issues
breakingOpenTelemetry Semantic Conventions, especially for Generative AI (gen_ai.* attributes), are actively evolving. This instrumentation frequently updates to conform to the latest conventions, which may introduce changes to span attribute names or structures.
fix
Review the OpenTelemetry semantic convention documentation for LLMs. For transitional periods, consider using the `OTEL_SEMCONV_STABILITY_OPT_IN=current,http/dup` environment variable in the OpenTelemetry SDK to emit both old and new attributes simultaneously, easing migration.
affects: All versions, particularly when upgrading across minor/major OpenTelemetry SDK or instrumentation versions.
gotchaBy default, this instrumentation logs prompts, completions, and embeddings as span attributes. These may contain highly sensitive user data.
fix
To disable the logging of content, set the environment variable `TRACELOOP_TRACE_CONTENT=false` before running your application.
affects: All versions.
gotchaThis library only provides the instrumentation for `mistralai`. A full OpenTelemetry setup, including a `TracerProvider` and an exporter (e.g., OTLP exporter), is required to process and send the generated telemetry data to an observability backend. Without this, no traces will be collected or visible.
fix
Ensure you explicitly configure the OpenTelemetry SDK with a `TracerProvider` and at least one `SpanProcessor` with an appropriate `SpanExporter` (e.g., `OTLPSpanExporter` for sending to a collector).
affects: All versions.
gotchaThe instrumentation requires the `mistralai` library to be installed and compatible with the instrumentation's version. Incompatible `mistralai` SDK versions may lead to partial or no instrumentation.
fix
Always install `mistralAI` alongside the instrumentation (`pip install opentelemetry-instrumentation-mistralai mistralai`) and refer to the specific instrumentation's `pyproject.toml` or `setup.py` for exact version compatibility ranges if issues arise. Ensure your `mistralai` SDK client version is `1.0.0` or newer.
affects: All versions.
Upgrade
Version history
0.62.3latest on PyPI · released Aug 10, 2026
Audit
Dependencies
mistralairequiredThis library instruments the 'mistralai' SDK; it must be installed for instrumentation to occur.
opentelemetry-sdkrequiredRequired for a functional OpenTelemetry setup to process and export traces.
opentelemetry-exporter-otlpoptionalCommonly used exporter to send telemetry data to an OpenTelemetry Collector or compatible backend.
Agent activity
17 hits · last 30 days
node
14
Amazon
1
OpenAI (training)
1
Resources
opentelemetry-instrumentation-mistralai — pip install opentelemetry-instrumentation-mistralai · libregistry