Skip to content

fix(node): Do not emit fetch spans when tracing is disabled #13003

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

Merged
merged 1 commit into from
Jul 23, 2024

Conversation

mydea
Copy link
Member

@mydea mydea commented Jul 22, 2024

Ensure that TWP works with fetch, but we do not emit a span. Otherwise, if a user does not use our tracing functionality but adds their own fetch instrumentation, they get spans twice.

The benefit we have with fetch is that fetch is instrumented via diagnostics channel, which means that this can be instrumented multiple times. So if we instrument it, on the plus side this does not interfere with a user instrumenting it again themselves if they want.

However, with the previous implementation our integration would always emit spans. If a user is using our own sampler, this is "OK" because it will sample it out. But if a user does not use our sampler, the spans we emit there get sent unintentionally.

With this change, we ensure to ignore requests if tracing is disabled. In order to make TWP work, we instead manually inject the propagator headers into the fetch request in this scenario.

Part of #12984

Fixes #12969

Ensure that TWP works with fetch, but we do not emit a span.
Otherwise, if a user does not use our tracing functionality but adds their own fetch instrumentation, they get spans twice.
@mydea mydea self-assigned this Jul 22, 2024
@@ -1,5 +1,5 @@
{
"name": "node-otel-sdk-trace",
"name": "node-otel-sdk-node",
Copy link
Member Author

Choose a reason for hiding this comment

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

noticed this name was actually not consistent.


createTestServer(done)
.get('/api/v0', headers => {
expect(headers['sentry-trace']).toEqual(expect.stringMatching(/^([a-f0-9]{32})-([a-f0-9]{16})$/));
expect(headers['sentry-trace']).not.toEqual('00000000000000000000000000000000-0000000000000000');
expect(headers['baggage']).toEqual(expect.any(String));
expect(headers['__requestUrl']).toBeUndefined();
Copy link
Member Author

Choose a reason for hiding this comment

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

this is actually not needed anymore, we do not set this anywhere, removed it in all places.

const url = request.origin;
return _ignoreOutgoingRequests && url && _ignoreOutgoingRequests(url);
ignoreRequestHook: (request: FetchRequest) => {
const url = getAbsoluteUrl(request.origin, request.path);
Copy link
Member Author

Choose a reason for hiding this comment

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

Noticed that this was actually incorrect, we just took the origin as URL, oops.

Copy link
Contributor

size-limit report 📦

Path Size
@sentry/browser 22.31 KB (0%)
@sentry/browser (incl. Tracing) 33.72 KB (0%)
@sentry/browser (incl. Tracing, Replay) 69.81 KB (0%)
@sentry/browser (incl. Tracing, Replay) - with treeshaking flags 63.15 KB (0%)
@sentry/browser (incl. Tracing, Replay with Canvas) 74.21 KB (0%)
@sentry/browser (incl. Tracing, Replay, Feedback) 86.52 KB (0%)
@sentry/browser (incl. Tracing, Replay, Feedback, metrics) 88.4 KB (0%)
@sentry/browser (incl. metrics) 26.62 KB (0%)
@sentry/browser (incl. Feedback) 38.98 KB (0%)
@sentry/browser (incl. sendFeedback) 26.93 KB (0%)
@sentry/browser (incl. FeedbackAsync) 31.54 KB (0%)
@sentry/react 25.08 KB (0%)
@sentry/react (incl. Tracing) 36.8 KB (0%)
@sentry/vue 26.45 KB (0%)
@sentry/vue (incl. Tracing) 35.61 KB (0%)
@sentry/svelte 22.44 KB (0%)
CDN Bundle 23.52 KB (0%)
CDN Bundle (incl. Tracing) 35.5 KB (0%)
CDN Bundle (incl. Tracing, Replay) 69.9 KB (0%)
CDN Bundle (incl. Tracing, Replay, Feedback) 75.17 KB (0%)
CDN Bundle - uncompressed 69 KB (0%)
CDN Bundle (incl. Tracing) - uncompressed 105.1 KB (0%)
CDN Bundle (incl. Tracing, Replay) - uncompressed 216.88 KB (0%)
CDN Bundle (incl. Tracing, Replay, Feedback) - uncompressed 229.6 KB (0%)
@sentry/nextjs (client) 36.66 KB (0%)
@sentry/sveltekit (client) 34.39 KB (0%)
@sentry/node 111.76 KB (+0.18% 🔺)
@sentry/node - without tracing 89.21 KB (+0.25% 🔺)
@sentry/aws-serverless 98.35 KB (+0.19% 🔺)


test('Sends an API route transaction to OTLP', async ({ baseURL }) => {
waitForTransaction('node-otel-without-tracing', transactionEvent => {
throw new Error('THIS SHOULD NEVER HAPPEN!');
Copy link
Member

Choose a reason for hiding this comment

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

nice idea to ensure something is not sent 😅

@mydea mydea merged commit 5a709df into develop Jul 23, 2024
106 checks passed
@mydea mydea deleted the fn/node-fetch-no-tracing branch July 23, 2024 08:07
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

Duplication of OpenTelemetry Spans in HTTP requests with @sentry/node
2 participants