Conversation
Log records emitted by the plugin carried no OTel context, so `Logger.emit` fell back to `context.active()`, which is always empty under opencode's event dispatch. Every `user_prompt`, `tool_result`, `api_request`, `tool_decision`, and session lifecycle log therefore exported without a trace/span id and appeared as its own root trace in backends such as Logfire instead of nesting under the session, run, tool, or LLM span that produced it. Resolve a context for every log record: an explicit `record.context` wins, otherwise the record is parented to the session/run context named by its `session.id` attribute. `tool_result` and `api_request`/`api_error` additionally nest under their tool/LLM span by attaching that span's context.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Description
OTel log records emitted by the plugin carried no
context, soLogger.emitfell back tocontext.active()— which is always empty under opencode's event dispatch. As a result everyuser_prompt,tool_result,api_request/api_error,tool_decision, and session lifecycle log exported with no trace/span id and rendered as its own root trace in backends such as Logfire, instead of nesting under the session, run, tool, or LLM span that produced it.Observed in a Logfire project (all
parent_span_id = null):This resolves a context for every emitted log record:
record.contextalways wins;session.idattribute (resolveLogContext);tool_resultnests under its tool span, andapi_request/api_errorunder their LLM span, by attaching that span's context.The SDK honours
LogRecord.context(const currentContext = logRecord.context || context.active()in@opentelemetry/sdk-logs), so the trace/span id now reaches the exporter.Type of change
Checklist
bun run lintpasses with no errorsbun run check:jsdoc-coveragepasses with no errorsbun run typecheckpasses with no errorsbun testpasses with no errorsAdditional context
Tests added cover
contextForSpanContext/resolveLogContext(explicit context wins, session/run resolution, unknown session fallback) and assert that the emittedtool_resultandapi_requestrecords carry the tool/LLM span id. Full suite: 334 pass, 0 fail.Related: #107, #109 (both concern trace-context propagation; this fix only covers the plugin's own log records).