Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix: Improve isSentryRequestUrl #632

Merged
merged 1 commit into from May 4, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
7 changes: 5 additions & 2 deletions otel/internal/utils/sentryrequest.go
Expand Up @@ -27,7 +27,10 @@
func isSentryRequestUrl(ctx context.Context, url string) bool {
hub := sentry.GetHubFromContext(ctx)
if hub == nil {
return false
hub = sentry.CurrentHub()
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Note: for better experience and to fix more cases like this, we might want to set the Hub on context a lot earlier, maybe even in StartSpan.

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

We might not know which hub to set on the ctx in StartSpan.
I think it might be worth digging a little bit into how Otel handles go routines.
For now, we might still consider this as a quick win.

if hub == nil {
return false
}

Check warning on line 33 in otel/internal/utils/sentryrequest.go

View check run for this annotation

Codecov / codecov/patch

otel/internal/utils/sentryrequest.go#L30-L33

Added lines #L30 - L33 were not covered by tests
}

client := hub.Client()
Expand All @@ -36,5 +39,5 @@
}

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