Skip to content

refactor: remove deprecated otelhttp.WithMetricAttributesFn#11257

Merged
lidel merged 1 commit intomasterfrom
fix/drop-deprecated-otelhttp-metric-attrs-fn
Mar 29, 2026
Merged

refactor: remove deprecated otelhttp.WithMetricAttributesFn#11257
lidel merged 1 commit intomasterfrom
fix/drop-deprecated-otelhttp-metric-attrs-fn

Conversation

@lidel
Copy link
Copy Markdown
Member

@lidel lidel commented Mar 28, 2026

Problem

#11208 added otelhttp.WithMetricAttributesFn calls when otelhttp was at v0.65.0 and the function was not yet deprecated. The feat/provide-entity-roots-with-dedup branch bumps otelhttp to v0.67.0, which marks the function deprecated, breaking Go Lint with staticcheck SA1019:

https://github.com/ipfs/kubo/actions/runs/23673403623

core/corehttp/commands.go:150:4: SA1019: otelhttp.WithMetricAttributesFn is deprecated
core/corehttp/gateway.go:49:32:  SA1019: otelhttp.WithMetricAttributesFn is deprecated
core/corehttp/gateway.go:80:32:  SA1019: otelhttp.WithMetricAttributesFn is deprecated

This is an early warning we should move away from otelhttp.WithMetricAttributesFn :)

Solution

Replace WithMetricAttributesFn with a withMetricLabels middleware that uses the request-scoped otelhttp.Labeler (the officially recommended replacement).

func withMetricLabels(next http.Handler, fn func(*http.Request) []attribute.KeyValue) http.Handler

Wraps a handler inside otelhttp.NewHandler to call LabelerFromContext and add attributes before delegating.

Code: otelhttp handler.go:201 shows both the old and new paths converge at the same metric recording point, feeding into the same http_server_* metrics through semconv/server.go.

Manual test: i've built the binary, started a daemon with PublicGateways configured, fired requests, scraped /debug/metrics/prometheus:

Request server_domain Handler
POST /api/v0/id "api" commands.go (static)
GET /ipfs/Qm... on 127.0.0.1 "loopback" GatewayOption (dynamic)
Host: *.ipns.localhost "localhost" HostnameOption (dynamic)

Confirmed server_domain present on http_server_request_body_size_bytes, http_server_response_body_size_bytes, and http_server_request_duration_seconds for all three paths.

So this is functionally equivalent, just uses more modern API.

Use request-scoped otelhttp.Labeler instead, which is the
recommended replacement per upstream otelhttp v0.67.0.

- add withMetricLabels helper wrapping inner handler
- migrate all 4 call sites in commands.go and gateway.go
@lidel lidel requested a review from a team March 28, 2026 00:55
@lidel lidel added the skip/changelog This change does NOT require a changelog entry label Mar 28, 2026
@lidel lidel marked this pull request as ready for review March 28, 2026 01:01
@lidel lidel mentioned this pull request Mar 28, 2026
24 tasks
@lidel
Copy link
Copy Markdown
Member Author

lidel commented Mar 29, 2026

I'm going to merge this to fix CI in all PRs, feels low risk + right now we are in permanent state of red CI due to this lint.

@lidel lidel merged commit a78991e into master Mar 29, 2026
24 of 26 checks passed
@lidel lidel deleted the fix/drop-deprecated-otelhttp-metric-attrs-fn branch March 29, 2026 15:33
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

skip/changelog This change does NOT require a changelog entry

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant