Skip to content

feat(net/http/otelhttp): Add http.route attribute#8632

Merged
dmathieu merged 18 commits intoopen-telemetry:mainfrom
gaiaz-iusipov:metric-route-attr
Apr 1, 2026
Merged

feat(net/http/otelhttp): Add http.route attribute#8632
dmathieu merged 18 commits intoopen-telemetry:mainfrom
gaiaz-iusipov:metric-route-attr

Conversation

@gaiaz-iusipov
Copy link
Copy Markdown
Contributor

@gaiaz-iusipov gaiaz-iusipov commented Mar 4, 2026

Fixes #8633

In this pull request, I add recording of the http.route metric attribute for net/http/otelhttp.

This PR does not affect any instrumentation other than otelhttp, because the check if route == "" && req.Pattern != "" is triggered only in otelhttp.

@gaiaz-iusipov gaiaz-iusipov requested review from a team and dmathieu as code owners March 4, 2026 06:26
@codecov
Copy link
Copy Markdown

codecov Bot commented Mar 4, 2026

Codecov Report

✅ All modified and coverable lines are covered by tests.
✅ Project coverage is 82.2%. Comparing base (7d66e8f) to head (b84e6d0).
⚠️ Report is 4 commits behind head on main.

Additional details and impacted files

Impacted file tree graph

@@           Coverage Diff           @@
##            main   #8632     +/-   ##
=======================================
- Coverage   82.2%   82.2%   -0.1%     
=======================================
  Files        183     183             
  Lines      13907   13919     +12     
=======================================
+ Hits       11443   11444      +1     
- Misses      2056    2067     +11     
  Partials     408     408             
Files with missing lines Coverage Δ
.../go-restful/otelrestful/internal/semconv/server.go 83.2% <100.0%> (+0.1%) ⬆️
...m/gin-gonic/gin/otelgin/internal/semconv/server.go 83.2% <100.0%> (+0.1%) ⬆️
...com/gorilla/mux/otelmux/internal/semconv/server.go 83.2% <100.0%> (+0.1%) ⬆️
.../labstack/echo/otelecho/internal/semconv/server.go 83.2% <100.0%> (+0.1%) ⬆️
...httptrace/otelhttptrace/internal/semconv/server.go 83.2% <100.0%> (+0.1%) ⬆️
...ation/net/http/otelhttp/internal/semconv/server.go 83.2% <100.0%> (+0.1%) ⬆️

... and 1 file with indirect coverage changes

🚀 New features to boost your workflow:
  • ❄️ Test Analytics: Detect flaky tests, report on failures, and find test suite problems.

Copy link
Copy Markdown
Member

@pellared pellared left a comment

Choose a reason for hiding this comment

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

Can you please create an issue first?

From https://github.com/open-telemetry/opentelemetry-go-contrib/blob/main/CONTRIBUTING.md#contributing-code:

It's recommended that you signal your intention to contribute in the issue tracker, either by filing a new issue or by claiming an existing one.

@dmathieu
Copy link
Copy Markdown
Member

dmathieu commented Mar 4, 2026

Could this be done with a Labeler?

@gaiaz-iusipov
Copy link
Copy Markdown
Contributor Author

I created an issue where I tried to explain my motivation: #8633

@gaiaz-iusipov
Copy link
Copy Markdown
Contributor Author

I changed the logic so that the attribute is recorded by default, with an option to disable it. There is also still the question of moving the routeFromRequest function to the semconv package. Let’s discuss the final approach in the issue.

@gaiaz-iusipov gaiaz-iusipov marked this pull request as draft March 6, 2026 12:04
@gaiaz-iusipov gaiaz-iusipov changed the title feat(net/http/otelhttp): Add optional MetricRouteAttribute feat(net/http/otelhttp): Add http.route attribute Mar 9, 2026
@gaiaz-iusipov
Copy link
Copy Markdown
Contributor Author

Could this be done with a Labeler?

Sure it could, but @pellared pointed out in the issue that this attribute should always (when it is available) be recorded by default.

@gaiaz-iusipov gaiaz-iusipov marked this pull request as ready for review March 9, 2026 13:46
@dmathieu
Copy link
Copy Markdown
Member

dmathieu commented Mar 9, 2026

Sure, though this is not what that PR was doing when I left my comment.
Now: the attribute can be removed with a view. Why do we need the option?

@gaiaz-iusipov
Copy link
Copy Markdown
Contributor Author

Sure, though this is not what that PR was doing when I left my comment. Now: the attribute can be removed with a view. Why do we need the option?

So it turns out the option is not needed at all. What about moving the routeFromRequest function to semconv.HTTPServer and making it public since its logic is duplicated?

@github-actions github-actions Bot requested a review from akats7 March 9, 2026 16:21
Comment thread internal/shared/semconv/util.go.tmpl Outdated
Comment thread instrumentation/net/http/otelhttp/handler_test.go Outdated
@dmathieu dmathieu requested a review from pellared March 10, 2026 15:17
Copy link
Copy Markdown
Member

@flc1125 flc1125 left a comment

Choose a reason for hiding this comment

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

Some small adjustments.

Comment thread CHANGELOG.md Outdated
@gaiaz-iusipov
Copy link
Copy Markdown
Contributor Author

I think this PR is ready to merge.

@dmathieu
Copy link
Copy Markdown
Member

I'm waiting for @pellared's review, since he requested changes.

@pellared pellared dismissed their stale review April 1, 2026 08:10

Issue has been created and I added it to the PR description.

Copy link
Copy Markdown
Member

@pellared pellared left a comment

Choose a reason for hiding this comment

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

It looks that the description in #8633 is not updated

I also do not follow the following part of the current PR description

The routeFromRequest function code is duplicated, and it might be better to move it to semconv.HTTPServer.

Can you please update the issue and PR description?

Comment thread internal/shared/semconv/server.go.tmpl
Comment thread internal/shared/semconv/server_test.go.tmpl Outdated
Comment thread CHANGELOG.md Outdated
@gaiaz-iusipov
Copy link
Copy Markdown
Contributor Author

gaiaz-iusipov commented Apr 1, 2026

Can you please update the issue and PR description?

@pellared thanks for the review, I will update the issue description and this PR.

Comment thread internal/shared/semconv/server.go.tmpl
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.

feat(net/http/otelhttp): Add http.route attribute

4 participants