opentelemetry-go-contrib
opentelemetry-go-contrib copied to clipboard
Add WithRouteTagMiddleware function to otelhttp package
This new function simplifies usage of this utility by users of third party router packages.
This new function simplifies usage of this utility within third party router packages.
Could you please provide examples? You can even consider adding "test examples".
EDIT: I think if we document how to use it with: gorilla/mux, echo, chi. We could even consider deprecating the otelmux, otelecho (or rewriting to use the same codebase).
Codecov Report
Merging #4017 (efd7ba7) into main (9a582bd) will decrease coverage by
0.2%. The diff coverage is25.0%.
Additional details and impacted files
@@ Coverage Diff @@
## main #4017 +/- ##
=======================================
- Coverage 79.2% 79.0% -0.2%
=======================================
Files 165 165
Lines 10318 10349 +31
=======================================
+ Hits 8176 8182 +6
- Misses 2006 2030 +24
- Partials 136 137 +1
| Impacted Files | Coverage Δ | |
|---|---|---|
| ...hub.com/emicklei/go-restful/otelrestful/restful.go | 90.5% <0.0%> (-9.5%) |
:arrow_down: |
| ...ation/github.com/gin-gonic/gin/otelgin/gintrace.go | 79.1% <0.0%> (-4.4%) |
:arrow_down: |
| ...trumentation/github.com/gorilla/mux/otelmux/mux.go | 80.7% <0.0%> (-7.7%) |
:arrow_down: |
| ...entation/github.com/labstack/echo/otelecho/echo.go | 89.8% <0.0%> (-10.2%) |
:arrow_down: |
| instrumentation/net/http/otelhttp/handler.go | 85.7% <90.0%> (+2.6%) |
:arrow_up: |
@pellared I've added one example so far and can add more in the morning. I added it to instrumentation/net/http/otelhttp/example/server/github.com/labstack/echo . It semanticly makes sense but may be tough to find. What do you think?
@pellared I've added a bunch of examples to instrumentation/net/http/otelhttp/example/server. Probably not the best place so lmk if there's somewhere else they should be.
I think simpler, and testable examples would be better than this. What we need is a code sample, not a full-blown runnable app.
I think simpler, and testable examples would be better than this. What we need is a code sample, not a full-blown runnable app.
Not sure how to do this and actually add examples for the NewMiddlware function. If I add this into the root of the otelhttp module it'll add a bunch of extra dependencies. Should these examples be put in the example directory as testable examples? Even though they'll be examples for the example module?
Not sure how to do this and actually add examples for the NewMiddlware function. If I add this into the root of the otelhttp module it'll add a bunch of extra dependencies. Should these examples be put in the example directory as testable examples? Even though they'll be examples for the example module?
They can be put in the same directory, but with a different module name. See this example from gRPC: https://github.com/open-telemetry/opentelemetry-go-contrib/blob/main/instrumentation/google.golang.org/grpc/otelgrpc/example_interceptor_test.go
Not sure how to do this and actually add examples for the NewMiddlware function. If I add this into the root of the otelhttp module it'll add a bunch of extra dependencies. Should these examples be put in the example directory as testable examples? Even though they'll be examples for the example module?
They can be put in the same directory, but with a different module name. See this example from gRPC: https://github.com/open-telemetry/opentelemetry-go-contrib/blob/main/instrumentation/google.golang.org/grpc/otelgrpc/example_interceptor_test.go
Won't that still require dependencies in the go.mod? I created a file called instrumentation/net/http/otelhttp/example_echo_middleware_test.go that is defined within the otelhttp_test package. Then running go mod tidy -v in that directory adds the dependencies required by the example to go.mod.
It's still unclear to me where I should be putting the example tests. Maybe there is not really a good answer for this at the moment?
It's still unclear to me where I should be putting the example tests. Maybe there is not really a good answer for this at the moment?
For me it is good as it is for now. We can improve the examples later. You are correct here: https://github.com/open-telemetry/opentelemetry-go-contrib/pull/4017#issuecomment-1619453056
Does anyone have opinions on whether this should be closed? It seems like the third party instrumentation is due to be removed at some point so maybe this is obsolete?
With the routing enhancements in Go 1.22, and this PR being rather stale, I think we should close it. Once all supported versions of Go have routing available, we can add that to otelhttp.
Note that while 1.22 added routing support, retrieving the pattern is only available from 1.23. So we'll have to wait for 1.22 to be EOL. https://pkg.go.dev/net/http@master#Request.Pattern