Skip to content

feat(hook): custom trace tags and session grouping via commands (rebase of #27) - #106

Open
atoomic wants to merge 1 commit into
langfuse:mainfrom
atoomic:pr-27-rebased
Open

atoomic wants to merge 1 commit into
langfuse:mainfrom
atoomic:pr-27-rebased

Conversation

@atoomic

@atoomic atoomic commented Oct 15, 2026

Copy link
Copy Markdown

Summary

This is #27 by @zerafachris, rebased onto current main (b5b7cc3, v1.2.1). It is the same single commit, with the original authorship kept.

It is an alternative to #27, not an addition. Merge one and close the other:

What the feature does

See #27 for the full description. In short, it adds two opt-in options, both empty by default:

  • CC_LANGFUSE_TAG_COMMAND: runs a command once per hook run. Each non-empty stdout line becomes a trace tag.
  • CC_LANGFUSE_SESSION_LABEL_COMMAND + CC_LANGFUSE_SESSION_LABEL_MODE: the first stdout line becomes a label that groups the session's traces (prefix / collapse / off).

It composes with CC_LANGFUSE_TRACE_TAGS from #87. That one covers tags the launching process already knows. This one covers tags computed at run time.

What changed in the rebase

  1. get_trace_tags(): the operator tags from feat(hook): accept caller trace tags via CC_LANGFUSE_TRACE_TAGS #87 come first, then the command tags. Both are de-duped against the tags already in the list.
  2. emit_new_turns_from_transcript(): keeps the per-session lock from fix(hook): narrow the state lock so concurrent sessions keep their turns #89. The trace_session_id default sits in front of it.
  3. main now emits through two calls: emit_and_close_ready_turns() and emit_ready_observations_of_open_turn(). Git moved trace_session_id onto the open-turn call only, so closed turns lost the label. Both calls get it now.
  4. README: docs(readme): slim the README and add a contributing guide #94 slimmed the README, and options are now documented through the userConfig descriptions in plugin.json. The README sections are dropped; the four userConfig entries stay.

Testing

uv run --with pytest pytest -q: 293 pass. One fails: tests/integration/test_state_lock_contention.py::test_entry_of_another_session_survives_the_emit. It fails on main too, so this change does not cause it.

Refs #27, #62.

🤖 Generated with Claude Code

Adds two opt-in, related config options for attributing traces to external
work items, both empty by default (no behavior change for existing users):

- CC_LANGFUSE_TAG_COMMAND: run once per hook run; each non-empty stdout line
  is merged into the trace tags (de-duped, order-preserving).
- CC_LANGFUSE_SESSION_LABEL_COMMAND + CC_LANGFUSE_SESSION_LABEL_MODE: use the
  first stdout line as a label to group the session's traces
  (prefix / collapse / off).

One script can drive both -- tags use every line, the label uses the first.
Session labeling changes only the trace grouping id; the incremental-read
state key stays on the raw session id, so relabeling never re-emits past
turns and needs no state migration. Both paths are fail-open and bounded
(timeout, tag count/length, 199-char session id cap).

Adds tests/unit/test_custom_tags.py (15 cases). Full suite green.

Co-Authored-By: Claude Opus 4.8 <noreply@anthropic.com>

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

@CLAassistant

Copy link
Copy Markdown

CLA assistant check
Thank you for your submission! We really appreciate it. Like many open source projects, we ask that you sign our Contributor License Agreement before we can accept your contribution.
You have signed the CLA already but the status is still pending? Let us recheck it.

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