Add otelhttp middleware for automatic HTTP request metrics#31
Open
Add otelhttp middleware for automatic HTTP request metrics#31
Conversation
ca86d99 to
60b1e42
Compare
There was a problem hiding this comment.
Pull request overview
Adds OpenTelemetry HTTP server instrumentation so standard request metrics are emitted automatically for all endpoints and exposed via the existing Prometheus /metrics endpoint.
Changes:
- Wrap the main
http.ServeMuxwithotelhttp.NewHandler()to enable automatic HTTP server metrics. - Add a unit test that verifies OTel HTTP server metrics are produced.
- Promote
otelhttp(andotel/metric) to directgo.moddependencies.
Reviewed changes
Copilot reviewed 4 out of 4 changed files in this pull request and generated 2 comments.
| File | Description |
|---|---|
| pkg/cmd/commands/serve.go | Wraps the HTTP mux with otelhttp.NewHandler so requests are instrumented automatically. |
| pkg/api/telemetry_test.go | Adds a test to collect and assert OTel HTTP server metrics are emitted. |
| go.mod | Adds otelhttp and otel/metric as direct dependencies (previously indirect). |
💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.
60b1e42 to
e00b76b
Compare
Wraps the HTTP mux with otelhttp.NewHandler() to get automatic per-route metrics (http.server.request.duration, active requests, response size) for every endpoint without touching individual handlers. Co-Authored-By: Claude Opus 4.6 (1M context) <noreply@anthropic.com>
e00b76b to
3595958
Compare
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.
Summary
Wraps the HTTP server mux with
otelhttp.NewHandler()so every endpoint automatically gets request duration, active request count, and response size metrics — without modifying any individual handler. These metrics appear atGET /metricsalongside the existing custom metrics from the OTel foundation PR.After this,
curl /metricswill include standard HTTP server metrics likehttp_server_request_duration_seconds_bucket{http_route="/api/plan",...}for every route, giving visibility into latency and error rates per endpoint.🤖 Generated with Claude Code