{"id":2639,"library":"opentelemetry-instrumentation-mistralai","title":"OpenTelemetry Mistral AI Instrumentation","description":"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.","status":"active","version":"0.58.0","language":"en","source_language":"en","source_url":"https://github.com/traceloop/openllmetry/tree/main/packages/opentelemetry-instrumentation-mistralai","tags":["opentelemetry","instrumentation","mistralai","llm","observability","tracing","ai"],"install":[{"cmd":"pip install opentelemetry-instrumentation-mistralai mistralai","lang":"bash","label":"Install library and Mistral AI SDK"}],"dependencies":[{"reason":"This library instruments the 'mistralai' SDK; it must be installed for instrumentation to occur.","package":"mistralai","optional":false},{"reason":"Required for a functional OpenTelemetry setup to process and export traces.","package":"opentelemetry-sdk","optional":false},{"reason":"Commonly used exporter to send telemetry data to an OpenTelemetry Collector or compatible backend.","package":"opentelemetry-exporter-otlp","optional":true}],"imports":[{"note":"The class name uses 'Ai' (lowercase 'i'), not 'AI' (uppercase 'I').","wrong":"from opentelemetry.instrumentation.mistralai import MistralAIInstrumentor","symbol":"MistralAiInstrumentor","correct":"from opentelemetry.instrumentation.mistralai import MistralAiInstrumentor"}],"quickstart":{"code":"import os\nfrom opentelemetry import trace\nfrom opentelemetry.sdk.resources import Resource\nfrom opentelemetry.sdk.trace import TracerProvider\nfrom opentelemetry.sdk.trace.export import ConsoleSpanExporter, SimpleSpanProcessor\nfrom opentelemetry.instrumentation.mistralai import MistralAiInstrumentor\nfrom mistralai.client import MistralClient\nfrom mistralai.models.chat_completion import ChatMessage\n\n# Configure OpenTelemetry SDK\nresource = Resource.create({\"service.name\": \"mistralai-app\"})\ntracer_provider = TracerProvider(resource=resource)\ntracer_provider.add_span_processor(SimpleSpanProcessor(ConsoleSpanExporter()))\ntrace.set_tracer_provider(tracer_provider)\n\n# Instrument the Mistral AI library\nMistralAiInstrumentor().instrument()\n\n# Set your Mistral AI API key (replace with your actual key or env var)\nmistral_api_key = os.environ.get(\"MISTRAL_API_KEY\", \"YOUR_MISTRAL_API_KEY\")\n\nif mistral_api_key == \"YOUR_MISTRAL_API_KEY\":\n    print(\"Warning: MISTRAL_API_KEY environment variable not set. Using a placeholder.\")\n    print(\"Please set MISTRAL_API_KEY to run a real Mistral AI call.\")\nelse:\n    client = MistralClient(api_key=mistral_api_key)\n\n    try:\n        # Example Mistral AI API call\n        chat_response = client.chat(\n            model=\"mistral-tiny\",\n            messages=[\n                ChatMessage(role=\"user\", content=\"What is the capital of France?\")\n            ]\n        )\n        print(f\"Mistral AI Response: {chat_response.choices[0].message.content}\")\n    except Exception as e:\n        print(f\"Error making Mistral AI call: {e}\")\n\nprint(\"Instrumentation initialized. Check console for OpenTelemetry spans.\")","lang":"python","description":"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."},"warnings":[{"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.","message":"OpenTelemetry 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.","severity":"breaking","affected_versions":"All versions, particularly when upgrading across minor/major OpenTelemetry SDK or instrumentation versions."},{"fix":"To disable the logging of content, set the environment variable `TRACELOOP_TRACE_CONTENT=false` before running your application.","message":"By default, this instrumentation logs prompts, completions, and embeddings as span attributes. These may contain highly sensitive user data.","severity":"gotcha","affected_versions":"All versions."},{"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).","message":"This 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.","severity":"gotcha","affected_versions":"All versions."},{"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.","message":"The 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.","severity":"gotcha","affected_versions":"All versions."}],"env_vars":null,"last_verified":"2026-04-10T00:00:00.000Z","next_check":"2026-07-09T00:00:00.000Z"}