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

Change otelecho to wrap otelhttp

Open terev opened this issue 2 years ago • 16 comments

Summary

This pr changes the otelecho instrumentation to wrap the otelhttp instrumentation rather than implement it's own. This has many benefits in my opinion as the otelecho instrumentation wasn't doing anything novel. Wrapping the otelhttp instrumentation provides metrics in addition to a more standard trace middleware. I don't really expect this pr to be accepted as is because it kind of goes against the definition of an instrumentation package. Is there a different/better approach that should be taken here?

terev avatar May 09 '22 04:05 terev

Codecov Report

Merging #2269 (4459e53) into main (d1faf5c) will decrease coverage by 0.5%. The diff coverage is 58.9%.

:exclamation: Current head 4459e53 differs from pull request most recent head bb53c82. Consider uploading reports for the commit bb53c82 to get more accurate results

Additional details and impacted files

Impacted file tree graph

@@           Coverage Diff           @@
##            main   #2269     +/-   ##
=======================================
- Coverage   74.3%   73.8%   -0.5%     
=======================================
  Files        144     145      +1     
  Lines       6563    6573     +10     
=======================================
- Hits        4877    4853     -24     
- Misses      1543    1578     +35     
+ Partials     143     142      -1     
Impacted Files Coverage Δ
...thub.com/labstack/echo/otelecho/config_otelhttp.go 30.0% <30.0%> (ø)
...entation/github.com/labstack/echo/otelecho/echo.go 85.7% <82.6%> (-9.3%) :arrow_down:
...tation/github.com/labstack/echo/otelecho/config.go 100.0% <100.0%> (ø)

... and 1 file with indirect coverage changes

codecov[bot] avatar May 09 '22 06:05 codecov[bot]

I advise you to consider joining the SIG meeting to present the PR and ask for feedback. You can also ask for reviews on Slack. See: https://github.com/open-telemetry/opentelemetry-go/blob/main/CONTRIBUTING.md

The comments I left are based on an issue that I was working on a long time ago. Maybe it is worth the revisit the topic. Nobody even "upvoted" my comments so maybe they are no longer invalid.

pellared avatar May 12 '22 05:05 pellared

go: updates to go.mod needed; to update it:
	go mod tidy

pellared avatar Jun 08 '22 09:06 pellared

I ran precommit to fix the mod tidy issue.

terev avatar Jun 12 '22 05:06 terev

it looks like a linter failed because of a timeout on an unrelated module. anything else this pr needs to get in?

terev avatar Jun 19 '22 03:06 terev

Unfortunately, the lint job is a bit flaky at the moment 😢 I reran it. But it seems the failure now is indeed related to your changes.

dmathieu avatar Jun 20 '22 07:06 dmathieu

@open-telemetry/go-maintainers PTAL

pellared avatar Jun 21 '22 07:06 pellared

@terev just out of curiosity, was this closed for lack of review or another reason?

matoous avatar Jun 17 '23 18:06 matoous

@matoous Yes mainly because it was not getting reviewed and possibly stale. Very happy to resubmit if others see value in it too lmk.

terev avatar Jun 17 '23 19:06 terev

@terev I definitely do and would love to see this merged, also happy to contribute. Maybe @pellared could help get this through (please)?

matoous avatar Jun 21 '23 07:06 matoous

I am reopening it and assigning to myself. However, I guess I will have to time to look at it in about a month 😬 @terev Can you make update the PR before tomorrow SIG meeting? I Then I can mention the PR during the SIG meeting.

Also I do not remember exactly how it is implemented but you can also explore how semconvutil is generated to reuse code between HTTP instrumentation libraries. This could potentially address this comment https://github.com/open-telemetry/opentelemetry-go-contrib/pull/2269#discussion_r915277852

PS. Sorry for inconvenience. I will do my best to help.

pellared avatar Jun 21 '23 07:06 pellared

Thanks for trying to get this some love for us but I just noticed this change in main https://github.com/open-telemetry/opentelemetry-go-contrib/blob/main/instrumentation/net/http/otelhttp/handler.go#L65 . This makes me think my change is no longer needed. Having the ability to create a net/http middleware directly allows us to wrap it and use it without need for a specific package. Once this is released we should be able to do:

mw := echo.WrapMiddleware(otelhttp.NewMiddleware("operation", opts...))
server.Use(mw)

@matoous does that seem reasonable to you?

terev avatar Jun 22 '23 06:06 terev

@terev I think the "missing feature" of using otelhttp.NewMiddleware is that the route tags (like assert.Contains(t, attrs, attribute.String("http.route", "/user/:id"))) would be lost.

pellared avatar Jun 22 '23 07:06 pellared

@pellared Right that's a good point. maybe we need a variant of WithRouteTag that can be used as a middleware as well? I'd be happy to make that change.

terev avatar Jun 22 '23 07:06 terev

@terev exactly as @pellared wrote. If you don't have time or capacity for it, please let me know, I would be happy to contribute.

matoous avatar Jun 22 '23 07:06 matoous

@matoous @pellared Submitted a new pull request here https://github.com/open-telemetry/opentelemetry-go-contrib/pull/4017

terev avatar Jun 22 '23 08:06 terev