Skip to content

Commit 8f5beb9

Browse files
committed
ref: Streamline SDK metadata handling
1 parent caad0bc commit 8f5beb9

File tree

25 files changed

+59
-257
lines changed

25 files changed

+59
-257
lines changed

packages/angular-ivy/src/sdk.ts

Lines changed: 3 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
import { VERSION } from '@angular/core';
22
import type { BrowserOptions } from '@sentry/browser';
3-
import { SDK_VERSION, defaultIntegrations, init as browserInit, setContext } from '@sentry/browser';
4-
import type { SdkMetadata } from '@sentry/types';
3+
import { defaultIntegrations, init as browserInit, setContext } from '@sentry/browser';
4+
import { applySdkMetadata } from '@sentry/core';
55
import { logger } from '@sentry/utils';
66

77
import { IS_DEBUG_BUILD } from './flags';
@@ -11,7 +11,6 @@ import { IS_DEBUG_BUILD } from './flags';
1111
*/
1212
export function init(options: BrowserOptions): void {
1313
const opts = {
14-
_metadata: {} as SdkMetadata,
1514
// Filter out TryCatch integration as it interferes with our Angular `ErrorHandler`:
1615
// TryCatch would catch certain errors before they reach the `ErrorHandler` and thus provide a
1716
// lower fidelity error than what `SentryErrorHandler` (see errorhandler.ts) would provide.
@@ -24,16 +23,7 @@ export function init(options: BrowserOptions): void {
2423
...options,
2524
};
2625

27-
opts._metadata.sdk = opts._metadata.sdk || {
28-
name: 'sentry.javascript.angular-ivy',
29-
packages: [
30-
{
31-
name: 'npm:@sentry/angular-ivy',
32-
version: SDK_VERSION,
33-
},
34-
],
35-
version: SDK_VERSION,
36-
};
26+
applySdkMetadata(opts, 'angular-ivy');
3727

3828
checkAndSetAngularVersion();
3929
browserInit(opts);

packages/angular/src/sdk.ts

Lines changed: 3 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
import { VERSION } from '@angular/core';
22
import type { BrowserOptions } from '@sentry/browser';
3-
import { SDK_VERSION, defaultIntegrations, init as browserInit, setContext } from '@sentry/browser';
4-
import type { SdkMetadata } from '@sentry/types';
3+
import { defaultIntegrations, init as browserInit, setContext } from '@sentry/browser';
4+
import { applySdkMetadata } from '@sentry/core';
55
import { logger } from '@sentry/utils';
66

77
import { IS_DEBUG_BUILD } from './flags';
@@ -11,7 +11,6 @@ import { IS_DEBUG_BUILD } from './flags';
1111
*/
1212
export function init(options: BrowserOptions): void {
1313
const opts = {
14-
_metadata: {} as SdkMetadata,
1514
// Filter out TryCatch integration as it interferes with our Angular `ErrorHandler`:
1615
// TryCatch would catch certain errors before they reach the `ErrorHandler` and thus provide a
1716
// lower fidelity error than what `SentryErrorHandler` (see errorhandler.ts) would provide.
@@ -24,16 +23,7 @@ export function init(options: BrowserOptions): void {
2423
...options,
2524
};
2625

27-
opts._metadata.sdk = opts._metadata.sdk || {
28-
name: 'sentry.javascript.angular',
29-
packages: [
30-
{
31-
name: 'npm:@sentry/angular',
32-
version: SDK_VERSION,
33-
},
34-
],
35-
version: SDK_VERSION,
36-
};
26+
applySdkMetadata(opts, 'angular');
3727

3828
checkAndSetAngularVersion();
3929
browserInit(opts);

packages/astro/src/client/sdk.ts

Lines changed: 2 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,10 +1,8 @@
11
import type { BrowserOptions } from '@sentry/browser';
22
import { BrowserTracing, init as initBrowserSdk } from '@sentry/browser';
3-
import { getCurrentScope, hasTracingEnabled } from '@sentry/core';
3+
import { applySdkMetadata, getCurrentScope, hasTracingEnabled } from '@sentry/core';
44
import { addOrUpdateIntegration } from '@sentry/utils';
55

6-
import { applySdkMetadata } from '../common/metadata';
7-
86
// Treeshakable guard to remove all code related to tracing
97
declare const __SENTRY_TRACING__: boolean;
108

@@ -14,8 +12,7 @@ declare const __SENTRY_TRACING__: boolean;
1412
* @param options Configuration options for the SDK.
1513
*/
1614
export function init(options: BrowserOptions): void {
17-
applySdkMetadata(options, ['astro', 'browser']);
18-
15+
applySdkMetadata(options, 'astro', ['astro', 'browser']);
1916
addClientIntegrations(options);
2017

2118
initBrowserSdk(options);

packages/astro/src/server/sdk.ts

Lines changed: 2 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,15 +1,13 @@
1-
import { getCurrentScope } from '@sentry/core';
1+
import { applySdkMetadata, getCurrentScope } from '@sentry/core';
22
import type { NodeOptions } from '@sentry/node';
33
import { init as initNodeSdk } from '@sentry/node';
44

5-
import { applySdkMetadata } from '../common/metadata';
6-
75
/**
86
*
97
* @param options
108
*/
119
export function init(options: NodeOptions): void {
12-
applySdkMetadata(options, ['astro', 'node']);
10+
applySdkMetadata(options, 'astro', ['astro', 'node']);
1311

1412
initNodeSdk(options);
1513

packages/browser/src/client.ts

Lines changed: 3 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,6 @@
11
import type { Scope } from '@sentry/core';
2-
import { BaseClient, SDK_VERSION } from '@sentry/core';
2+
import { applySdkMetadata } from '@sentry/core';
3+
import { BaseClient } from '@sentry/core';
34
import type {
45
BrowserClientProfilingOptions,
56
BrowserClientReplayOptions,
@@ -50,18 +51,7 @@ export class BrowserClient extends BaseClient<BrowserClientOptions> {
5051
*/
5152
public constructor(options: BrowserClientOptions) {
5253
const sdkSource = WINDOW.SENTRY_SDK_SOURCE || getSDKSource();
53-
54-
options._metadata = options._metadata || {};
55-
options._metadata.sdk = options._metadata.sdk || {
56-
name: 'sentry.javascript.browser',
57-
packages: [
58-
{
59-
name: `${sdkSource}:@sentry/browser`,
60-
version: SDK_VERSION,
61-
},
62-
],
63-
version: SDK_VERSION,
64-
};
54+
applySdkMetadata(options, 'browser', ['browser'], sdkSource);
6555

6656
super(options);
6757

packages/bun/src/client.ts

Lines changed: 3 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,7 @@
11
import * as os from 'os';
22
import type { ServerRuntimeClientOptions } from '@sentry/core';
3-
import { SDK_VERSION, ServerRuntimeClient } from '@sentry/core';
3+
import { applySdkMetadata } from '@sentry/core';
4+
import { ServerRuntimeClient } from '@sentry/core';
45

56
import type { BunClientOptions } from './types';
67

@@ -16,17 +17,7 @@ export class BunClient extends ServerRuntimeClient<BunClientOptions> {
1617
* @param options Configuration options for this SDK.
1718
*/
1819
public constructor(options: BunClientOptions) {
19-
options._metadata = options._metadata || {};
20-
options._metadata.sdk = options._metadata.sdk || {
21-
name: 'sentry.javascript.bun',
22-
packages: [
23-
{
24-
name: 'npm:@sentry/bun',
25-
version: SDK_VERSION,
26-
},
27-
],
28-
version: SDK_VERSION,
29-
};
20+
applySdkMetadata(options, 'bun');
3021

3122
const clientOptions: ServerRuntimeClientOptions = {
3223
...options,

packages/core/src/index.ts

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -86,6 +86,7 @@ export {
8686
spanIsSampled,
8787
} from './utils/spanUtils';
8888
export { getRootSpan } from './utils/getRootSpan';
89+
export { applySdkMetadata } from './utils/sdkMetadata';
8990
export { DEFAULT_ENVIRONMENT } from './constants';
9091
/* eslint-disable deprecation/deprecation */
9192
export { ModuleMetadata } from './integrations/metadata';

packages/astro/src/common/metadata.ts renamed to packages/core/src/utils/sdkMetadata.ts

Lines changed: 7 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,5 @@
1-
import { SDK_VERSION } from '@sentry/core';
21
import type { Options, SdkInfo } from '@sentry/types';
3-
4-
const PACKAGE_NAME_PREFIX = 'npm:@sentry/';
2+
import { SDK_VERSION } from '../version';
53

64
/**
75
* A builder for the SDK metadata in the options for the SDK initialization.
@@ -16,14 +14,16 @@ const PACKAGE_NAME_PREFIX = 'npm:@sentry/';
1614
* @param options SDK options object that gets mutated
1715
* @param names list of package names
1816
*/
19-
export function applySdkMetadata(options: Options, names: string[]): void {
17+
export function applySdkMetadata(options: Options, name: string, names?: string[], source = 'npm'): void {
2018
options._metadata = options._metadata || {};
19+
const namesToUse = names || [name];
20+
2121
options._metadata.sdk =
2222
options._metadata.sdk ||
2323
({
24-
name: 'sentry.javascript.astro',
25-
packages: names.map(name => ({
26-
name: `${PACKAGE_NAME_PREFIX}${name}`,
24+
name: `sentry.javascript.${name}`,
25+
packages: namesToUse.map(name => ({
26+
name: `${source}:@sentry/${name}`,
2727
version: SDK_VERSION,
2828
})),
2929
version: SDK_VERSION,

packages/ember/addon/index.ts

Lines changed: 2 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,7 @@ import { getOwnConfig, isDevelopingApp, macroCondition } from '@embroider/macros
55
import { startSpan } from '@sentry/browser';
66
import type { BrowserOptions } from '@sentry/browser';
77
import * as Sentry from '@sentry/browser';
8-
import { SDK_VERSION } from '@sentry/browser';
8+
import { applySdkMetadata } from '@sentry/core';
99
import { GLOBAL_OBJ } from '@sentry/utils';
1010
import Ember from 'ember';
1111

@@ -33,17 +33,7 @@ export function InitSentryForEmber(_runtimeConfig?: BrowserOptions): void {
3333
Object.assign(environmentConfig.sentry, _runtimeConfig || {});
3434
const initConfig = Object.assign({}, environmentConfig.sentry);
3535

36-
initConfig._metadata = initConfig._metadata || {};
37-
initConfig._metadata.sdk = {
38-
name: 'sentry.javascript.ember',
39-
packages: [
40-
{
41-
name: 'npm:@sentry/ember',
42-
version: SDK_VERSION,
43-
},
44-
],
45-
version: SDK_VERSION,
46-
};
36+
applySdkMetadata(initConfig, 'ember');
4737

4838
// Persist Sentry init options so they are identical when performance initializers call init again.
4939
const sentryInitConfig = _getSentryInitConfig();

packages/gatsby/src/sdk.ts

Lines changed: 3 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,5 @@
1-
import { SDK_VERSION, init as reactInit } from '@sentry/react';
1+
import { applySdkMetadata } from '@sentry/core';
2+
import { init as reactInit } from '@sentry/react';
23

34
import { getIntegrationsFromOptions } from './utils/integrations';
45
import type { GatsbyOptions } from './utils/types';
@@ -7,18 +8,7 @@ import type { GatsbyOptions } from './utils/types';
78
* Inits the Sentry Gatsby SDK.
89
*/
910
export function init(options: GatsbyOptions): void {
10-
options._metadata = options._metadata || {};
11-
options._metadata.sdk = options._metadata.sdk || {
12-
name: 'sentry.javascript.gatsby',
13-
packages: [
14-
{
15-
name: 'npm:@sentry/gatsby',
16-
version: SDK_VERSION,
17-
},
18-
],
19-
version: SDK_VERSION,
20-
};
21-
11+
applySdkMetadata(options, 'gatsby');
2212
const integrations = getIntegrationsFromOptions(options);
2313
reactInit({
2414
...options,

packages/nextjs/src/client/index.ts

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
import { hasTracingEnabled } from '@sentry/core';
1+
import { applySdkMetadata, hasTracingEnabled } from '@sentry/core';
22
import { RewriteFrames } from '@sentry/integrations';
33
import type { BrowserOptions } from '@sentry/react';
44
import {
@@ -13,7 +13,6 @@ import { addOrUpdateIntegration } from '@sentry/utils';
1313

1414
import { devErrorSymbolicationEventProcessor } from '../common/devErrorSymbolicationEventProcessor';
1515
import { getVercelEnv } from '../common/getVercelEnv';
16-
import { buildMetadata } from '../common/metadata';
1716
import { nextRouterInstrumentation } from './routing/nextRoutingInstrumentation';
1817
import { applyTunnelRouteOption } from './tunnelRoute';
1918

@@ -50,7 +49,7 @@ export function init(options: BrowserOptions): void {
5049
};
5150

5251
applyTunnelRouteOption(opts);
53-
buildMetadata(opts, ['nextjs', 'react']);
52+
applySdkMetadata(opts, 'nextjs', ['nextjs', 'react']);
5453

5554
addClientIntegrations(opts);
5655

packages/nextjs/src/common/metadata.ts

Lines changed: 0 additions & 23 deletions
This file was deleted.

packages/nextjs/src/edge/index.ts

Lines changed: 2 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,5 @@
1-
import { SDK_VERSION, addTracingExtensions } from '@sentry/core';
1+
import { addTracingExtensions, applySdkMetadata } from '@sentry/core';
22
import { RewriteFrames } from '@sentry/integrations';
3-
import type { SdkMetadata } from '@sentry/types';
43
import { GLOBAL_OBJ, addOrUpdateIntegration, escapeStringForRegex } from '@sentry/utils';
54
import type { VercelEdgeOptions } from '@sentry/vercel-edge';
65
import { init as vercelEdgeInit } from '@sentry/vercel-edge';
@@ -23,20 +22,10 @@ export function init(options: VercelEdgeOptions = {}): void {
2322
}
2423

2524
const opts = {
26-
_metadata: {} as SdkMetadata,
2725
...options,
2826
};
2927

30-
opts._metadata.sdk = opts._metadata.sdk || {
31-
name: 'sentry.javascript.nextjs',
32-
packages: [
33-
{
34-
name: 'npm:@sentry/nextjs',
35-
version: SDK_VERSION,
36-
},
37-
],
38-
version: SDK_VERSION,
39-
};
28+
applySdkMetadata(opts, 'nextjs');
4029

4130
let integrations = opts.integrations || [];
4231

packages/nextjs/src/server/index.ts

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
import * as path from 'path';
2-
import { addTracingExtensions, getClient } from '@sentry/core';
2+
import { addTracingExtensions, applySdkMetadata, getClient } from '@sentry/core';
33
import { RewriteFrames } from '@sentry/integrations';
44
import type { NodeOptions } from '@sentry/node';
55
import { Integrations, getCurrentScope, init as nodeInit } from '@sentry/node';
@@ -10,7 +10,6 @@ import { addOrUpdateIntegration, escapeStringForRegex, logger } from '@sentry/ut
1010
import { DEBUG_BUILD } from '../common/debug-build';
1111
import { devErrorSymbolicationEventProcessor } from '../common/devErrorSymbolicationEventProcessor';
1212
import { getVercelEnv } from '../common/getVercelEnv';
13-
import { buildMetadata } from '../common/metadata';
1413
import { isBuild } from '../common/utils/isBuild';
1514

1615
export { createReduxEnhancer } from '@sentry/react';
@@ -90,7 +89,7 @@ export function init(options: NodeOptions): void {
9089
return;
9190
}
9291

93-
buildMetadata(opts, ['nextjs', 'node']);
92+
applySdkMetadata(opts, 'nextjs', ['nextjs', 'node']);
9493

9594
addServerIntegrations(opts);
9695

packages/node-experimental/src/sdk/client.ts

Lines changed: 2 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,7 @@ import { NodeClient, SDK_VERSION } from '@sentry/node';
33
import type { Tracer } from '@opentelemetry/api';
44
import { trace } from '@opentelemetry/api';
55
import type { BasicTracerProvider } from '@opentelemetry/sdk-trace-base';
6+
import { applySdkMetadata } from '@sentry/core';
67
import type { CaptureContext, Event, EventHint } from '@sentry/types';
78
import { Scope, getIsolationScope } from './scope';
89

@@ -12,17 +13,7 @@ export class NodeExperimentalClient extends NodeClient {
1213
private _tracer: Tracer | undefined;
1314

1415
public constructor(options: ConstructorParameters<typeof NodeClient>[0]) {
15-
options._metadata = options._metadata || {};
16-
options._metadata.sdk = options._metadata.sdk || {
17-
name: 'sentry.javascript.node-experimental',
18-
packages: [
19-
{
20-
name: 'npm:@sentry/node-experimental',
21-
version: SDK_VERSION,
22-
},
23-
],
24-
version: SDK_VERSION,
25-
};
16+
applySdkMetadata(options, 'node-experimental');
2617

2718
super(options);
2819
}

0 commit comments

Comments
 (0)