Skip to content

Commit bbdbf40

Browse files
committed
save some bytes in httpContext integration when tree-shaking tracing
1 parent e4169b5 commit bbdbf40

File tree

1 file changed

+16
-11
lines changed

1 file changed

+16
-11
lines changed

packages/browser/src/integrations/httpcontext.ts

Lines changed: 16 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,9 @@ import {
66
} from '@sentry/core';
77
import { getHttpRequestData, WINDOW } from '../helpers';
88

9+
// Treeshakable guard to remove all code related to tracing
10+
declare const __SENTRY_TRACING__: boolean | undefined;
11+
912
/**
1013
* Collects information about HTTP request headers and
1114
* attaches them to the event.
@@ -20,19 +23,21 @@ export const httpContextIntegration = defineIntegration(() => {
2023
return;
2124
}
2225

23-
if (client.getOptions().traceLifecycle === 'stream') {
24-
client.on('processSpan', spanJSON => {
25-
if (spanJSON.is_segment) {
26-
const { url, headers } = getHttpRequestData();
26+
if (typeof __SENTRY_TRACING__ === 'undefined' || __SENTRY_TRACING__) {
27+
if (client.getOptions().traceLifecycle === 'stream') {
28+
client.on('processSpan', spanJSON => {
29+
if (spanJSON.is_segment) {
30+
const { url, headers } = getHttpRequestData();
2731

28-
const attributeHeaders = httpHeadersToSpanAttributes(headers);
32+
const attributeHeaders = httpHeadersToSpanAttributes(headers);
2933

30-
safeSetSpanJSONAttributes(spanJSON, {
31-
[SEMANTIC_ATTRIBUTE_URL_FULL]: url,
32-
...attributeHeaders,
33-
});
34-
}
35-
});
34+
safeSetSpanJSONAttributes(spanJSON, {
35+
[SEMANTIC_ATTRIBUTE_URL_FULL]: url,
36+
...attributeHeaders,
37+
});
38+
}
39+
});
40+
}
3641
}
3742
},
3843
preprocessEvent(event) {

0 commit comments

Comments
 (0)