getsentry / sentry-go

The official Go SDK for Sentry (sentry.io)
https://docs.sentry.io/platforms/go/
MIT License
897 stars 211 forks source link

Tunnel Support #705

Closed 02strich closed 11 months ago

02strich commented 1 year ago

Summary

I would like to use the Tunnel feature available in the Node SDK also in the Go one.

Motivation

This feature allows tunneling Sentry reports via a different endpoint. In the case of the Node SDK this is mostly to deal with same-origin requirements of browsers (so the tunnel endpoint is part of the same domain as where the Sentry-supported web-app runs). In the Go case, we have to deal with firewall rules that allow certain endpoints already, which we would like to re-use also for Sentry reports.

Additional Context

I have a change to the code ready that adds the feature, but wanted to raise the topic first to get some feedback.

tonyo commented 1 year ago

Would modifying the DSN work for you, perhaps? DSN is not an exact URL, but e.g. if your DSN is https://public@sentry.example.com/123: you can set sentry.example.com to the desired hostname (newhost.com), and then the data will be sent to newhost.com/api/123/envelope/

02strich commented 1 year ago

I tried that but ended up with two constraints:

  1. It forced me to have a username for the URL which was unclear on how it would be used
  2. It forces me to have a very specific endpoint, that I wonder whether it might change in the future (which would be hard for us to follow due to the deployment location of the code).

As such while it might work, it seems sub-optimal.

tonyo commented 1 year ago

Another alternative (without implementing it in the SDK) could be implementing a custom SDK Transport (example) that implements the logic.

To clarify your use case: you have a Go app, and now you want all Sentry events from it to be sent to some example.com/endpoint that bypasses the firewall? What will accept those events on the other end, some kind of proxy/forwarder?

I have a change to the code ready that adds the feature, but wanted to raise the topic first to get some feedback.

You can totally open a PR, but we cannot guarantee that it'll be on a high-prio list for reviewing/merging, since it's a pretty special use case IMO.

02strich commented 11 months ago

Thanks for the pointers and the link to the section in the document. This works and is a lot simpler than I originally thought (I had tried to use the transport interface).