🌐 US-Proxy
class="logged-out env-production page-responsive" style="word-wrap: break-word;" >
Skip to content

feat: setup logging, tracing and metrics in standalone AI Gateway - #27068

Merged
pawbana merged 5 commits into
mainfrom
pawel/aigov-317-add-observability-to-standalone-ai-gateway
Jul 9, 2026
Merged

feat: setup logging, tracing and metrics in standalone AI Gateway#27068
pawbana merged 5 commits into
mainfrom
pawel/aigov-317-add-observability-to-standalone-ai-gateway

Conversation

@pawbana

@pawbana pawbana commented Jul 7, 2026

Copy link
Copy Markdown
Contributor

Adds logging, tracing and metrics setup to standalone AI Gateway.
Existing options are re-used when possible.

@linear-code

linear-code Bot commented Jul 7, 2026

Copy link
Copy Markdown

AIGOV-317

@github-actions

github-actions Bot commented Jul 7, 2026

Copy link
Copy Markdown

Docs preview

📖 View docs preview for docs/reference/cli/ai-gateway_start.md

pawbana commented Jul 7, 2026

Copy link
Copy Markdown
Contributor Author

@pawbana
pawbana force-pushed the pawel/aigov-317-add-observability-to-standalone-ai-gateway branch from 3ecfb93 to 2d9f138 Compare July 7, 2026 18:45
@pawbana pawbana changed the title feat: wire ai gateway logging feat: setup logging, tracing and metrics in standalone AI Gateway Jul 7, 2026
@pawbana

pawbana commented Jul 7, 2026

Copy link
Copy Markdown
Contributor Author

/coder-agents-review

@coder-agents-review

coder-agents-review Bot commented Jul 7, 2026

Copy link
Copy Markdown
Contributor

Chat: Review posted | View chat
Requested: 2026-07-07 18:49 UTC by @pawbana
Spend: $37.80 / $100.00

Review history
  • R1 (2026-07-07): 16 reviewers, 6 Nit, 6 P3, 1 P4, COMMENT. Review

deep-review v0.9.0 | Round 1 | f378478..2d9f138

Last posted: Round 1, 13 findings (6 P3, 1 P4, 6 Nit), COMMENT. Review

Finding inventory

Findings

# Sev Status Location Summary Round Reviewer Posted
CRF-1 P4 Open scaletest/llmmock/server.go:680 StartHTTPSpan sibling not updated R1 Netero Yes
CRF-2 P3 Open enterprise/cli/aigatewaystart.go:322 tracingMiddleware traces /healthz and /readyz health check endpoints R1 Hisoka P3, Mafuuu P3, Ryosuke Note Yes
CRF-3 P3 Open enterprise/cli/aigatewaystart.go:88 CODER_AI_GATEWAY_VERBOSE silently dropped; no deprecation path R1 Hisoka P3, Chopper P4, Meruem Note Yes
CRF-4 P3 Open enterprise/cli/aigatewaystart.go:322 StartHTTPSpan writes trace headers on raw rw before StatusWriter wraps it; ordering inverted vs coderd R1 Meruem Yes
CRF-5 P3 Open enterprise/cli/proxyserver.go:156 Workspace proxy identifies as "coderd" in traces despite serviceName parameterization R1 Ryosuke Yes
CRF-6 P3 Open enterprise/cli/aigatewaystart_internal_test.go:295 TracingMiddleware test passes with noop passthrough middleware; doesn't verify tracing R1 Bisky P3, Chopper Note Yes
CRF-7 P3 Open cli/server.go:2798 ConfigureTraceProvider exported with 4 params, 3 returns, no doc comment R1 Leorio Yes
CRF-8 Nit Open enterprise/cli/aigatewaystart.go:313 tracingMiddleware doc comment 6 lines; 4 restate the implementation R1 Gon Yes
CRF-9 Nit Open enterprise/cli/aigatewaystart_internal_test.go:257 Missing prometheus-aggregate-agent-stats-by from absent flag list R1 Mafuuu Nit, Melody P3 Yes
CRF-10 Nit Open enterprise/cli/aigatewaystart.go:335 http.target span attribute drops query string vs OTel convention R1 Chopper Yes
CRF-11 Nit Open enterprise/cli/aigatewaystart_internal_test.go:234 Test comment "same coderd option group" is inaccurate; items span groups R1 Leorio Yes
CRF-12 Nit Open enterprise/cli/aigatewaystart.go:325 "Wrap the writer" comment restates code R1 Gon Yes
CRF-13 Nit Open coderd/tracing/httpmw.go:62 StartHTTPSpan doc restates return type R1 Gon Yes
CRF-14 Note Dropped by orchestrator (pre-existing design, no runtime impact) cli/server.go:2826 ConfigureTraceProvider registers postgres driver for non-DB callers R1 Hisoka Note, Mafuuu Note, Meruem P4 No
CRF-15 Note Dropped by orchestrator (informational, tested) enterprise/cli/aigatewaystart.go:270 Group inheritance auto-captures future options R1 Ryosuke Note, Meruem Note No

