Mistral AI for Cloudflare

Adds instrumentation for the Mistral AI SDK. (default)

Import name: Sentry.mistralAIIntegration

This integration is enabled by default when tracing is enabled. If you'd like to modify your default integrations, read this.

The mistralAIIntegration adds instrumentation for the @mistralai/mistralai SDK to capture agent tracing gen_ai spans, recording model, token usage, latency, and (when enabled) inputs and outputs.

Copied
Sentry.init({
  dsn: "___PUBLIC_DSN___",
  // Tracing must be enabled for agent tracing to work.
  // `mistralAIIntegration` is then on by default; add it to `integrations` only to change its options.
  tracesSampleRate: 1.0,
});

To group multi-turn chats in Conversations and show who started them, set a conversation ID and user in every request that makes AI calls. See Tracking Conversations.

On Cloudflare, add sentryCloudflareVitePlugin() alongside Cloudflare's Vite plugin so the bundled Mistral SDK is instrumented:

vite.config.mts
Copied
import { cloudflare } from "@cloudflare/vite-plugin";
import { sentryCloudflareVitePlugin } from "@sentry/cloudflare/vite";
import { defineConfig } from "vite";

export default defineConfig({
  plugins: [cloudflare(), sentryCloudflareVitePlugin()],
});

Build-time instrumentation is enabled by default, and the plugin registers the integration in both vite dev and vite build. Keep the nodejs_compat flag enabled in your Wrangler configuration, and see the Vite plugin page for the full setup. Without the plugin, or with buildTimeInstrumentation: false, use Manual Instrumentation.

By default, tracing support is added to the following Mistral AI SDK calls:

  • chat.complete() / chat.parse() - Chat completion requests
  • chat.stream() / chat.parseStream() - Streaming chat completions
  • embeddings.create() - Embedding requests
  • agents.complete() - Agent completion requests
  • agents.stream() - Streaming agent completions

Streaming and non-streaming requests are automatically detected and handled appropriately.

  • @mistralai/mistralai: >=2.0.0 <3

Type: boolean (optional)

Records inputs to Mistral AI SDK calls (such as prompts and messages).

Defaults to true if dataCollection.genAI.inputs is true, which is the default.

Type: boolean (optional)

Records outputs from Mistral AI SDK calls (such as generated text and responses).

Defaults to true if dataCollection.genAI.outputs is true, which is the default.

Copied
Sentry.init({
  dsn: "___PUBLIC_DSN___",
  tracesSampleRate: 1.0,
  integrations: [
    Sentry.mistralAIIntegration({
      recordInputs: false,
      recordOutputs: false,
    }),
  ],
});

Import name: Sentry.instrumentMistralAiClient

If your application does not use automatic instrumentation, wrap your Mistral client after setting up Sentry. Use the returned client for all Mistral calls.

Copied
import * as Sentry from "___SDK_PACKAGE___";
Copied
import { Mistral } from "@mistralai/mistralai";

const mistral = new Mistral({ apiKey: "your-mistral-api-key" });
const client = Sentry.instrumentMistralAiClient(mistral, {
  recordInputs: false,
  recordOutputs: false,
});

const response = await client.chat.complete({
  model: "mistral-small-latest",
  messages: [{ role: "user", content: "Hello!" }],
});

Use one instrumentation approach for each client. If automatic instrumentation is already active, you don't need to wrap the client.

Was this helpful?
Help improve this content
Our documentation is open source and available on GitHub. Your contributions are welcome, whether fixing a typo (drat!) or suggesting an update ("yeah, this would be better").