Skip to content

fix: wire tracing provider and parse Codex user messages - #52

Open
idityaGE wants to merge 1 commit into
langfuse:mainfrom
idityaGE:fix-trace-provider-user-message
Open

fix: wire tracing provider and parse Codex user messages#52
idityaGE wants to merge 1 commit into
langfuse:mainfrom
idityaGE:fix-trace-provider-user-message

Conversation

@idityaGE

@idityaGE idityaGE commented Aug 20, 2026

Copy link
Copy Markdown

Summary

Fixes two tracing correctness issues in the Codex plugin:

  • Langfuse tracing now uses the plugin's registered NodeTracerProvider, so spans created through @langfuse/tracing are exported by the configured Langfuse span processor.
  • Codex item_completed UserMessage events are now preferred when extracting the user prompt, and instruction-wrapper content is ignored as a fallback.

Fixes #51.
Fixes #47.

Why

Codex 0.147 writes the real user prompt as an item_completed event with item.type === "UserMessage". The previous parser could fall back to wrapper content such as AGENTS.md, <environment_context>, or <user_instructions>, which made the Langfuse trace input misleading.

Separately, the plugin registered its own OpenTelemetry provider but did not pass it to @langfuse/tracing. That meant Langfuse observations could be created against the global provider instead of the provider that owns the Langfuse exporter.

Changes

  • Call setLangfuseTracerProvider(provider) after registering the plugin's NodeTracerProvider.
  • Clear the Langfuse tracer provider during shutdown.
  • Extract user input from event_msg.payload.type === "item_completed" and item.type === "UserMessage".
  • Treat AGENTS.md, <environment_context>, and <user_instructions> content as instruction wrappers instead of user prompts.
  • Add regression coverage for provider wiring and prompt extraction.
  • Rebuild the committed dist/index.mjs bundle.

Testing

  • npx pnpm run format
  • npx pnpm test
  • npx pnpm run lint:tsc
  • npx pnpm run lint:dist

Manual verification

Tested with a local Langfuse Docker stack and a project-level Codex plugin config. A real Codex run from /tmp/codex-plugin-test uploaded a trace to Langfuse with:

  • root observation: Codex Turn
  • environment: local-codex-plugin-test
  • tag: codex-plugin-test
  • prompt input: List the files in this directory, read sample.txt, and summarize it in one sentence.
  • child observations: LLM, exec_command, exec_command, LLM

Screenshot:

screenshot-2026-08-20_17-39-46

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

@idityaGE

Copy link
Copy Markdown
Author

Reviewer notes: the main thing worth scrutinizing is the provider-wiring regression test. I kept it intentionally small because this plugin bundles the hook and a behavioral unit test around the global OpenTelemetry provider would be more brittle, but the source invariant is less strong than a full runtime assertion. Also worth double-checking whether there are any other Codex wrapper message shapes beyond AGENTS.md, <environment_context>, and <user_instructions>.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

1 participant