Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

otelecho: remove global error handler call #4420

Open
wants to merge 8 commits into
base: main
Choose a base branch
from

Conversation

rattuscz
Copy link

First try at implementing #4419

@linux-foundation-easycla
Copy link

linux-foundation-easycla bot commented Oct 12, 2023

CLA Signed

The committers listed above are authorized under a signed CLA.

@rattuscz rattuscz marked this pull request as ready for review November 15, 2023 18:07
@rattuscz rattuscz requested a review from a team November 15, 2023 18:07
@MrAlias
Copy link
Contributor

MrAlias commented Nov 15, 2023

#4419 (comment)

Instead of modifying the instrumentation, I would recommend you register a rate-limiting error handler. You can customize the behavior of how errors are handle however you want by using your own error handler. Adding to the API surface error of the instrumentation does not seem like a prudent way to solve an issue that can already be solved with a custom error handler.

@pellared
Copy link
Member

pellared commented Nov 15, 2023

To be honest, I do not understand why c.Error(err) is even called given that the err is returned by the middleware. Shouldn't we simply remove this line?

PS. I never used echo.

@MrAlias
Copy link
Contributor

MrAlias commented Nov 15, 2023

To be honest, I do not understand why c.Error(err) is even called given that the err is returned by the middleware. Shouldn't we simply remove this line?

PS. I never used echo.

I'm not opposed to this.

Copy link
Member

@hanyuancheung hanyuancheung left a comment

Choose a reason for hiding this comment

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

This PR SGTM

@hanyuancheung
Copy link
Member

@rattuscz Please do not forget to add a changelog.

Copy link

codecov bot commented Nov 16, 2023

Codecov Report

All modified and coverable lines are covered by tests ✅

Comparison is base (3cecdcf) 81.1% compared to head (d34410e) 80.8%.

❗ Current head d34410e differs from pull request most recent head e1b9126. Consider uploading reports for the commit e1b9126 to get more accurate results

Additional details and impacted files

Impacted file tree graph

@@           Coverage Diff           @@
##            main   #4420     +/-   ##
=======================================
- Coverage   81.1%   80.8%   -0.3%     
=======================================
  Files        150     150             
  Lines      10753   10349    -404     
=======================================
- Hits        8725    8371    -354     
+ Misses      1872    1834     -38     
+ Partials     156     144     -12     
Files Coverage Δ
...tation/github.com/labstack/echo/otelecho/config.go 100.0% <100.0%> (ø)
...entation/github.com/labstack/echo/otelecho/echo.go 100.0% <100.0%> (ø)

... and 22 files with indirect coverage changes

@rattuscz
Copy link
Author

rattuscz commented Dec 6, 2023

To be honest, I do not understand why c.Error(err) is even called given that the err is returned by the middleware. Shouldn't we simply remove this line?

PS. I never used echo.

Yes it seems weird to me too, it's probably propagated by copy pasting some example from echo documentation.

Anyway it will be BC break if you simply remove it now as users of this package had to already solve it somehow on their end - either by ignoring some errors in the global error handler or by carefully stacking middlewares to get expected behavior.

@pellared
Copy link
Member

pellared commented Dec 6, 2023

Anyway it will be BC break

It is not a stable Go module so breaking change are acceptable if there are good reasons to do so.

@rattuscz rattuscz changed the title [WIP] otelecho: config option to skip global error handler call otelecho: remove global error handler call Jan 15, 2024
@rattuscz
Copy link
Author

Okie, changed this to implement the removal.
I've once again today run into issue with this so I hope this is merged & released soon :-)

CHANGELOG.md Outdated Show resolved Hide resolved
Copy link
Member

@dmathieu dmathieu left a comment

Choose a reason for hiding this comment

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

Tests are failing.

@@ -38,6 +38,9 @@ This project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0.htm

- Upgrade dependencies of OpenTelemetry Go to use the new [`v1.21.0`/`v0.44.0` release](https://github.com/open-telemetry/opentelemetry-go/releases/tag/v1.21.0). (#4582)

### Changed
- Remove call to global error handler in `go.opentelemetry.io/contrib/instrumentation/github.com/labstack/echo/otelecho` (#4420)
Copy link
Member

Choose a reason for hiding this comment

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

This is also improperly placed in the changelog. It needs to be in the unreleased section.

@rattuscz
Copy link
Author

Tests are failing.

Oh well it actually depends on the http status code being already set (for example by error handler.. 😞 ).

So this middleware would require some other middleware up in the chain calling the error handler or it needs to call the error handler itself.

Otherwise even though the server works properly - global error handler is called by echo if err comes out of middlewares - it will not record correct http status code and span ok/error status.

Any thoughts? 🤔

@dmathieu
Copy link
Member

Well, it looks like the TestStatusError test needs to be updated to properly reflect those changes.

@rattuscz
Copy link
Author

Well, it looks like the TestStatusError test needs to be updated to properly reflect those changes.

Sure I can fix the tests, if that's the way to go.
Not really sure if there is some better way how to avoid those problems, because it will still be quite easy to have it wrongly setup just because of order of middlewares/logger/error handler.

In our projects we tend to have logger as the last middleware and eating the error returned from handler functions so the response is already set, error logged/handled and all is great.
Others may have different order and suffer breaks when we change this.

Will leave it here for a few days before commiting

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.

5 participants