Skip to content

Commit

Permalink
Implement hijacker interface for Negroni integration (#871)
Browse files Browse the repository at this point in the history
  • Loading branch information
ribice authored Sep 3, 2024
1 parent bff876d commit e5d46d5
Show file tree
Hide file tree
Showing 5 changed files with 10 additions and 21 deletions.
5 changes: 5 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -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.
Expand Down
2 changes: 1 addition & 1 deletion http/sentryhttp.go
Original file line number Diff line number Diff line change
Expand Up @@ -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()
Expand Down
20 changes: 2 additions & 18 deletions negroni/sentrynegroni.go
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand Down Expand Up @@ -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()
Expand Down
2 changes: 1 addition & 1 deletion http/wrap_writer.go → wrap_writer.go
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
package sentryhttp
package sentry

import (
"bufio"
Expand Down
2 changes: 1 addition & 1 deletion http/wrap_writer_test.go → wrap_writer_test.go
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
package sentryhttp
package sentry

import (
"bufio"
Expand Down

0 comments on commit e5d46d5

Please sign in to comment.