Skip to content

Commit f46f39c

Browse files
transport: Set attempts in Sentry transaction
1 parent 53dce24 commit f46f39c

File tree

1 file changed

+13
-1
lines changed

1 file changed

+13
-1
lines changed

http/transport/attempt_round_tripper.go

+13-1
Original file line numberDiff line numberDiff line change
@@ -4,8 +4,11 @@ package transport
44

55
import (
66
"context"
7+
"fmt"
78
"net/http"
89
"sync/atomic"
10+
11+
"github.com/getsentry/sentry-go"
912
)
1013

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

32-
return l.Transport().RoundTrip(req.WithContext(ctx))
35+
resp, err := l.Transport().RoundTrip(req.WithContext(ctx))
36+
37+
if a > 0 {
38+
transaction := sentry.TransactionFromContext(req.Context())
39+
if transaction != nil {
40+
transaction.SetData("attempt", fmt.Sprintf("%d", a))
41+
}
42+
}
43+
44+
return resp, err
3345
}
3446

3547
func attemptFromCtx(ctx context.Context) int32 {

0 commit comments

Comments
 (0)