-
Notifications
You must be signed in to change notification settings - Fork 325
feat(web): migrate Langfuse SDK to v5 (Closes #1453) #1463
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
base: main
Are you sure you want to change the base?
Changes from all commits
17ca4a5
d7b787e
68ea842
2fe231f
2008c9a
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|
| @@ -1,21 +1,26 @@ | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| import * as Sentry from '@sentry/nextjs'; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| import { registerOTel } from '@vercel/otel'; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| import { LangfuseExporter } from 'langfuse-vercel'; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| import { LangfuseSpanProcessor } from '@langfuse/otel'; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| import { NodeSDK } from '@opentelemetry/sdk-node'; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
|
||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| export async function register() { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| if ( | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| process.env.LANGFUSE_SECRET_KEY && | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| process.env.NEXT_PUBLIC_LANGFUSE_PUBLIC_KEY | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| ) { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| console.log("Registering Langfuse"); | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| registerOTel({ | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| const sdk = new NodeSDK({ | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| serviceName: 'sourcebot', | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| traceExporter: new LangfuseExporter({ | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| secretKey: process.env.LANGFUSE_SECRET_KEY, | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| publicKey: process.env.NEXT_PUBLIC_LANGFUSE_PUBLIC_KEY, | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| baseUrl: process.env.NEXT_PUBLIC_LANGFUSE_BASE_URL, | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| }), | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| spanProcessors: [ | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| new LangfuseSpanProcessor({ | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| secretKey: process.env.LANGFUSE_SECRET_KEY, | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| publicKey: process.env.NEXT_PUBLIC_LANGFUSE_PUBLIC_KEY, | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| baseUrl: process.env.NEXT_PUBLIC_LANGFUSE_BASE_URL, | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| }), | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| ], | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| }); | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| sdk.start(); | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| registerOTel({ serviceName: 'sourcebot' }); | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
cursor[bot] marked this conversation as resolved.
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. NodeSDK import unsafe on edgeMedium Severity
Reviewed by Cursor Bugbot for commit 68ea842. Configure here. There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Dual OTel SDK breaks LangfuseHigh Severity Langfuse is wired through a separate Additional Locations (1)Reviewed by Cursor Bugbot for commit 2fe231f. Configure here. |
||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Comment on lines
+3
to
24
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. 🩺 Stability & Availability | 🔴 Critical | 🏗️ Heavy lift Prevent Edge runtime crashes and OpenTelemetry provider conflicts. There are two critical issues in this OpenTelemetry setup:
If 🛠️ Proposed fix (using `@vercel/otel` directly)-import { LangfuseSpanProcessor } from '`@langfuse/otel`';
-import { NodeSDK } from '`@opentelemetry/sdk-node`';
export async function register() {
if (
process.env.LANGFUSE_SECRET_KEY &&
- process.env.NEXT_PUBLIC_LANGFUSE_PUBLIC_KEY
+ process.env.NEXT_PUBLIC_LANGFUSE_PUBLIC_KEY &&
+ process.env.NEXT_RUNTIME === 'nodejs'
) {
console.log("Registering Langfuse");
- const sdk = new NodeSDK({
- serviceName: 'sourcebot',
- spanProcessors: [
- new LangfuseSpanProcessor({
- secretKey: process.env.LANGFUSE_SECRET_KEY,
- publicKey: process.env.NEXT_PUBLIC_LANGFUSE_PUBLIC_KEY,
- baseUrl: process.env.NEXT_PUBLIC_LANGFUSE_BASE_URL,
- }),
- ],
- });
- sdk.start();
- registerOTel({ serviceName: 'sourcebot' });
+ const { LangfuseSpanProcessor } = await import('`@langfuse/otel`');
+
+ registerOTel({
+ serviceName: 'sourcebot',
+ spanProcessors: [
+ new LangfuseSpanProcessor({
+ secretKey: process.env.LANGFUSE_SECRET_KEY,
+ publicKey: process.env.NEXT_PUBLIC_LANGFUSE_PUBLIC_KEY,
+ baseUrl: process.env.NEXT_PUBLIC_LANGFUSE_BASE_URL,
+ }),
+ ],
+ });
} else {
+ registerOTel({ serviceName: 'sourcebot' });
+ }📝 Committable suggestion
Suggested change
🤖 Prompt for AI Agents |
||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
|
||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| if (process.env.NEXT_RUNTIME === 'nodejs') { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
|
||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||


Uh oh!
There was an error while loading. Please reload this page.