mistralM

Docs

sideBar

Quickstart: send your first trace

Instrument a Python script with the Mistral SDK, send a first trace to Studio, and find it in the Trace Explorer.

This quickstart instruments a Python script with the Mistral SDK, sends one traced request, and shows you the trace in the Studio Trace Explorer. A trace is a tree of spans: each span is one step of the request, with its input, output, latency, and token counts.

You need Python 3.10 or later, uvarrowUpRight, and a Mistral API keyarrowUpRight.

Install the SDK

Create a project and add the Mistral SDK with its telemetry extra:

uv init first-trace && cd first-trace
uv add "mistralai[telemetry]"
export MISTRAL_API_KEY="your-api-key"

Send a traced request

Replace the content of main.py with this script. configure_telemetry turns on tracing for the client. The script then wraps one chat request and one simulated tool call in a parent span, so the trace has several steps:

import os

from mistralai.client import Mistral
from mistralai.extra.observability import configure_telemetry, get_telemetry_tracer

client = Mistral(api_key=os.environ["MISTRAL_API_KEY"])
configure_telemetry(client)
tracer = get_telemetry_tracer(client, "first-trace")

with tracer.start_as_current_span("invoke_agent"):
    response = client.chat.complete(
        model="mistral-small-latest",
        messages=[{"role": "user", "content": "Explain distributed tracing in one sentence."}],
    )
    print(response.choices[0].message.content)

    with tracer.start_as_current_span("execute_tool web_search") as tool_span:
        tool_span.set_attribute("gen_ai.operation.name", "execute_tool")
        tool_span.set_attribute("gen_ai.tool.name", "web_search")
        tool_span.set_attribute("gen_ai.tool.call.arguments", "distributed tracing")

Run it:

uv run main.py

The script prints the model's answer. The SDK traces the chat request automatically. Tool calls aren't traced automatically, which is why the script adds the execute_tool span itself.

You should see

Open the Trace ExplorerarrowUpRight in Studio. The trace appears within a few seconds. Click it to open the span tree:

  • invoke_agent, the parent span you created.
  • Under it, the chat request, with the prompt, the answer, the model, the latency, and the input and output token counts.
  • The execute_tool web_search span, with the tool name and arguments you set.

Spans are redacted on the client before export: by default, the SDK masks recognized secrets and personal data, such as API keys and email addresses, and keeps the rest of the content. See Data redaction.

If no trace appears, check that:

  • 1.

    You called configure_telemetry(client) before the first request.
  • 2.

    Your organization is on the Enterprise tier, and an Org Admin hasn't disabled observability.
  • 3.

    Your workspace role is Org Admin, Workspace Admin, or Observability Viewer.

Traces are kept for 30 days.

Going further

Send traces from other sources
illustrationRadar

Send traces from other sources

Instrument Mistral products, the Mistral SDK, and your own code to send OpenTelemetry traces to Mistral.

Explore traces
illustrationSatellite

Explore traces

Search, filter, and inspect traces and spans in the Trace Explorer, and turn spans into dataset records.

Data redaction
illustrationGear

Data redaction

How client-side redaction scrubs secrets and personally identifiable information from spans before they leave your environment.

Quickstart: score your first span with online evaluations
illustrationRocket

Quickstart: score your first span with online evaluations

Score your first span end to end with curl.

Quickstart: run your first evaluation
illustrationMicroscope

Quickstart: run your first evaluation

Evaluate a prompt on a small dataset with the Evaluation SDK, then read the scores in your terminal and in Studio.