sentry-go icon indicating copy to clipboard operation
sentry-go copied to clipboard

Implement hijacker interface for Negroni integration

Open ribice opened this issue 1 year ago • 5 comments

Resolves https://github.com/getsentry/sentry-go/pull/837#issuecomment-2283914037

ribice avatar Aug 12 '24 14:08 ribice

Codecov Report

All modified and coverable lines are covered by tests :white_check_mark:

Project coverage is 82.81%. Comparing base (11d3c79) to head (e7df055). Report is 3 commits behind head on master.

Additional details and impacted files
@@            Coverage Diff             @@
##           master     #871      +/-   ##
==========================================
- Coverage   82.83%   82.81%   -0.03%     
==========================================
  Files          51       51              
  Lines        4597     4580      -17     
==========================================
- Hits         3808     3793      -15     
+ Misses        636      633       -3     
- Partials      153      154       +1     

:umbrella: View full report in Codecov by Sentry.
:loudspeaker: Have feedback on the report? Share it here.

codecov[bot] avatar Aug 12 '24 14:08 codecov[bot]

There are some breaking changes in here we need to call out on the changelog. Besides this, LGTM!

Are you referring to moving the WrapResponseWriter from sentryhttp to sentry?

That wasn't supposed to be exposed externally, so doubt anyone used it. To prevent a breaking change, we can keep it at sentryhttp as well (and just call the one at sentry internally)?

ribice avatar Aug 15 '24 07:08 ribice

It’s ok, we just need to call it out 🙂

cleptric avatar Aug 15 '24 13:08 cleptric

@cleptric Perhaps we should move the Hijacker interface to /internal?

ribice avatar Aug 28 '24 16:08 ribice

Perhaps we should move the Hijacker interface to /internal?

@ribice I'd say you should move it to internal package, but keep the one at sentryhttp to avoid breaking change, then add DEPRECATION notice (the one that's according to godoc format).

The one on sentryhttp should be a passthrough to internal package. Then after 2-3 minor version release, you can safely remove it.

aldy505 avatar Aug 30 '24 08:08 aldy505

Hi there, I reported the originar issue with negroni + websockets: the response writter does not implement http.Hijacker interface. https://github.com/getsentry/sentry-go/pull/837#issuecomment-2283914037 Today we have upgraded from v0.27.0 to v0.29.0 and the error persists.

I've reviewed the code and I've found the issue: https://github.com/getsentry/sentry-go/blob/a6acd05f8d419d0445475b9018bd59fc0503b322/internal/httputils/wrap_writer.go#L35-L57

The w is of type *negroni.responseWriter in negroni v1, which is the one referenced by the sentry-go package. This type implements http.Flusher, http.Hijacker, but not io.ReaderFrom. So fl and hj are true, but rf is not. So in line 48 does not return the httpFancyWriter. And it returns the basic flushWriter in line 53. (which does not support hijacker / websockets.

We have had to rollback our releases today as this was failing.

As mentioned before, negroni v1 uses a limited writer. This is solved in negroni v3, which is easy to migrate to, but it would be nice if go-sentry was upgraded to v3 too, as v1 was released in 2018. Having our project requiring both versions is a nightmare.

From my point of view, if go-sentry imports negroni v1, then the library should work with v1 (and this is not happening at the moment). If you expect people to be using v3 (which works with go-sentry v0.29.0) then you should import negroni v3 in your go.mod.

Please let me know your thoughts

Thank you!

kydemy-fran avatar Sep 19 '24 17:09 kydemy-fran

@ribice can you take a look please?

cleptric avatar Sep 19 '24 18:09 cleptric

Yes I can. Before I change the interface to support v1, I'm curious if we can update to v3? Is that an option?

ribice avatar Sep 19 '24 18:09 ribice

Fine with me.

cleptric avatar Sep 19 '24 23:09 cleptric

Thank you for looking into this guys :)

kydemy-fran avatar Sep 20 '24 07:09 kydemy-fran

Upgraded negroni to latest version in #885. This worked just fine: https://gist.github.com/ribice/95934b3c209b9692efc4b50b91d5dd4a

ribice avatar Sep 20 '24 09:09 ribice

@kydemy-fran Can you confirm that it works as expected with 0.29.1?

ribice avatar Oct 14 '24 12:10 ribice

Hi there @ribice and @cleptric. I've just tested it and it seems to be working fine using the negroni v3 implementation. Thank you for your help!!

kydemy-fran avatar Oct 15 '24 08:10 kydemy-fran