Skip to content

feat: opencode trace, close #1740#1744

Merged
looplj merged 1 commit into
unstablefrom
dev-tmp
May 29, 2026
Merged

feat: opencode trace, close #1740#1744
looplj merged 1 commit into
unstablefrom
dev-tmp

Conversation

@looplj

@looplj looplj commented May 29, 2026

Copy link
Copy Markdown
Owner

@greptile-apps

greptile-apps Bot commented May 29, 2026

Copy link
Copy Markdown
Contributor

Greptile Summary

This PR adds OpenCode trace extraction support by reading the x-session-affinity request header when opencode_trace_enabled is set to true, following the same pattern used for Claude Code and Codex tracing.

  • Adds OpenCodeTraceEnabled config field to tracing.Config (defaults false) and the corresponding setDefaults entry in conf.go.
  • Implements tryExtractTraceIDFromOpenCodeRequest in the trace middleware, inserted between the primary header check and the ClaudeCode check in priority order.
  • Adds three integration tests covering: feature-flag disabled, header-sets-trace, and primary-header-takes-precedence scenarios.

Confidence Score: 5/5

Safe to merge; the new extractor is gated behind a feature flag that defaults to false, so existing deployments are unaffected.

The change is additive and opt-in. The extractor follows the same shape as the Codex extractor, is well-tested, and the feature flag defaults to false so no existing behavior changes on upgrade.

internal/server/middleware/trace.go — the extractor is missing whitespace trimming (noted in prior review threads) and has no trace-ID format validation, unlike the ClaudeCode path.

Important Files Changed

Filename Overview
internal/server/middleware/trace.go Adds tryExtractTraceIDFromOpenCodeRequest; missing strings.TrimSpace (unlike Codex) and no format validation on the returned header value.
internal/tracing/tracing.go Adds OpenCodeTraceEnabled bool field with proper conf/yaml/json tags, consistent with existing fields.
conf/conf.go Adds server.trace.opencode_trace_enabled default (false), consistent with other trace feature-flag defaults.
internal/server/middleware/trace_test.go Three new integration tests cover disabled, enabled, and priority-ordering scenarios; good coverage for the new extractor.

Sequence Diagram

sequenceDiagram
    participant Client as OpenCode Client
    participant MW as WithTrace Middleware
    participant Ext as tryExtractTraceIDFromOpenCodeRequest
    participant DB as TraceService

    Client->>MW: POST /v1/chat/completions x-session-affinity: session-id
    MW->>MW: getTraceIDFromHeader() → empty
    MW->>Ext: "config.OpenCodeTraceEnabled == true"
    Ext->>Ext: c.GetHeader("x-session-affinity")
    Ext-->>MW: "traceID = session-id"
    MW->>DB: GetOrCreateTrace(projectID, traceID)
    DB-->>MW: trace entity
    MW->>MW: contexts.WithTrace(ctx, trace)
    MW->>MW: shared.WithSessionID(ctx, traceID)
    MW-->>Client: continue to handler
Loading

Reviews (2): Last reviewed commit: "feat: opencode trace, close #1740" | Re-trigger Greptile

Comment thread internal/server/middleware/trace.go
Comment thread internal/server/middleware/trace.go

@devin-ai-integration devin-ai-integration Bot left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

Devin Review found 1 potential issue.

View 3 additional findings in Devin Review.

Open in Devin Review

Comment on lines +44 to +46
// OpenCodeTraceEnabled enables extracting trace IDs from OpenCode request headers.
// Default to false.
OpenCodeTraceEnabled bool `conf:"opencode_trace_enabled" yaml:"opencode_trace_enabled" json:"opencode_trace_enabled"`

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

🔴 Missing SetDefault for opencode_trace_enabled prevents env var configuration

The new OpenCodeTraceEnabled config field (internal/tracing/tracing.go:46) lacks a corresponding v.SetDefault("server.trace.opencode_trace_enabled", false) call in conf/conf.go:164, unlike the analogous claude_code_trace_enabled and codex_trace_enabled fields which both have defaults at conf/conf.go:163-164. With Viper v1.21.0, AutomaticEnv only intercepts explicit Get() calls — during Unmarshal, Viper builds a settings map from registered keys (defaults, config file, flags, overrides) and only checks env vars for those known keys. Without SetDefault, the key server.trace.opencode_trace_enabled is never registered, so setting AXONHUB_SERVER_TRACE_OPENCODE_TRACE_ENABLED=true (the standard env var pattern documented for other trace options) will be silently ignored. YAML config file values still work because Viper reads file contents directly.

Prompt for agents
The new OpenCodeTraceEnabled config field needs a default value registered in conf/conf.go's setDefaults function, just like the existing claude_code_trace_enabled and codex_trace_enabled fields. In conf/conf.go, after line 164 (v.SetDefault("server.trace.codex_trace_enabled", false)), add: v.SetDefault("server.trace.opencode_trace_enabled", false). Additionally, for consistency, add a corresponding entry in config.example.yml after the codex_trace_enabled line (around line 19): opencode_trace_enabled: false # Enable extracting trace IDs from OpenCode X-Session-Affinity header (env: AXONHUB_SERVER_TRACE_OPENCODE_TRACE_ENABLED)
Open in Devin Review

Was this helpful? React with 👍 or 👎 to provide feedback.

@looplj looplj merged commit 4211222 into unstable May 29, 2026
4 checks passed
junjiangao pushed a commit to junjiangao/axonhub that referenced this pull request May 30, 2026
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.

1 participant