From 08cdc59c249335362fc4e14d644e1a542e75a8ac Mon Sep 17 00:00:00 2001 From: Reinaldy Rafli Date: Tue, 26 Mar 2024 22:49:17 +0700 Subject: [PATCH] feat(starfish): add `http.request.method` attribute to span data (#786) MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit * feat(starfish): add attribute to span data * test: add Extra field on gin tests * chore: add changelog --------- Co-authored-by: Emir Ribić Co-authored-by: Ivan Dlugos <6349682+vaind@users.noreply.github.com> --- CHANGELOG.md | 1 + gin/sentrygin.go | 1 + gin/sentrygin_test.go | 7 +++++++ http/sentryhttp.go | 1 + 4 files changed, 10 insertions(+) diff --git a/CHANGELOG.md b/CHANGELOG.md index df584c281..f810a4cc1 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -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)) diff --git a/gin/sentrygin.go b/gin/sentrygin.go index 387699109..79abbf595 100644 --- a/gin/sentrygin.go +++ b/gin/sentrygin.go @@ -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() diff --git a/gin/sentrygin_test.go b/gin/sentrygin_test.go index e959716d5..4663f2037 100644 --- a/gin/sentrygin_test.go +++ b/gin/sentrygin_test.go @@ -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, @@ -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, }, @@ -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, @@ -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, @@ -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, @@ -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, @@ -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, }, diff --git a/http/sentryhttp.go b/http/sentryhttp.go index d581fd029..739e6a34b 100644 --- a/http/sentryhttp.go +++ b/http/sentryhttp.go @@ -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,