Thanks to visit codestin.com
Credit goes to github.com

Skip to content

Fix/langfuse trace name binding#80

Merged
NeverMore93 merged 3 commits into
NeverMore93:mainfrom
dotaerOne:fix/langfuse-trace-name-binding
May 19, 2026
Merged

Fix/langfuse trace name binding#80
NeverMore93 merged 3 commits into
NeverMore93:mainfrom
dotaerOne:fix/langfuse-trace-name-binding

Conversation

@dotaerOne

@dotaerOne dotaerOne commented May 19, 2026

Copy link
Copy Markdown
Contributor

fix langfuse trace name

Summary by CodeRabbit

  • New Features

    • Enhanced observability with OpenTelemetry distributed tracing: automatic span capture and propagation, and inclusion of trace IDs in telemetry/ingestion for better end-to-end traceability.
  • Chores

    • Added OpenTelemetry API library dependency and bumped package version to 1.10.10.

Review Change Stack

@coderabbitai

coderabbitai Bot commented May 19, 2026

Copy link
Copy Markdown

No actionable comments were generated in the recent review. 🎉

ℹ️ Recent review info
⚙️ Run configuration

Configuration used: defaults

Review profile: CHILL

Plan: Pro

Run ID: fadc4d64-1e70-446c-b2db-515ac18a5425

📥 Commits

Reviewing files that changed from the base of the PR and between 15bc4cd and c777e32.

⛔ Files ignored due to path filters (1)
  • package-lock.json is excluded by !**/package-lock.json
📒 Files selected for processing (2)
  • package.json
  • src/handler/chat.ts
✅ Files skipped from review due to trivial changes (1)
  • package.json
🚧 Files skipped from review as they are similar to previous changes (1)
  • src/handler/chat.ts

📝 Walkthrough

Walkthrough

The pull request adds OpenTelemetry tracing integration to the chat handler's Langfuse instrumentation. A new @opentelemetry/api dependency is added, imported, and used to read the current active span. The traceLangfuseUser function now attaches Langfuse tracing attributes to the active span and includes the span's traceId in the Langfuse ingestion payload when available. Logging is updated to report the resolved traceId.

Changes

Langfuse OpenTelemetry Integration

Layer / File(s) Summary
OpenTelemetry dependency and imports
package.json, src/handler/chat.ts
The @opentelemetry/api package (v1.9.1) is added to dependencies and the trace module is imported to enable active span inspection in the chat handler.
Active span attributes and traceBody construction
src/handler/chat.ts
The traceLangfuseUser function is updated to read the current OpenTelemetry active span, attach Langfuse-related attributes (langfuse.trace.name, langfuse.session.id, langfuse.user.id) to it, and build a traceBody object that conditionally includes the span's traceId.
Langfuse payload and tracing logging
src/handler/chat.ts
The Langfuse ingestion request payload for the trace-create batch item now uses a generated UUID for id and sends the constructed traceBody instead of a hardcoded object; success logging is adjusted to include the resolved traceId.

Estimated code review effort

🎯 2 (Simple) | ⏱️ ~10 minutes

Poem

I nibble on traces in the moonlit queue,
UUID seeds sprout where span-threads grew,
Langfuse whispers follow every hop,
OpenTelemetry hums—never a stop,
A rabbit's hop joins each observability view. 🐇✨

🚥 Pre-merge checks | ✅ 5
✅ Passed checks (5 passed)
Check name Status Explanation
Description Check ✅ Passed Check skipped - CodeRabbit’s high-level summary is enabled.
Title check ✅ Passed The pull request title 'Fix/langfuse trace name binding' accurately reflects the main change described in the commit messages and code modifications, which focus on aligning Feishu trace handling with OpenTelemetry spans and preserving the Feishu business trace name in Langfuse.
Docstring Coverage ✅ Passed Docstring coverage is 100.00% which is sufficient. The required threshold is 80.00%.
Linked Issues check ✅ Passed Check skipped because no linked issues were found for this pull request.
Out of Scope Changes check ✅ Passed Check skipped because no linked issues were found for this pull request.

✏️ Tip: You can configure your own custom pre-merge checks in the settings.

✨ Finishing Touches
🧪 Generate unit tests (beta)
  • Create PR with unit tests

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

If the error stems from missing dependencies, add them to the package.json file. For unrecoverable errors (e.g., due to private dependencies), disable the tool in the CodeRabbit configuration.

ESLint skipped: no ESLint configuration detected in root package.json. To enable, add eslint to devDependencies.


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.

❤️ Share

Comment @coderabbitai help to get the list of available commands and usage tips.

@coderabbitai coderabbitai 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.

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

📥 Commits

Reviewing files that changed from the base of the PR and between 4874468 and 15bc4cd.

⛔ Files ignored due to path filters (1)
  • package-lock.json is excluded by !**/package-lock.json
📒 Files selected for processing (2)
  • package.json
  • src/handler/chat.ts

Comment thread package.json

@gemini-code-assist gemini-code-assist 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.

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.

Comment thread src/handler/chat.ts
Comment on lines +67 to +74
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)
}

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

medium

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)
  }

liub6 added 2 commits May 19, 2026 18:22
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.
@dotaerOne dotaerOne force-pushed the fix/langfuse-trace-name-binding branch from 269e171 to 2de8e10 Compare May 19, 2026 10:29
Bump package version by one patch level to v1.10.10 and update lockfile metadata accordingly.
@NeverMore93 NeverMore93 merged commit 6d8927e into NeverMore93:main May 19, 2026
3 checks passed
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.

2 participants