Skip to content

Commit e503187

Browse files
committed
ref(astro): Streamline how we add browser tracing
1 parent caad0bc commit e503187

File tree

2 files changed

+15
-17
lines changed

2 files changed

+15
-17
lines changed

packages/astro/src/client/sdk.ts

Lines changed: 13 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
import type { BrowserOptions } from '@sentry/browser';
2-
import { BrowserTracing, init as initBrowserSdk } from '@sentry/browser';
3-
import { getCurrentScope, hasTracingEnabled } from '@sentry/core';
4-
import { addOrUpdateIntegration } from '@sentry/utils';
2+
import { BrowserTracing, defaultIntegrations, init as initBrowserSdk, setTag } from '@sentry/browser';
3+
import { hasTracingEnabled } from '@sentry/core';
4+
import type { Integration } from '@sentry/types';
55

66
import { applySdkMetadata } from '../common/metadata';
77

@@ -14,27 +14,26 @@ declare const __SENTRY_TRACING__: boolean;
1414
* @param options Configuration options for the SDK.
1515
*/
1616
export function init(options: BrowserOptions): void {
17-
applySdkMetadata(options, ['astro', 'browser']);
17+
const opts = {
18+
defaultIntegrations: getDefaultIntegrations(options),
19+
...options,
20+
};
1821

19-
addClientIntegrations(options);
22+
applySdkMetadata(opts, ['astro', 'browser']);
2023

21-
initBrowserSdk(options);
24+
initBrowserSdk(opts);
2225

23-
getCurrentScope().setTag('runtime', 'browser');
26+
setTag('runtime', 'browser');
2427
}
2528

26-
function addClientIntegrations(options: BrowserOptions): void {
27-
let integrations = options.integrations || [];
28-
29+
function getDefaultIntegrations(options: BrowserOptions): Integration[] | undefined {
2930
// This evaluates to true unless __SENTRY_TRACING__ is text-replaced with "false",
3031
// in which case everything inside will get treeshaken away
3132
if (typeof __SENTRY_TRACING__ === 'undefined' || __SENTRY_TRACING__) {
3233
if (hasTracingEnabled(options)) {
33-
const defaultBrowserTracingIntegration = new BrowserTracing({});
34-
35-
integrations = addOrUpdateIntegration(defaultBrowserTracingIntegration, integrations);
34+
return [...defaultIntegrations, new BrowserTracing()];
3635
}
3736
}
3837

39-
options.integrations = integrations;
38+
return undefined;
4039
}

packages/astro/src/server/sdk.ts

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,5 @@
1-
import { getCurrentScope } from '@sentry/core';
21
import type { NodeOptions } from '@sentry/node';
3-
import { init as initNodeSdk } from '@sentry/node';
2+
import { init as initNodeSdk, setTag } from '@sentry/node';
43

54
import { applySdkMetadata } from '../common/metadata';
65

@@ -13,5 +12,5 @@ export function init(options: NodeOptions): void {
1312

1413
initNodeSdk(options);
1514

16-
getCurrentScope().setTag('runtime', 'node');
15+
setTag('runtime', 'node');
1716
}

0 commit comments

Comments
 (0)