Debian Codegraph @

otel/internal/utils/sentryrequest.go

raw
1 package utils
2
3 import (
4 "context"
5 "strings"
6
7 "github.com/getsentry/sentry-go"
8 "go.opentelemetry.io/otel/sdk/trace"
9 semconv "go.opentelemetry.io/otel/semconv/v1.12.0"
10 )
11
12 func IsSentryRequestSpan(ctx context.Context, s trace.ReadOnlySpan) bool {
13 attributes := s.Attributes()
14
15 // TODO(michi): can we access the attribute directly?
16 for _, attribute := range attributes {
17 if attribute.Key == semconv.HTTPURLKey {
18 return isSentryRequestUrl(ctx, attribute.Value.AsString())
19 }
20 }
21
22 return false
23 }
24
25 func isSentryRequestUrl(ctx context.Context, url string) bool {
26 hub := sentry.GetHubFromContext(ctx)
27 if hub == nil {
28 hub = sentry.CurrentHub()
29 if hub == nil {
30 return false
31 }
32 }
33
34 client := hub.Client()
35 if client == nil {
36 return false
37 }
38
39 dsn, err := sentry.NewDsn(client.Options().Dsn)
40 if err != nil {
41 return false
42 }
43
44 return strings.Contains(url, dsn.GetAPIURL().String())
45 }