Skip to content

Commit

Permalink
transport: Set attempts in Sentry transaction
Browse files Browse the repository at this point in the history
  • Loading branch information
monstermunchkin committed Dec 2, 2024
1 parent 53dce24 commit f46f39c
Showing 1 changed file with 13 additions and 1 deletion.
14 changes: 13 additions & 1 deletion http/transport/attempt_round_tripper.go
Original file line number Diff line number Diff line change
Expand Up @@ -4,8 +4,11 @@ package transport

import (
"context"
"fmt"
"net/http"
"sync/atomic"

"github.com/getsentry/sentry-go"
)

type ctxkey int
Expand All @@ -29,7 +32,16 @@ func (l *attemptRoundTripper) RoundTrip(req *http.Request) (*http.Response, erro
a := atomic.AddInt32(&l.attempt, 1)
ctx := context.WithValue(req.Context(), attemptKey, a)

return l.Transport().RoundTrip(req.WithContext(ctx))
resp, err := l.Transport().RoundTrip(req.WithContext(ctx))

if a > 0 {
transaction := sentry.TransactionFromContext(req.Context())
if transaction != nil {
transaction.SetData("attempt", fmt.Sprintf("%d", a))
}
}

return resp, err
}

func attemptFromCtx(ctx context.Context) int32 {
Expand Down

0 comments on commit f46f39c

Please sign in to comment.