Skip to content

Commit

Permalink
feat(starfish): add http.request.method attribute to span data (#786)
Browse files Browse the repository at this point in the history
* feat(starfish): add  attribute to span data

* test: add Extra field on gin tests

* chore: add changelog

---------

Co-authored-by: Emir Ribić <[email protected]>
Co-authored-by: Ivan Dlugos <[email protected]>
  • Loading branch information
3 people authored Mar 26, 2024
1 parent a084ac9 commit 08cdc59
Show file tree
Hide file tree
Showing 4 changed files with 10 additions and 0 deletions.
1 change: 1 addition & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@

- Accept `interface{}` for span data values ([#784](https://github.com/getsentry/sentry-go/pull/784))
- Automatic transactions for Echo integration ([#722](https://github.com/getsentry/sentry-go/pull/722))
- Add `http.request.method` attribute for performance span data ([#786](https://github.com/getsentry/sentry-go/pull/786))
- Automatic transactions for Fasthttp integration ([#732](https://github.com/getsentry/sentry-go/pull/723))
- Add `Fiber` integration ([#795](https://github.com/getsentry/sentry-go/pull/795))

Expand Down
1 change: 1 addition & 0 deletions gin/sentrygin.go
Original file line number Diff line number Diff line change
Expand Up @@ -83,6 +83,7 @@ func (h *handler) handle(c *gin.Context) {
fmt.Sprintf("%s %s", c.Request.Method, transactionName),
options...,
)
transaction.SetData("http.request.method", c.Request.Method)
defer func() {
transaction.Status = sentry.HTTPtoSpanStatus(c.Writer.Status())
transaction.Finish()
Expand Down
7 changes: 7 additions & 0 deletions gin/sentrygin_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -53,6 +53,7 @@ func TestIntegration(t *testing.T) {
},
},
TransactionInfo: &sentry.TransactionInfo{Source: "route"},
Extra: map[string]interface{}{"http.request.method": string("GET")},
},
WantEvent: &sentry.Event{
Level: sentry.LevelFatal,
Expand Down Expand Up @@ -86,6 +87,7 @@ func TestIntegration(t *testing.T) {
},
},
TransactionInfo: &sentry.TransactionInfo{Source: "url"},
Extra: map[string]interface{}{"http.request.method": string("GET")},
},
WantEvent: nil,
},
Expand Down Expand Up @@ -119,6 +121,7 @@ func TestIntegration(t *testing.T) {
},
},
TransactionInfo: &sentry.TransactionInfo{Source: "route"},
Extra: map[string]interface{}{"http.request.method": string("POST")},
},
WantEvent: &sentry.Event{
Level: sentry.LevelInfo,
Expand Down Expand Up @@ -158,6 +161,7 @@ func TestIntegration(t *testing.T) {
},
},
TransactionInfo: &sentry.TransactionInfo{Source: "route"},
Extra: map[string]interface{}{"http.request.method": string("GET")},
},
WantEvent: &sentry.Event{
Level: sentry.LevelInfo,
Expand Down Expand Up @@ -200,6 +204,7 @@ func TestIntegration(t *testing.T) {
},
},
TransactionInfo: &sentry.TransactionInfo{Source: "route"},
Extra: map[string]interface{}{"http.request.method": string("POST")},
},
WantEvent: &sentry.Event{
Level: sentry.LevelInfo,
Expand Down Expand Up @@ -243,6 +248,7 @@ func TestIntegration(t *testing.T) {
},
},
TransactionInfo: &sentry.TransactionInfo{Source: "route"},
Extra: map[string]interface{}{"http.request.method": string("POST")},
},
WantEvent: &sentry.Event{
Level: sentry.LevelInfo,
Expand Down Expand Up @@ -281,6 +287,7 @@ func TestIntegration(t *testing.T) {
},
},
TransactionInfo: &sentry.TransactionInfo{Source: "route"},
Extra: map[string]interface{}{"http.request.method": string("GET")},
},
WantEvent: nil,
},
Expand Down
1 change: 1 addition & 0 deletions http/sentryhttp.go
Original file line number Diff line number Diff line change
Expand Up @@ -105,6 +105,7 @@ func (h *Handler) handle(handler http.Handler) http.HandlerFunc {
fmt.Sprintf("%s %s", r.Method, r.URL.Path),
options...,
)
transaction.SetData("http.request.method", r.Method)
defer transaction.Finish()
// TODO(tracing): if the next handler.ServeHTTP panics, store
// information on the transaction accordingly (status, tag,
Expand Down

0 comments on commit 08cdc59

Please sign in to comment.