Fix/langfuse trace name binding#80
Conversation
|
No actionable comments were generated in the recent review. 🎉 ℹ️ Recent review info⚙️ Run configurationConfiguration used: defaults Review profile: CHILL Plan: Pro Run ID: ⛔ Files ignored due to path filters (1)
📒 Files selected for processing (2)
✅ Files skipped from review due to trivial changes (1)
🚧 Files skipped from review as they are similar to previous changes (1)
📝 WalkthroughWalkthroughThe pull request adds OpenTelemetry tracing integration to the chat handler's Langfuse instrumentation. A new ChangesLangfuse OpenTelemetry Integration
Estimated code review effort🎯 2 (Simple) | ⏱️ ~10 minutes Poem
🚥 Pre-merge checks | ✅ 5✅ Passed checks (5 passed)
✏️ Tip: You can configure your own custom pre-merge checks in the settings. ✨ Finishing Touches🧪 Generate unit tests (beta)
Warning There were issues while running some tools. Please review the errors and either fix the tool's configuration or disable the tool if it's a critical failure. 🔧 ESLint
ESLint skipped: no ESLint configuration detected in root package.json. To enable, add Thanks for using CodeRabbit! It's free for OSS, and your support helps us grow. If you like it, consider giving us a shout-out. Comment |
There was a problem hiding this comment.
Actionable comments posted: 1
🤖 Prompt for all review comments with AI agents
Verify each finding against current code. Fix only still-valid issues, skip the
rest with a brief reason, keep changes minimal, and validate.
Inline comments:
In `@package.json`:
- Line 35: Update package.json's "version" field to reflect this dependency
change by bumping the package version (follow project semantic versioning),
ideally by running the repository's release helper: run "npm run release" to
automatically update version, create the commit and tag; ensure the resulting
package.json version change is included in the same PR before merging.
🪄 Autofix (Beta)
Fix all unresolved CodeRabbit comments on this PR:
- Push a commit to this branch (recommended)
- Create a new PR with the fixes
ℹ️ Review info
⚙️ Run configuration
Configuration used: defaults
Review profile: CHILL
Plan: Pro
Run ID: 99c24338-0f32-4e78-81d6-535ad696653f
⛔ Files ignored due to path filters (1)
package-lock.jsonis excluded by!**/package-lock.json
📒 Files selected for processing (2)
package.jsonsrc/handler/chat.ts
There was a problem hiding this comment.
Code Review
This pull request integrates OpenTelemetry tracing into the Langfuse reporting logic. Key changes include adding the @opentelemetry/api dependency, capturing active trace IDs to link Langfuse traces with OpenTelemetry spans, and attaching session and user metadata as span attributes. The update also introduces unique batch IDs and enhances logging for the ingestion process. A review comment suggested validating the span context to prevent sending invalid or non-recording trace IDs to Langfuse.
| const activeSpan = trace.getActiveSpan() | ||
| const activeTraceId = activeSpan?.spanContext().traceId | ||
|
|
||
| if (activeSpan) { | ||
| activeSpan.setAttribute("langfuse.trace.name", "支付agent") | ||
| activeSpan.setAttribute("langfuse.session.id", sessionId) | ||
| activeSpan.setAttribute("langfuse.user.id", userId) | ||
| } |
There was a problem hiding this comment.
The current implementation extracts the traceId from the active span without verifying if the span context is valid. If OpenTelemetry is initialized but no span is active, trace.getActiveSpan() may return a NonRecordingSpan with an invalid context (all zeros). Sending an invalid trace ID (e.g., "00000000000000000000000000000000") to Langfuse is likely unintended. It is recommended to check if the span is recording and if the trace ID is valid before using it.
const activeSpan = trace.getActiveSpan()
const spanContext = activeSpan?.spanContext()
const activeTraceId = spanContext && spanContext.traceId !== "00000000000000000000000000000000" ? spanContext.traceId : undefined
if (activeSpan?.isRecording()) {
activeSpan.setAttribute("langfuse.trace.name", "feishu-message")
activeSpan.setAttribute("langfuse.session.id", sessionId)
activeSpan.setAttribute("langfuse.user.id", userId)
}Attach trace-create to the active OpenTelemetry trace ID and set langfuse trace attributes on the current span so Langfuse can preserve the feishu business trace name. # Conflicts: # package-lock.json
Update the Langfuse trace name written from the Feishu handler so active OTEL span attributes and trace-create events both use 支付agent.
269e171 to
2de8e10
Compare
Bump package version by one patch level to v1.10.10 and update lockfile metadata accordingly.
fix langfuse trace name
Summary by CodeRabbit
New Features
Chores