Skip to content

feat(node): Add Mistral AI integration - #24243

Draft
nicohrubec wants to merge 6 commits into
developfrom
nh/mistral-integration
Draft

feat(node): Add Mistral AI integration#24243
nicohrubec wants to merge 6 commits into
developfrom
nh/mistral-integration

Conversation

@nicohrubec

@nicohrubec nicohrubec commented Sep 9, 2026

Copy link
Copy Markdown
Member

Adds a gen_ai integration for the @mistralai/mistralai v2 SDK, mirroring the OpenAI integration.

  • Automatic: Sentry.mistralAIIntegration() — default-on in Node via the orchestrion diagnostics channels
  • Manual: Sentry.instrumentMistralClient(client) — for edge runtimes

Instruments chat.complete/stream (gen_ai.chat), embeddings.create (gen_ai.embeddings), and agents.complete/stream (gen_ai.invoke_agent), including streaming, with recordInputs/recordOutputs (PII) controls. Provider mistral, origin auto.ai.mistral.

Node integration tests cover chat/embeddings/agents across default, PII-on, and explicit-options configs (ESM + CJS).

Add span-streaming (`traceLifecycle: 'stream'`) node integration tests
for a planned `@mistralai/mistralai` gen_ai integration, mirroring the
OpenAI suite. Covers chat, embeddings, agents (invoke_agent) and fim
(text_completion), across PII-off, PII-on and explicit-integration-option
variants.

These tests are expected to fail until the `mistralAIIntegration` /
`instrumentMistralClient` instrumentation is implemented (TDD step 1).

Co-Authored-By: Claude Opus 4.8 (1M context) <noreply@anthropic.com>
@github-actions

github-actions Bot commented Sep 9, 2026

Copy link
Copy Markdown
Contributor

size-limit report 📦

Path Size % Change Change
@sentry/browser 28.81 kB +0.04% +11 B 🔺
@sentry/browser - with treeshaking flags 27.12 kB +0.04% +10 B 🔺
@sentry/browser - with treeshaking flags tracing without tracing 27.01 kB +0.03% +7 B 🔺
@sentry/browser (incl. Tracing) 49.27 kB +0.12% +57 B 🔺
@sentry/browser (incl. Tracing + Span Streaming) 49.28 kB +0.12% +57 B 🔺
@sentry/browser (incl. Tracing, Profiling) 52.21 kB +0.17% +84 B 🔺
@sentry/browser (incl. Tracing, Replay) 88.81 kB +0.05% +44 B 🔺
@sentry/browser (incl. Tracing, Replay) - with treeshaking flags 77.99 kB +0.05% +33 B 🔺
@sentry/browser (incl. Tracing, Replay with Canvas) 93.49 kB +0.06% +51 B 🔺
@sentry/browser (incl. Tracing, Replay, Feedback) 106.44 kB +0.07% +67 B 🔺
@sentry/browser (incl. Feedback) 46.3 kB +0.02% +5 B 🔺
@sentry/browser (incl. sendFeedback) 33.87 kB +0.02% +6 B 🔺
@sentry/browser (incl. FeedbackAsync) 38.99 kB +0.04% +13 B 🔺
@sentry/browser (incl. Metrics) 29.84 kB +0.08% +23 B 🔺
@sentry/browser (incl. Logs) 30.1 kB +0.06% +18 B 🔺
@sentry/browser (incl. Metrics & Logs) 30.78 kB +0.11% +31 B 🔺
@sentry/react 30.57 kB +0.05% +14 B 🔺
@sentry/react (incl. Tracing) 51.64 kB +0.16% +78 B 🔺
@sentry/vue 36.07 kB +0.05% +17 B 🔺
@sentry/vue (incl. Tracing) 51.56 kB +0.16% +82 B 🔺
@sentry/svelte 28.85 kB +0.06% +15 B 🔺
CDN Bundle 30.56 kB +0.05% +15 B 🔺
CDN Bundle (incl. Tracing) 49.81 kB +0.15% +73 B 🔺
CDN Bundle (incl. Logs, Metrics) 32.83 kB +0.03% +9 B 🔺
CDN Bundle (incl. Tracing, Logs, Metrics) 51.77 kB +0.14% +71 B 🔺
CDN Bundle (incl. Replay, Logs, Metrics) 73.48 kB -0.01% -4 B 🔽
CDN Bundle (incl. Tracing, Replay) 87.35 kB +0.08% +63 B 🔺
CDN Bundle (incl. Tracing, Replay, Logs, Metrics) 89.26 kB +0.1% +82 B 🔺
CDN Bundle (incl. Tracing, Replay, Feedback) 93.28 kB +0.07% +59 B 🔺
CDN Bundle (incl. Tracing, Replay, Feedback, Logs, Metrics) 95.27 kB +0.07% +65 B 🔺
CDN Bundle - uncompressed 90.47 kB +0.01% +8 B 🔺
CDN Bundle (incl. Tracing) - uncompressed 148.36 kB +0.13% +189 B 🔺
CDN Bundle (incl. Logs, Metrics) - uncompressed 97.04 kB +0.01% +8 B 🔺
CDN Bundle (incl. Tracing, Logs, Metrics) - uncompressed 154.32 kB +0.13% +189 B 🔺
CDN Bundle (incl. Replay, Logs, Metrics) - uncompressed 226.3 kB +0.01% +8 B 🔺
CDN Bundle (incl. Tracing, Replay) - uncompressed 267.95 kB +0.08% +189 B 🔺
CDN Bundle (incl. Tracing, Replay, Logs, Metrics) - uncompressed 273.9 kB +0.07% +189 B 🔺
CDN Bundle (incl. Tracing, Replay, Feedback) - uncompressed 281.65 kB +0.07% +189 B 🔺
CDN Bundle (incl. Tracing, Replay, Feedback, Logs, Metrics) - uncompressed 287.59 kB +0.07% +189 B 🔺
@sentry/nextjs (client) 54.09 kB +0.16% +84 B 🔺
@sentry/sveltekit (client) 49.73 kB +0.15% +71 B 🔺
@sentry/core/server 36.99 kB - -
@sentry/core/browser 13.55 kB - -
@sentry/node 128.5 kB +0.56% +714 B 🔺
@sentry/node/import (ESM hook with diagnostics-channel injection) 81.72 kB +0.13% +103 B 🔺
@sentry/node - without tracing 88.88 kB +0.19% +162 B 🔺
@sentry/node - without channel injection 107.76 kB +0.69% +732 B 🔺
@sentry/aws-serverless 97.26 kB +0.17% +165 B 🔺
@sentry/cloudflare (withSentry) - minified 202.05 kB +0.04% +74 B 🔺
@sentry/cloudflare (withSentry) 502.91 kB +0.05% +232 B 🔺

