getsentry / sentry-go

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

Ship a version of the library without all of the external HTTP libraries #361

Closed kevinburke1 closed 3 years ago

kevinburke1 commented 3 years ago

Because of the third party library imports and examples, anyone who imports this library ends up with every Go third party HTTP integration in their go.sum file. This makes installs and vendoring slower than they'd otherwise be, and makes me do a double take every time (why are we loading kataras/iris??).

For fun I forked the project and removed all of the third party dependencies and it makes quite a big difference to the go.sum file. The core functionality of the library is unaffected.

module github.com/getsentry/sentry-go

-go 1.14
+go 1.16

 require (
-   github.com/ajg/form v1.5.1 // indirect
-   github.com/codegangsta/inject v0.0.0-20150114235600-33e0aa1cb7c0 // indirect
-   github.com/fasthttp-contrib/websocket v0.0.0-20160511215533-1f3b11f56072 // indirect
-   github.com/gin-gonic/gin v1.4.0
    github.com/go-errors/errors v1.0.1
-   github.com/go-martini/martini v0.0.0-20170121215854-22fa46961aab
    github.com/google/go-cmp v0.5.5
-   github.com/google/go-querystring v1.0.0 // indirect
-   github.com/imkira/go-interpol v1.1.0 // indirect
-   github.com/k0kubun/colorstring v0.0.0-20150214042306-9440f1994b88 // indirect
-   github.com/kataras/iris/v12 v12.1.8
-   github.com/labstack/echo/v4 v4.1.11
-   github.com/moul/http2curl v1.0.0 // indirect
-   github.com/onsi/ginkgo v1.10.3 // indirect
-   github.com/onsi/gomega v1.7.1 // indirect
    github.com/pingcap/errors v0.11.4
    github.com/pkg/errors v0.8.1
-   github.com/sergi/go-diff v1.0.0 // indirect
-   github.com/shurcooL/sanitized_anchor_name v1.0.0 // indirect
-   github.com/smartystreets/goconvey v1.6.4 // indirect
-   github.com/ugorji/go v1.1.7 // indirect
-   github.com/urfave/negroni v1.0.0
-   github.com/valyala/fasthttp v1.6.0
-   github.com/xeipuuv/gojsonschema v1.2.0 // indirect
-   github.com/yalp/jsonpath v0.0.0-20180802001716-5cc68e5049a0 // indirect
-   github.com/yudai/gojsondiff v1.0.0 // indirect
-   github.com/yudai/golcs v0.0.0-20170316035057-ecda9a501e82 // indirect
-   github.com/yudai/pp v2.0.1+incompatible // indirect
 )

It would be nice if you made it possible to export this version, instead of having them all bundled in as they are currently. See https://github.com/meterup/sentry-go/pull/1 for the patch.

rhcarvalho commented 3 years ago

I think this is essentially a duplicate of #156.

I understand that all sorts of confusion arise from seeing references to apparently unrelated packages/modules, but I'm not sure how "makes installs and vendoring slower" is quantitatively measurable. Do you have some data to share?

Here's a small unscientific experiment that shows the (lack of) difference between vendoring github.com/getsentry/sentry-go and the github.com/meterup/sentry-go fork ```console $ mkdir /tmp/mod1 $ cd /tmp/mod1 $ go mod init mod1 go: creating new go.mod: module mod1 $ go mod edit -require github.com/getsentry/sentry-go@v0.11.0 $ cat go.mod module mod1 go 1.16 require github.com/getsentry/sentry-go v0.11.0 $ vim main.go $ cat main.go package main import ( "fmt" "github.com/getsentry/sentry-go" ) func main() { fmt.Println(sentry.Version) } $ mkdir /tmp/gopath1 $ export GOPATH=/tmp/gopath1 $ time go mod vendor go: downloading github.com/getsentry/sentry-go v0.11.0 go mod vendor 0.46s user 1.07s system 21% cpu 7.030 total ``` ```console $ mkdir /tmp/mod2 $ cd /tmp/mod2 $ go mod init mod2 go: creating new go.mod: module mod2 $ go mod edit -require github.com/getsentry/sentry-go@v0.11.0 $ go mod edit -replace github.com/getsentry/sentry-go=github.com/meterup/sentry-go@master $ cat go.mod module mod2 go 1.16 require github.com/getsentry/sentry-go v0.11.0 replace github.com/getsentry/sentry-go => github.com/meterup/sentry-go master $ cp /tmp/mod1/main.go /tmp/mod2/main.go $ mkdir /tmp/gopath2 $ export GOPATH=/tmp/gopath2 $ time go mod vendor go: downloading github.com/meterup/sentry-go v0.11.1-0.20210527165036-5632c1961b3c go mod vendor 0.23s user 0.34s system 4% cpu 12.168 total ``` ```console $ du -sh /tmp/mod1/vendor /tmp/mod2/vendor 268K /tmp/mod1/vendor 248K /tmp/mod2/vendor $ du -sh /tmp/gopath1 /tmp/gopath2 2.1M /tmp/gopath1 888K /tmp/gopath2 ```
kevinburke1 commented 3 years ago

I ran each one in its own Docker container with no cache and got the following timings, FWIW.

time go mod vendor
go: downloading github.com/getsentry/sentry-go v0.11.0

real    0m1.369s
user    0m1.039s
sys 0m2.340s

Forked version

time go mod vendor
go: downloading github.com/meterup/sentry-go v0.11.1-0.20210527165036-5632c1961b3c

real    0m0.750s
user    0m0.209s
sys 0m0.356s
dolmen commented 3 years ago

I shouldn't have to import a Web framework into my project (github.com/kataras/iris/v12 is a module dependency) just to send errors to Sentry with package github.com/getsentry/sentry-go. This is dependency pollution.

Package github.com/getsentry/sentry-go/iris should be in its own Go module. Same for gin, fasthttp, martini, negroni.

Each example should also be in its own Go module.

rhcarvalho commented 3 years ago

Closing as a duplicate of #156.