Skip to content

Commit

Permalink
Set real path for gin transaction on 404
Browse files Browse the repository at this point in the history
  • Loading branch information
antonsacred committed Aug 14, 2023
1 parent ba3e92d commit 3b50c09
Show file tree
Hide file tree
Showing 2 changed files with 26 additions and 0 deletions.
4 changes: 4 additions & 0 deletions gin/sentrygin.go
Original file line number Diff line number Diff line change
Expand Up @@ -65,6 +65,10 @@ func (h *handler) handle(c *gin.Context) {
options...,
)
defer func() {
if c.Writer.Status() == 404 {
transaction.Name = fmt.Sprintf("%s %s", c.Request.Method, c.Request.URL.Path)
transaction.Source = sentry.SourceURL
}
transaction.Status = sentry.HTTPtoSpanStatus(c.Writer.Status())
transaction.Finish()
}()
Expand Down
22 changes: 22 additions & 0 deletions gin/sentrygin_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -64,6 +64,28 @@ func TestIntegration(t *testing.T) {
},
},
},
{
Path: "/404/1",
Method: "GET",
WantStatus: 404,
Handler: func(c *gin.Context) {
c.AbortWithStatus(404)
},
WantTransaction: &sentry.Event{
Level: sentry.LevelInfo,
Type: "transaction",
Transaction: "GET /404/1",
Request: &sentry.Request{
URL: "/404/1",
Method: "GET",
Headers: map[string]string{
"Accept-Encoding": "gzip",
"User-Agent": "Go-http-client/1.1",
},
},
TransactionInfo: &sentry.TransactionInfo{Source: "url"},
},
},
{
Path: "/post",
Method: "POST",
Expand Down

0 comments on commit 3b50c09

Please sign in to comment.