Skip to content

Conversation

@RulaKhaled
Copy link
Member

@RulaKhaled RulaKhaled commented Oct 21, 2025

Adds support for LangChain manual instrumentation in @sentry/cloudflare and @sentry/vercel-edge.
To instrument LangChain operations, create a callback handler with Sentry.createLangChainCallbackHandler and pass it to your LangChain invocations.

import * as Sentry from '@sentry/cloudflare';
import { ChatAnthropic } from '@langchain/anthropic';

// Create a LangChain callback handler
const callbackHandler = Sentry.createLangChainCallbackHandler({
  recordInputs: true,   // Optional: record input prompts/messages
  recordOutputs: true   // Optional: record output responses
});

// Use with chat models
const model = new ChatAnthropic({
  model: 'claude-3-5-sonnet-20241022',
  apiKey: 'your-api-key'
});

await model.invoke('Tell me a joke', {
  callbacks: [callbackHandler]
});

The callback handler automatically creates spans for:

  • Chat model invocations (gen_ai.chat)
  • LLM invocations (gen_ai.pipeline)
  • Chain executions (gen_ai.invoke_agent)
  • Tool executions (gen_ai.execute_tool)

@RulaKhaled RulaKhaled changed the title Support vercel and cloudflare feat(cloudflare,vercel-edge): Add support for LangChain instrumentation Oct 21, 2025
@RulaKhaled RulaKhaled force-pushed the support-vercel-and-cloudflare branch from 0ea9d06 to d07f822 Compare October 21, 2025 14:04
@github-actions
Copy link
Contributor

github-actions bot commented Oct 21, 2025

size-limit report 📦

Path Size % Change Change
@sentry/browser 24.63 kB - -
@sentry/browser - with treeshaking flags 23.11 kB - -
@sentry/browser (incl. Tracing) 40.97 kB - -
@sentry/browser (incl. Tracing, Profiling) 45.26 kB - -
@sentry/browser (incl. Tracing, Replay) 79.29 kB - -
@sentry/browser (incl. Tracing, Replay) - with treeshaking flags 68.97 kB - -
@sentry/browser (incl. Tracing, Replay with Canvas) 83.99 kB - -
@sentry/browser (incl. Tracing, Replay, Feedback) 96.16 kB - -
@sentry/browser (incl. Feedback) 41.3 kB - -
@sentry/browser (incl. sendFeedback) 29.29 kB - -
@sentry/browser (incl. FeedbackAsync) 34.22 kB - -
@sentry/react 26.31 kB - -
@sentry/react (incl. Tracing) 42.97 kB - -
@sentry/vue 29.11 kB - -
@sentry/vue (incl. Tracing) 42.75 kB - -
@sentry/svelte 24.64 kB - -
CDN Bundle 26.9 kB - -
CDN Bundle (incl. Tracing) 41.62 kB - -
CDN Bundle (incl. Tracing, Replay) 77.87 kB - -
CDN Bundle (incl. Tracing, Replay, Feedback) 83.35 kB - -
CDN Bundle - uncompressed 78.86 kB - -
CDN Bundle (incl. Tracing) - uncompressed 123.44 kB - -
CDN Bundle (incl. Tracing, Replay) - uncompressed 238.48 kB - -
CDN Bundle (incl. Tracing, Replay, Feedback) - uncompressed 251.24 kB - -
@sentry/nextjs (client) 45.11 kB - -
@sentry/sveltekit (client) 41.4 kB - -
@sentry/node-core 50.75 kB +0.01% +1 B 🔺
@sentry/node 156.93 kB - -
@sentry/node - without tracing 92.63 kB -0.01% -1 B 🔽
@sentry/aws-serverless 106.35 kB -0.01% -3 B 🔽

View base workflow run

@github-actions
Copy link
Contributor

github-actions bot commented Oct 21, 2025

node-overhead report 🧳

Note: This is a synthetic benchmark with a minimal express app and does not necessarily reflect the real-world performance impact in an application.

Scenario Requests/s % of Baseline Prev. Requests/s Change %
GET Baseline 8,741 - 9,475 -8%
GET With Sentry 1,298 15% 1,349 -4%
GET With Sentry (error only) 5,944 68% 6,020 -1%
POST Baseline 1,172 - 1,189 -1%
POST With Sentry 501 43% 513 -2%
POST With Sentry (error only) 1,030 88% 1,072 -4%
MYSQL Baseline 3,193 - 3,320 -4%
MYSQL With Sentry 381 12% 431 -12%
MYSQL With Sentry (error only) 2,628 82% 2,688 -2%

View base workflow run

@RulaKhaled RulaKhaled force-pushed the support-vercel-and-cloudflare branch from d07f822 to 0a41fc8 Compare October 22, 2025 13:13
@RulaKhaled RulaKhaled force-pushed the support-vercel-and-cloudflare branch from 8320a8c to 628a513 Compare October 22, 2025 14:48
@RulaKhaled RulaKhaled marked this pull request as ready for review October 23, 2025 09:16
@cursor
Copy link

cursor bot commented Oct 23, 2025

Bug: Type Assertion Causes Runtime Mismatch

The code passes a Record object { invocation_params: invocationParams } to the tags parameter which has type string[]. While the type assertion as unknown as string[] silences the compiler, this creates a type mismatch at runtime. The callback handler expects tags to be a string array, but receives an object instead, which could cause runtime errors or incorrect behavior in the actual LangChain callback handler implementation.

Fix in Cursor Fix in Web

@cursor
Copy link

cursor bot commented Oct 23, 2025

Bug: Future Compatibility Date Causes Errors

The compatibility_date is set to "2025-06-17" which is in the future relative to the current date (10/23/2025 according to the context). This appears to be a typo and should likely be "2024-06-17" or another valid past date. A future compatibility date may cause unexpected behavior or errors in Cloudflare Workers.

Fix in Cursor Fix in Web

@RulaKhaled RulaKhaled merged commit 925a4ea into develop Oct 23, 2025
191 of 193 checks passed
@RulaKhaled RulaKhaled deleted the support-vercel-and-cloudflare branch October 23, 2025 14:04
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.

3 participants