open-telemetry / opentelemetry-go-contrib

Collection of extensions for OpenTelemetry-Go.
https://opentelemetry.io/
Apache License 2.0
1.08k stars 505 forks source link

otelgin: add `routeName` argument to `SpanNameFormatter` function #5741

Open NeoCN opened 3 weeks ago

NeoCN commented 3 weeks ago

For Gin framework, the route name can only be get by using FullPath() function in gin.Context, the original SpanNameFormatter only has the http.Request argument that can not get the right route name if route parameters used.

This PR add routeName argument to SpanNameFormatter function, align with SpanNameFormatter in otelmux.

NeoCN commented 3 weeks ago

@dmathieu Currently no other info needed from the gin.Context. Honestly, using gin.Context will be more flexible as lots of things can be got from the context. Do we need the flexibility ?

codecov[bot] commented 3 weeks ago

Codecov Report

All modified and coverable lines are covered by tests :white_check_mark:

Project coverage is 64.2%. Comparing base (2dc32c1) to head (26c54e1).

Additional details and impacted files [![Impacted file tree graph](https://app.codecov.io/gh/open-telemetry/opentelemetry-go-contrib/pull/5741/graphs/tree.svg?width=650&height=150&src=pr&token=P6F3W9WA7Q&utm_medium=referral&utm_source=github&utm_content=comment&utm_campaign=pr+comments&utm_term=open-telemetry)](https://app.codecov.io/gh/open-telemetry/opentelemetry-go-contrib/pull/5741?src=pr&el=tree&utm_medium=referral&utm_source=github&utm_content=comment&utm_campaign=pr+comments&utm_term=open-telemetry) ```diff @@ Coverage Diff @@ ## main #5741 +/- ## ===================================== Coverage 64.2% 64.2% ===================================== Files 199 199 Lines 12454 12454 ===================================== Hits 8001 8001 Misses 4219 4219 Partials 234 234 ``` | [Files](https://app.codecov.io/gh/open-telemetry/opentelemetry-go-contrib/pull/5741?dropdown=coverage&src=pr&el=tree&utm_medium=referral&utm_source=github&utm_content=comment&utm_campaign=pr+comments&utm_term=open-telemetry) | Coverage Δ | | |---|---|---| | [...ation/github.com/gin-gonic/gin/otelgin/gintrace.go](https://app.codecov.io/gh/open-telemetry/opentelemetry-go-contrib/pull/5741?src=pr&el=tree&filepath=instrumentation%2Fgithub.com%2Fgin-gonic%2Fgin%2Fotelgin%2Fgintrace.go&utm_medium=referral&utm_source=github&utm_content=comment&utm_campaign=pr+comments&utm_term=open-telemetry#diff-aW5zdHJ1bWVudGF0aW9uL2dpdGh1Yi5jb20vZ2luLWdvbmljL2dpbi9vdGVsZ2luL2dpbnRyYWNlLmdv) | `81.1% <100.0%> (ø)` | | | [...ntation/github.com/gin-gonic/gin/otelgin/option.go](https://app.codecov.io/gh/open-telemetry/opentelemetry-go-contrib/pull/5741?src=pr&el=tree&filepath=instrumentation%2Fgithub.com%2Fgin-gonic%2Fgin%2Fotelgin%2Foption.go&utm_medium=referral&utm_source=github&utm_content=comment&utm_campaign=pr+comments&utm_term=open-telemetry#diff-aW5zdHJ1bWVudGF0aW9uL2dpdGh1Yi5jb20vZ2luLWdvbmljL2dpbi9vdGVsZ2luL29wdGlvbi5nbw==) | `100.0% <100.0%> (ø)` | |
dmathieu commented 3 weeks ago

Ping @hanyuancheung

NeoCN commented 2 weeks ago

@dmathieu @hanyuancheung Any suggestions for this PR?