diff --git a/CHANGELOG.md b/CHANGELOG.md index 096a84bb0..f92e704ae 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -5,6 +5,11 @@ - Remove Martini integration ([#861](https://github.com/getsentry/sentry-go/pull/861)) - Fix closure functions name grouping ([#877](https://github.com/getsentry/sentry-go/pull/877)) + +### Breaking Changes + +- WrapResponseWriter has been moved from sentryhttp to sentry. If you've imported it from sentryhttp, you'll need to update your imports. + ## 0.28.1 The Sentry SDK team is happy to announce the immediate availability of Sentry Go SDK v0.28.1. diff --git a/http/sentryhttp.go b/http/sentryhttp.go index 0eb998c57..9912530e5 100644 --- a/http/sentryhttp.go +++ b/http/sentryhttp.go @@ -107,7 +107,7 @@ func (h *Handler) handle(handler http.Handler) http.HandlerFunc { ) transaction.SetData("http.request.method", r.Method) - rw := NewWrapResponseWriter(w, r.ProtoMajor) + rw := sentry.NewWrapResponseWriter(w, r.ProtoMajor) defer func() { status := rw.Status() diff --git a/negroni/sentrynegroni.go b/negroni/sentrynegroni.go index 2a49695d5..c7623e7dd 100644 --- a/negroni/sentrynegroni.go +++ b/negroni/sentrynegroni.go @@ -45,22 +45,6 @@ func New(options Options) negroni.Handler { } } -// responseWriter is a wrapper around http.ResponseWriter that captures the status code. -type responseWriter struct { - http.ResponseWriter - statusCode int -} - -// WriteHeader captures the status code and calls the original WriteHeader method. -func (rw *responseWriter) WriteHeader(code int) { - rw.statusCode = code - rw.ResponseWriter.WriteHeader(code) -} - -func newResponseWriter(w http.ResponseWriter) *responseWriter { - return &responseWriter{ResponseWriter: w, statusCode: http.StatusOK} -} - func (h *handler) ServeHTTP(w http.ResponseWriter, r *http.Request, next http.HandlerFunc) { ctx := r.Context() hub := sentry.GetHubFromContext(ctx) @@ -91,10 +75,10 @@ func (h *handler) ServeHTTP(w http.ResponseWriter, r *http.Request, next http.Ha options..., ) transaction.SetData("http.request.method", r.Method) - rw := newResponseWriter(w) + rw := sentry.NewWrapResponseWriter(w, r.ProtoMajor) defer func() { - status := rw.statusCode + status := rw.Status() transaction.Status = sentry.HTTPtoSpanStatus(status) transaction.SetData("http.response.status_code", status) transaction.Finish() diff --git a/http/wrap_writer.go b/wrap_writer.go similarity index 99% rename from http/wrap_writer.go rename to wrap_writer.go index 053c33cbf..01f5f45cd 100644 --- a/http/wrap_writer.go +++ b/wrap_writer.go @@ -1,4 +1,4 @@ -package sentryhttp +package sentry import ( "bufio" diff --git a/http/wrap_writer_test.go b/wrap_writer_test.go similarity index 99% rename from http/wrap_writer_test.go rename to wrap_writer_test.go index 057a22e3d..b4cdc9e09 100644 --- a/http/wrap_writer_test.go +++ b/wrap_writer_test.go @@ -1,4 +1,4 @@ -package sentryhttp +package sentry import ( "bufio"