View base workflow run

Instrument `@mistralai/mistralai` v2 with gen_ai spans, turning the
previously-failing integration tests green.

- Automatic `mistralAIIntegration()` via the orchestrion diagnostics
  channels (default-on in Node)
- Manual `instrumentMistralClient()` proxy for edge runtimes
- Covers chat, embeddings, agents (invoke_agent) and fim
  (text_completion), including streaming, with `recordInputs` /
  `recordOutputs` controls

Mistral's typed responses/usage are camelCase, so the response/stream
mapping reads `promptTokens`/`completionTokens`/`totalTokens` and
`choices[].finishReason` directly. `@mistralai/mistralai` v2 is ESM-only,
so the CJS test variants are marked `failsOnCjs`.

Co-Authored-By: Claude Opus 4.8 (1M context) <noreply@anthropic.com>

@cursor cursor Bot left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Stale Bugbot comment from a previous run.

for (const choice of chunk.choices ?? []) {
if (recordOutputs && typeof choice.delta?.content === 'string' && choice.delta.content) {
state.responseTexts.push(choice.delta.content);
}

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Stream output drops chunk arrays

Low Severity

processChunk only records choice.delta.content when it is a non-empty string, but MistralCompletionChunk types that field as string | Array | null. Non-streaming responses go through contentToString, which flattens text chunks. Streamed structured content is therefore omitted from gen_ai.response.text when output recording is on.

Additional Locations (1)
Fix in Cursor Fix in Web

Reviewed by Cursor Bugbot for commit bc0fbe4. Configure here.

- Remove `failsOnCjs` from the Mistral suite: CJS auto-instrumentation
  works on a full build (it only failed under a partial local rebuild),
  so the tests pass in both ESM and CJS.
- Re-export `mistralAIIntegration` / `instrumentMistralClient` from the
  dependent SDK packages (aws-serverless, bun, elysia, deno,
  google-cloud-serverless, astro, cloudflare, vercel-edge) so the
  node-exports consistency check passes.
- Add `Mistral` to the Deno default-integrations snapshot.

Co-Authored-By: Claude Opus 4.8 (1M context) <noreply@anthropic.com>

@cursor cursor Bot left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Cursor Bugbot has reviewed your changes and found 1 potential issue.

There are 2 total unresolved issues (including 1 from previous review).

Fix All in Cursor

❌ Bugbot Autofix is OFF. To automatically fix reported issues with cloud agents, enable autofix in the Cursor dashboard.

Reviewed by Cursor Bugbot for commit cd4eb98. Configure here.

Comment thread dev-packages/node-integration-tests/suites/tracing/mistral/test.ts
@nicohrubec nicohrubec changed the title test(node): Add failing integration tests for Mistral AI SDK feat(node): Add Mistral AI integration Sep 9, 2026
nicohrubec and others added 3 commits September 9, 2026 15:31
Exclude the fim endpoints for now — `text_completion` is not yet used by
any other AI integration, so defer it to a follow-up. Remaining scope:
chat, embeddings, and agents.

Co-Authored-By: Claude Opus 4.8 (1M context) <noreply@anthropic.com>
`@mistralai/mistralai` v2 ships no CJS build, so CJS consumers load it via
`require(esm)`, whose auto-instrumentation is inconsistent across Node
versions (works on 24/26, fails on 22). The SDK's native mode is ESM, so
use `createEsmTests` and cover it there only.

Also give the embeddings mock a distinct id per call shape so the
single-input span is targeted unambiguously.

Co-Authored-By: Claude Opus 4.8 (1M context) <noreply@anthropic.com>
`@langchain/mistralai` drives the `@mistralai/mistralai` SDK under the
hood, so with the LangChain integration active both it and
`mistralAIIntegration` would instrument the same call, producing two
spans. Add `Mistral` to LangChain's `SKIPPED_PROVIDERS`, matching the
existing OpenAI/Anthropic/Google handling. This also puts the previously
unused `MISTRAL_INTEGRATION_NAME` constant to use.

Co-Authored-By: Claude Opus 4.8 (1M context) <noreply@anthropic.com>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant