Skip to content

Commit

Permalink
fix: Improve isSentryRequestUrl (#632)
Browse files Browse the repository at this point in the history
  • Loading branch information
cleptric committed May 4, 2023
1 parent eb7fca9 commit f7478f0
Show file tree
Hide file tree
Showing 2 changed files with 6 additions and 3 deletions.
7 changes: 5 additions & 2 deletions otel/internal/utils/sentryrequest.go
Expand Up @@ -27,7 +27,10 @@ func IsSentryRequestSpan(ctx context.Context, s trace.ReadOnlySpan) bool {
func isSentryRequestUrl(ctx context.Context, url string) bool {
hub := sentry.GetHubFromContext(ctx)
if hub == nil {
return false
hub = sentry.CurrentHub()
if hub == nil {
return false
}
}

client := hub.Client()
Expand All @@ -36,5 +39,5 @@ func isSentryRequestUrl(ctx context.Context, url string) bool {
}

dsn, _ := sentry.NewDsn(client.Options().Dsn)
return strings.Contains(url, dsn.GetHost())
return strings.Contains(url, dsn.GetHost()) && strings.Contains(url, dsn.GetProjectID())
}
2 changes: 1 addition & 1 deletion otel/span_processor_test.go
Expand Up @@ -313,7 +313,7 @@ func TestOnEndDoesNotFinishSentryRequests(t *testing.T) {
emptyContextWithSentry(),
"POST to Sentry",
// Hostname is same as in Sentry DSN
trace.WithAttributes(attribute.String("http.url", "https://example.com/sub/route")),
trace.WithAttributes(attribute.String("http.url", "https://example.com/123")),
)
sentrySpan, _ := sentrySpanMap.Get(otelSpan.SpanContext().SpanID())
otelSpan.End()
Expand Down

0 comments on commit f7478f0

Please sign in to comment.