Skip to content

Conversation

@aldy505
Copy link
Contributor

@aldy505 aldy505 commented Aug 27, 2024

An effort to implement this: https://develop.sentry.dev/sdk/telemetry/traces/modules/requests/

Since we already have tracing without performance, this should be good to go.

@codecov
Copy link

codecov bot commented Aug 27, 2024

Codecov Report

✅ All modified and coverable lines are covered by tests.
✅ Project coverage is 86.23%. Comparing base (c243873) to head (4cc9a92).

Additional details and impacted files
@@            Coverage Diff             @@
##           master     #876      +/-   ##
==========================================
+ Coverage   86.07%   86.23%   +0.16%     
==========================================
  Files          62       63       +1     
  Lines        6090     6148      +58     
==========================================
+ Hits         5242     5302      +60     
+ Misses        634      631       -3     
- Partials      214      215       +1     

☔ View full report in Codecov by Sentry.
📢 Have feedback on the report? Share it here.

🚀 New features to boost your workflow:
  • ❄️ Test Analytics: Detect flaky tests, report on failures, and find test suite problems.

@ribice
Copy link
Collaborator

ribice commented Sep 3, 2024

@aldy505 We should document this (in _examples, and perhaps sentry-docs?), and also update changelog accordingly.

@aldy505 aldy505 requested a review from ribice September 3, 2024 14:04
@aldy505 aldy505 requested a review from cleptric September 4, 2024 01:06
Comment on lines 70 to 74
// Only create the `http.client` span only if there is a parent span.
parentSpan := sentry.GetSpanFromContext(request.Context())
if parentSpan == nil {
return s.originalRoundTripper.RoundTrip(request)
}
Copy link
Contributor Author

Choose a reason for hiding this comment

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

A quick note why I prefer this instead of creating a sentry.WithOnlyIfParentExists() (a SpanOption type):

I used the JS SDK a lot at work lately, and I've been wondering the entire week, on their startSpan function, they have this as an option: https://github.com/getsentry/sentry-javascript/blob/216aaeba1ee27cce8a4876e1f9212ba374eb30b3/packages/types/src/startSpanOptions.ts#L14-L15

Should the Go SDK move forward with that, as a SpanOption or not?

We could to the SpanOption thing, but it feels really weird since the way Go SDK handles scopes/hubs with span is to add the span pointer into the scope. See

sentry-go/tracing.go

Lines 196 to 199 in a6acd05

if clientOptions.EnableTracing {
hub := hubFromContext(ctx)
hub.Scope().SetSpan(&span)
}

Although we could just not call the scope.SetSpan() function, I don't know about the behavior if this span that we're creating will ever have a child span being created manually by the user.

Comment on lines +88 to +90
// Always add `Baggage` and `Sentry-Trace` headers.
request.Header.Add("Baggage", span.ToBaggage())
request.Header.Add("Sentry-Trace", span.ToSentryTrace())
Copy link
Member

Choose a reason for hiding this comment

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

To support the recently added "Tracing without Performance" feature, we should use hub.GetTraceparent() and hub.GetBaggage()

@aldy505 aldy505 requested a review from cleptric November 6, 2024 13:59
@aldy505 aldy505 requested a review from cleptric November 16, 2024 11:02
@aldy505 aldy505 requested a review from cleptric May 7, 2025 03:29
@aldy505
Copy link
Contributor Author

aldy505 commented May 12, 2025

@giortzisg @cleptric Is there anything that's blocking this PR to be merged?

@cleptric
Copy link
Member

Not sure we actually want to go the route with the round tripper. But we take another look after logs.

@aldy505
Copy link
Contributor Author

aldy505 commented Sep 25, 2025

@cleptric @giortzisg any updates?

@giortzisg
Copy link
Contributor

Will have a look after transport refactoring.

RequestMethod: "OPTIONS",
RequestURL: "https://example.com",
WantError: false,
WantSpan: nil,
Copy link
Contributor

Choose a reason for hiding this comment

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

also we should get a span here.

@aldy505
Copy link
Contributor Author

aldy505 commented Nov 30, 2025

@giortzisg updated

}

// With Sentry's HTTP client
err = getExamplePage(ctx, sentryhttpclient.Client)
Copy link

Choose a reason for hiding this comment

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

Bug: The example _examples/httpclient/main.go uses the non-existent sentryhttpclient.Client variable, leading to a compilation error.
Severity: CRITICAL | Confidence: High

🔍 Detailed Analysis

The example file _examples/httpclient/main.go on line 41 attempts to use sentryhttpclient.Client. However, the sentryhttpclient.Client variable does not exist, as it was intentionally removed from the httpclient package in recent commits. This oversight means the example was not updated, causing a compilation failure and rendering the example non-functional.

💡 Suggested Fix

Update _examples/httpclient/main.go to either remove the section using sentryhttpclient.Client or create a local http.Client with the RoundTripper as shown in lines 31-33.

🤖 Prompt for AI Agent
Review the code at the location below. A potential bug has been identified by an AI
agent.
Verify if this is a real issue. If it is, propose a fix; if not, explain why it's not
valid.

Location: _examples/httpclient/main.go#L41

Potential issue: The example file `_examples/httpclient/main.go` on line 41 attempts to
use `sentryhttpclient.Client`. However, the `sentryhttpclient.Client` variable does not
exist, as it was intentionally removed from the `httpclient` package in recent commits.
This oversight means the example was not updated, causing a compilation failure and
rendering the example non-functional.

Did we get this right? 👍 / 👎 to inform future reviews.
Reference ID: 4362237

if tt.WantSpan != nil && !foundMatch {
t.Errorf("Span mismatch (-want +got):\n%s", strings.Join(diffs, "\n"))
} else if tt.WantSpan == nil && foundMatch {
t.Errorf("Expected no span, got %+v", gotSpans)
Copy link

Choose a reason for hiding this comment

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

Bug: Test cannot detect unwanted spans when expecting none

The test logic for validating the "no span expected" case is broken. When WantSpan is nil, the condition tt.WantSpan == nil && foundMatch at line 308 can never trigger because foundMatch only becomes true when cmp.Diff returns an empty string, but cmp.Diff(nil, gotSpan) always returns a diff when comparing nil to an actual span. This means if the implementation incorrectly creates an http.client span when none is expected (like when a URL doesn't match trace propagation targets), the test will silently pass instead of catching the bug.

Fix in Cursor Fix in Web

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

Feature Issue type

Projects

None yet

Development

Successfully merging this pull request may close these issues.

5 participants