Skip to content

Add otelhttp middleware for automatic HTTP request metrics#31

Open
aparajon wants to merge 1 commit intomainfrom
armand/otelhttp
Open

Add otelhttp middleware for automatic HTTP request metrics#31
aparajon wants to merge 1 commit intomainfrom
armand/otelhttp

Conversation

@aparajon
Copy link
Copy Markdown
Collaborator

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 at GET /metrics alongside the existing custom metrics from the OTel foundation PR.

After this, curl /metrics will include standard HTTP server metrics like http_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

Copilot AI review requested due to automatic review settings April 23, 2026 15:04
Copy link
Copy Markdown

Copilot AI left a comment

Choose a reason for hiding this comment

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

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.ServeMux with otelhttp.NewHandler() to enable automatic HTTP server metrics.
  • Add a unit test that verifies OTel HTTP server metrics are produced.
  • Promote otelhttp (and otel/metric) to direct go.mod dependencies.

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.

Comment thread pkg/cmd/commands/serve.go Outdated
Comment thread pkg/api/telemetry_test.go
@aparajon aparajon marked this pull request as ready for review April 23, 2026 15:59
@aparajon aparajon requested a review from morgo as a code owner April 23, 2026 15:59
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>
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.

2 participants