refactor: remove deprecated otelhttp.WithMetricAttributesFn#11257
Merged
refactor: remove deprecated otelhttp.WithMetricAttributesFn#11257
Conversation
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
Member
Author
|
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. |
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.
Problem
#11208 added
otelhttp.WithMetricAttributesFncalls when otelhttp was at v0.65.0 and the function was not yet deprecated. Thefeat/provide-entity-roots-with-dedupbranch bumps otelhttp to v0.67.0, which marks the function deprecated, breaking Go Lint withstaticcheckSA1019:https://github.com/ipfs/kubo/actions/runs/23673403623
This is an early warning we should move away from
otelhttp.WithMetricAttributesFn:)Solution
Replace
WithMetricAttributesFnwith awithMetricLabelsmiddleware that uses the request-scopedotelhttp.Labeler(the officially recommended replacement).Wraps a handler inside
otelhttp.NewHandlerto callLabelerFromContextand add attributes before delegating.Code: otelhttp
handler.go:201shows both the old and new paths converge at the same metric recording point, feeding into the samehttp_server_*metrics throughsemconv/server.go.Manual test: i've built the binary, started a daemon with
PublicGatewaysconfigured, fired requests, scraped/debug/metrics/prometheus:server_domainPOST /api/v0/id"api"commands.go(static)GET /ipfs/Qm...on127.0.0.1"loopback"GatewayOption(dynamic)Host: *.ipns.localhost"localhost"HostnameOption(dynamic)Confirmed
server_domainpresent onhttp_server_request_body_size_bytes,http_server_response_body_size_bytes, andhttp_server_request_duration_secondsfor all three paths.So this is functionally equivalent, just uses more modern API.