Round log

Round 1

Panel. 6 P3, 5 Nit, 2 Note dropped. CRF-1 not posted (outside diff). Reviewed against f378478..2d9f138.

About deep-review

CRF = Coder Review Finding (P0-P4, Nit, Note)

Reviewer Focus
Bisky tests
Chopper ops/errors
Churn-guard change verification
Ging language modernization
Gon naming
Hisoka edge cases
Killua perf
Kite change integrity
Knov contracts
Knuckle SQL
Komugi flake/determinism
Kurapika security
Law decomposition
Leorio docs
Luffy product
Mafu-san process
Mafuuu contracts
Melody dispatch/pairing
Meruem structural
Nami frontend
Netero mechanical checks
Pariston premise testing
Pen-botter product gaps
Razor verification
Robin duplication
Ryosuke Go arch
Takumi concurrency
Zoro shape

🤖 Managed by Coder Agents.

@coder-agents-review coder-agents-review 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.

Clean extraction of StartHTTPSpan from the coderd middleware, well-designed option inheritance mechanism (group + env + exclusion), and good test coverage for the option surface. The approach of parameterizing existing infrastructure (ConfigureTraceProvider, clilog, ServeHandler) instead of building parallel stacks is exactly right.

6 P3, 5 Nit. No blockers.

Three reviewers independently flagged health endpoint tracing (CRF-2) as the sharpest finding. Gon audited all 13 comments in the diff and found a consistent pattern of restating what the code shows before reaching the useful "why"; the two most impactful are inline, the rest share the same pattern.

The PR description ("Adds logging, tracing and metrics setup") would benefit from noting: (1) why option inheritance uses two mechanisms (group match vs env-var cherry-pick), (2) the CODER_AI_GATEWAY_VERBOSE removal and its migration path, and (3) why the Gateway needs its own tracingMiddleware instead of the shared one.

"An operator with CODER_AI_GATEWAY_VERBOSE=true in their deployment environment starts the Gateway, gets no error, and runs without debug logging. They discover it when they need to debug a production issue and can't see debug output." (Hisoka)


cli/server.go:2798

P3 [CRF-7] This exported function now has 4 parameters and 3 return values, with 3 callers across 3 packages. The second return value is a SQL driver name (not obvious from the type string). The close function's contract (must defer, blocks, has a timeout?) is implicit.

// ConfigureTraceProvider sets up an OpenTelemetry TracerProvider based on
// the deployment's tracing configuration. serviceName identifies the service
// in exported traces (e.g. "coderd", "coder-ai-gateway"). Returns the
// TracerProvider, the SQL driver name for traced database connections, and a
// close function that flushes and shuts down the exporter.

(Leorio)

🤖

scaletest/llmmock/server.go:680

P4 [CRF-1] scaletest/llmmock/server.go:680-703 inlines the same trace context extraction, span creation, and response header injection that coderd/tracing.StartHTTPSpan now provides. The PR extracted this logic into a reusable function but did not update the existing duplicate. Could drop ~15 lines by calling StartHTTPSpan.

(Netero)

🤖

🤖 This review was automatically generated with Coder Agents.

Comment thread enterprise/cli/aigatewaystart.go Outdated
Comment thread enterprise/cli/aigatewaystart.go Outdated
Comment thread enterprise/cli/aigatewaystart.go Outdated
Comment thread enterprise/cli/proxyserver.go Outdated
Comment thread enterprise/cli/aigatewaystart_internal_test.go
Comment thread enterprise/cli/aigatewaystart_internal_test.go Outdated
Comment thread enterprise/cli/aigatewaystart.go Outdated
Comment thread enterprise/cli/aigatewaystart_internal_test.go Outdated
Comment thread enterprise/cli/aigatewaystart.go Outdated
Comment thread coderd/tracing/httpmw.go Outdated
@pawbana
pawbana force-pushed the pawel/aigov-317-add-observability-to-standalone-ai-gateway branch from 2d9f138 to 4d6d9e4 Compare July 8, 2026 09:13
@pawbana
pawbana force-pushed the pawel/aigov-316-add-health-endpoints-to-standalone-ai-gateway branch from f378478 to 8d475a7 Compare July 8, 2026 09:13
Base automatically changed from pawel/aigov-316-add-health-endpoints-to-standalone-ai-gateway to main July 8, 2026 09:28
@pawbana
pawbana force-pushed the pawel/aigov-317-add-observability-to-standalone-ai-gateway branch from 4d6d9e4 to e78c4ce Compare July 8, 2026 17:10
@pawbana
pawbana force-pushed the pawel/aigov-317-add-observability-to-standalone-ai-gateway branch from e78c4ce to d4c952a Compare July 8, 2026 17:16
@pawbana
pawbana marked this pull request as ready for review July 8, 2026 17:18
@pawbana
pawbana requested a review from dannykopping July 8, 2026 17:18
@coder-tasks

coder-tasks Bot commented Jul 8, 2026

Copy link
Copy Markdown
Contributor

Documentation Check

Updates Needed

  • docs/ai-coder/ai-gateway/monitoring.md - The "Enabling Tracing" and "Capturing Logs in Traces" sections reference only coder server --trace / CODER_TRACE_ENABLE. With this PR the standalone gateway (coder ai-gateway start) now supports the same tracing, Prometheus, and logging flags directly. Add a note or subsection clarifying that standalone replicas accept these flags (e.g., coder ai-gateway start --trace --prometheus-enable), with a link to the auto-generated CLI reference.
  • docs/ai-coder/ai-gateway/setup.md - Opening line states AI Gateway "runs inside the Coder control plane (coderd), requiring no separate compute." The standalone deployment mode (coder ai-gateway start) is not mentioned anywhere in the hand-written docs. Consider adding a brief "Standalone deployment" section or cross-reference now that standalone mode has production-grade observability.
  • docs/ai-coder/ai-gateway/monitoring.md - The Prometheus metrics section similarly assumes the embedded coderd mode. Standalone replicas now expose their own /metrics endpoint via --prometheus-enable; this should be noted.

Notes

  • docs/reference/cli/ai-gateway_start.md is auto-generated and will reflect the new flags after make gen; no manual edits needed.
  • The --verbose / CODER_AI_GATEWAY_VERBOSE flag was removed and replaced by standard Coder logging options (--log-human, --log-json, --verbose from CODER_VERBOSE, etc.). This is a minor breaking change for users with existing scripts or configs. Consider noting the migration in release notes or in the setup/monitoring docs.

Automated review via Coder Agents

Comment thread enterprise/cli/aigatewaystart.go
Comment thread enterprise/cli/aigatewaystart.go Outdated
traceCloseErr := shutdownWithTimeout(closeTracing, 5*time.Second)
logger.Debug(signalCtx, "tracing closed", slog.Error(traceCloseErr))
}()
tracer := tracerProvider.Tracer("aibridged")

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.

Nit: shouldn't we use the new name here?

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

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

Good catch, cleaned up both tracer and logger names.

Comment thread enterprise/cli/aigatewaystart.go Outdated
// to a standalone Gateway. CODER_ENABLE_TERRAFORM_DEBUG_MODE is grouped under
// Logging but controls provisioner behavior that coderd owns.
excludedEnvs := map[string]struct{}{
"CODER_ENABLE_TERRAFORM_DEBUG_MODE": {},

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.

This is just a concern for docs generation, correct?

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

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

Yes, this is for doc and --help message.

I've made option inheritance more straight forward and changed test.
Start command has hardcoded list of inherited optionsaiGatewayInheritedEnvs and test has hardcoded dropped list. Test verifies that every option from inherited groups is in one of those lists.

When new option is added to any group that standalone Gateway inherits options from (Logging, Tracing, AI Gateway, Prometheus) it must be added either to aiGatewayInheritedEnvs or dropped list otherwise test will fail. Maybe it is a bit annoying but it makes sure there won't be any drift.

@pawbana
pawbana enabled auto-merge (squash) July 9, 2026 14:01
@pawbana
pawbana merged commit bab8ce9 into main Jul 9, 2026
29 of 30 checks passed
@pawbana
pawbana deleted the pawel/aigov-317-add-observability-to-standalone-ai-gateway branch July 9, 2026 14:02
@github-actions github-actions Bot locked and limited conversation to collaborators Jul 9, 2026
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants