Skip to content

feat(hook): accept caller trace tags via CC_LANGFUSE_TRACE_TAGS - #87

Merged
hassiebp merged 2 commits into
langfuse:mainfrom
milanagm:lfe-15251-no-way-to-label-a-trace-from-outside-the-hook-operator-tags
Sep 9, 2026
Merged

hassiebp merged 2 commits into
langfuse:mainfrom
milanagm:lfe-15251-no-way-to-label-a-trace-from-outside-the-hook-operator-tags

Conversation

@milanagm

@milanagm milanagm commented Sep 8, 2026 •

Copy link
Copy Markdown
Contributor

What

CC_LANGFUSE_TRACE_TAGS adds a caller's own tags to every trace, next to claude-code and the skill:* tags. The value is either a JSON array (["lane:review","env:prod"]) or a comma-separated list (lane:review,env:prod).

Blank and duplicate entries are dropped; entries over 200 characters, and anything past the first 20, are dropped with a log line.

Refs #62 and the tag half of #69. Neither is closed by this PR — see the two notes below.

Why one variable serves both issues

#69 asks for a JSON array. #62 asks for a comma-separated list and argues for tags over metadata. The reference both issues point at, the sibling codex-observability-plugin, already accepts both shapes in one variable: it parses JSON when the value starts with [ and falls back to comma splitting. This PR does the same.

Two decisions a reviewer should confirm

Tags only. The metadata half of #69 is left out on purpose. Measured against the live API: ?tags=lane:review filters correctly, while ?metadata={"lane":"review"} is silently ignored and returns unfiltered results.

Verification

End to end against a live Langfuse, same transcript and same environment variable in each run, only the hook differs:

Run CC_LANGFUSE_TRACE_TAGS tags on the trace
before, main ["lane:review","env:prod"] ['claude-code']
after ["lane:review","env:prod"] ['claude-code', 'env:prod', 'lane:review']
after lane:executor,env:staging ['claude-code', 'env:staging', 'lane:executor']
after {"lane":"review"} ['claude-code'], with a diagnostic

The before run had the variable set as well; the old hook simply does not read it. In every run the trace still exported, including the rejected one, so telemetry stays best-effort.

The lane use case from #69, checked server-side: ?tags=lane:review, ?tags=lane:executor and ?tags=lane:scheduled each return only their own session, and ?tags=env:prod returns all of them. No use of the deployment environment field.

Tests: 247 pass, up from 228. All 19 new tests fail without the change.

Linear: LFE-16088

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

Claude Code Review

This pull request is from a fork — automated review is disabled. A repository maintainer can comment @claude review to run a one-time review.

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