opentelemetry-go-contrib
opentelemetry-go-contrib copied to clipboard
otelecho: remove global error handler call
First try at implementing #4419
The committers listed above are authorized under a signed CLA.
- :white_check_mark: login: rattuscz / name: Petr Vítek (4e40bbb32a42cabf2fd850bffcb2f0ee23d10482, c3761c7740f61cdf5c80622a981d38548e933aee, 08e7c3a52681984c775dbf908f215a4e6fffb6b5, 0ae232b650be0d01392b07811ffc42059699342e, 07184f63ae85bddb7f643cef24596a10fa73962e, 55bb62147ec1a0e6b0f1b52eefdc5c718e42fcdf, e1b91263508fcf6412daa254d8c44f07278ccb62)
- :white_check_mark: login: hanyuancheung / name: Chester Cheung (d34410e537212505e2377172f600dbe29c5cc34f)
- :white_check_mark: login: dmathieu / name: Damien Mathieu (55bb62147ec1a0e6b0f1b52eefdc5c718e42fcdf)
https://github.com/open-telemetry/opentelemetry-go-contrib/issues/4419#issuecomment-1813039942
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.
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.
To be honest, I do not understand why
c.Error(err)
is even called given that theerr
is returned by the middleware. Shouldn't we simply remove this line?PS. I never used echo.
I'm not opposed to this.
@rattuscz Please do not forget to add a changelog.
Codecov Report
All modified and coverable lines are covered by tests :white_check_mark:
Comparison is base (
3cecdcf
) 81.1% compared to head (d34410e
) 80.8%.
:exclamation: 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
@@ 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%> (ø) |
To be honest, I do not understand why
c.Error(err)
is even called given that theerr
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.
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.
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 :-)
Tests are failing.
Oh well it actually depends on the http status code being already set (for example by error handler.. :disappointed: ).
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? :thinking:
Well, it looks like the TestStatusError
test needs to be updated to properly reflect those changes.
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