Skip to content

Commit 1b25948

Browse files
committed
feat(core)!: Update hasTracingEnabled to consider empty trace config
1 parent 4415881 commit 1b25948

File tree

4 files changed

+20
-10
lines changed

4 files changed

+20
-10
lines changed

docs/migration/v8-to-v9.md

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -68,6 +68,16 @@ Sentry.init({
6868
});
6969
```
7070

71+
- In previous versions, we determined if tracing is enabled (for Tracing Without Performance) by checking if either `tracesSampleRate` or `traceSampler` are _defined_ at all, in `Sentry.init()`. This means that e.g. the following config would lead to tracing without performance (=tracing being enabled, even if no spans would be started):
72+
73+
```js
74+
Sentry.init({
75+
tracesSampleRate: undefined,
76+
});
77+
```
78+
79+
In v9, an `undefined` value will be treated the same as if the value is not defined at all. You'll need to set `tracesSampleRate: 0` if you want to enable tracing without performance.
80+
7181
### `@sentry/node`
7282

7383
- When `skipOpenTelemetrySetup: true` is configured, `httpIntegration({ spans: false })` will be configured by default. This means that you no longer have to specify this yourself in this scenario. With this change, no spans are emitted once `skipOpenTelemetrySetup: true` is configured, without any further configuration being needed.

packages/browser/src/sdk.ts

Lines changed: 5 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,7 @@
11
import {
22
consoleSandbox,
33
dedupeIntegration,
4+
dropUndefinedKeys,
45
functionToStringIntegration,
56
getCurrentScope,
67
getIntegrationsToSetup,
@@ -64,15 +65,10 @@ function applyDefaultOptions(optionsArg: BrowserOptions = {}): BrowserOptions {
6465
sendClientReports: true,
6566
};
6667

67-
// TODO: Instead of dropping just `defaultIntegrations`, we should simply
68-
// call `dropUndefinedKeys` on the entire `optionsArg`.
69-
// However, for this to work we need to adjust the `hasTracingEnabled()` logic
70-
// first as it differentiates between `undefined` and the key not being in the object.
71-
if (optionsArg.defaultIntegrations == null) {
72-
delete optionsArg.defaultIntegrations;
73-
}
74-
75-
return { ...defaultOptions, ...optionsArg };
68+
return {
69+
...defaultOptions,
70+
...dropUndefinedKeys(optionsArg),
71+
};
7672
}
7773

7874
type ExtensionProperties = {

packages/core/src/utils/hasTracingEnabled.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -19,5 +19,5 @@ export function hasTracingEnabled(
1919
const client = getClient();
2020
const options = maybeOptions || (client && client.getOptions());
2121
// eslint-disable-next-line deprecation/deprecation
22-
return !!options && (options.enableTracing || 'tracesSampleRate' in options || 'tracesSampler' in options);
22+
return !!options && (options.enableTracing || options.tracesSampleRate != null || !!options.tracesSampler);
2323
}

packages/core/test/lib/utils/hasTracingEnabled.test.ts

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -10,6 +10,10 @@ describe('hasTracingEnabled', () => {
1010
['With tracesSampleRate', { tracesSampleRate }, true],
1111
['With enableTracing=true', { enableTracing: true }, true],
1212
['With enableTracing=false', { enableTracing: false }, false],
13+
['With enableTracing=undefined', { enableTracing: undefined }, false],
14+
['With tracesSampleRate=undefined', { tracesSampleRate: undefined }, false],
15+
['With tracesSampleRate=0', { tracesSampleRate: 0 }, true],
16+
['With tracesSampler=undefined', { tracesSampler: undefined }, false],
1317
['With tracesSampler && enableTracing=false', { tracesSampler, enableTracing: false }, true],
1418
['With tracesSampleRate && enableTracing=false', { tracesSampler, enableTracing: false }, true],
1519
['With tracesSampler and tracesSampleRate', { tracesSampler, tracesSampleRate }, true],

0 commit comments

Comments
 (0)