opentelemetry-go-contrib icon indicating copy to clipboard operation
opentelemetry-go-contrib copied to clipboard

Add WithRouteTagMiddleware function to otelhttp package

Open terev opened this issue 2 years ago • 10 comments

This new function simplifies usage of this utility by users of third party router packages.

terev avatar Jun 22 '23 08:06 terev

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).

pellared avatar Jun 22 '23 08:06 pellared

Codecov Report

Merging #4017 (efd7ba7) into main (9a582bd) will decrease coverage by 0.2%. The diff coverage is 25.0%.

Additional details and impacted files

Impacted file tree graph

@@           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:

... and 2 files with indirect coverage changes

codecov[bot] avatar Jun 22 '23 08:06 codecov[bot]

@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?

terev avatar Jun 22 '23 09:06 terev

@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.

terev avatar Jun 25 '23 20:06 terev

I think simpler, and testable examples would be better than this. What we need is a code sample, not a full-blown runnable app.

dmathieu avatar Jun 26 '23 06:06 dmathieu

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?

terev avatar Jul 02 '23 08:07 terev

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

dmathieu avatar Jul 03 '23 07:07 dmathieu

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.

terev avatar Jul 04 '23 04:07 terev

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?

terev avatar Jul 25 '23 20:07 terev

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

pellared avatar Jul 26 '23 08:07 pellared

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?

terev avatar Jul 30 '24 18:07 terev

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

dmathieu avatar Jul 31 '24 07:07 dmathieu