Skip to content

Commit 06d6bd8

Browse files
authored
feat: Allow for attaching metadata and pass it to the API and transports (#3177)
* feat: Allow for attaching metadata and pass it to the API and transports
1 parent 7095822 commit 06d6bd8

40 files changed

+368
-375
lines changed

packages/angular/src/errorhandler.ts

Lines changed: 0 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -29,25 +29,6 @@ class SentryErrorHandler implements AngularErrorHandler {
2929
logErrors: true,
3030
...options,
3131
};
32-
33-
Sentry.configureScope(scope => {
34-
scope.addEventProcessor(event => {
35-
event.sdk = {
36-
...event.sdk,
37-
name: 'sentry.javascript.angular',
38-
packages: [
39-
...((event.sdk && event.sdk.packages) || []),
40-
{
41-
name: 'npm:@sentry/angular',
42-
version: Sentry.SDK_VERSION,
43-
},
44-
],
45-
version: Sentry.SDK_VERSION,
46-
};
47-
48-
return event;
49-
});
50-
});
5132
}
5233

5334
/**

packages/angular/src/index.ts

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,6 @@
11
export * from '@sentry/browser';
2+
3+
export { init } from './sdk';
24
export { createErrorHandler, ErrorHandlerOptions } from './errorhandler';
35
export {
46
getActiveTransaction,

packages/angular/src/sdk.ts

Lines changed: 19 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,19 @@
1+
import { BrowserOptions, init as browserInit, SDK_VERSION } from '@sentry/browser';
2+
3+
/**
4+
* Inits the Angular SDK
5+
*/
6+
export function init(options: BrowserOptions): void {
7+
options._metadata = options._metadata || {};
8+
options._metadata.sdk = {
9+
name: 'sentry.javascript.angular',
10+
packages: [
11+
{
12+
name: 'npm:@sentry/angular',
13+
version: SDK_VERSION,
14+
},
15+
],
16+
version: SDK_VERSION,
17+
};
18+
browserInit(options);
19+
}

packages/browser/package.json

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -81,7 +81,6 @@
8181
"size:check": "run-p size:check:es5 size:check:es6",
8282
"size:check:es5": "cat build/bundle.min.js | gzip -9 | wc -c | awk '{$1=$1/1024; print \"ES5: \",$1,\"kB\";}'",
8383
"size:check:es6": "cat build/bundle.es6.min.js | gzip -9 | wc -c | awk '{$1=$1/1024; print \"ES6: \",$1,\"kB\";}'",
84-
"version": "node ../../scripts/versionbump.js src/version.ts",
8584
"pack": "npm pack"
8685
},
8786
"volta": {

packages/browser/src/backend.ts

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -67,6 +67,7 @@ export class BrowserBackend extends BaseBackend<BrowserOptions> {
6767
const transportOptions = {
6868
...this._options.transportOptions,
6969
dsn: this._options.dsn,
70+
_metadata: this._options._metadata,
7071
};
7172

7273
if (this._options.transport) {

packages/browser/src/client.ts

Lines changed: 0 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,6 @@ import { getGlobalObject, logger } from '@sentry/utils';
55
import { BrowserBackend, BrowserOptions } from './backend';
66
import { injectReportDialog, ReportDialogOptions } from './helpers';
77
import { Breadcrumbs } from './integrations';
8-
import { SDK_NAME, SDK_VERSION } from './version';
98

109
/**
1110
* The Sentry Browser SDK Client.
@@ -51,19 +50,6 @@ export class BrowserClient extends BaseClient<BrowserBackend, BrowserOptions> {
5150
*/
5251
protected _prepareEvent(event: Event, scope?: Scope, hint?: EventHint): PromiseLike<Event | null> {
5352
event.platform = event.platform || 'javascript';
54-
event.sdk = {
55-
...event.sdk,
56-
name: SDK_NAME,
57-
packages: [
58-
...((event.sdk && event.sdk.packages) || []),
59-
{
60-
name: 'npm:@sentry/browser',
61-
version: SDK_VERSION,
62-
},
63-
],
64-
version: SDK_VERSION,
65-
};
66-
6753
return super._prepareEvent(event, scope, hint);
6854
}
6955

packages/browser/src/exports.ts

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -28,6 +28,7 @@ export {
2828
makeMain,
2929
Scope,
3030
startTransaction,
31+
SDK_VERSION,
3132
setContext,
3233
setExtra,
3334
setExtras,
@@ -42,4 +43,4 @@ export { BrowserClient } from './client';
4243
export { injectReportDialog, ReportDialogOptions } from './helpers';
4344
export { eventFromException, eventFromMessage } from './eventbuilder';
4445
export { defaultIntegrations, forceLoad, init, lastEventId, onLoad, showReportDialog, flush, close, wrap } from './sdk';
45-
export { SDK_NAME, SDK_VERSION } from './version';
46+
export { SDK_NAME } from './version';

packages/browser/src/sdk.ts

Lines changed: 13 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
import { getCurrentHub, initAndBind, Integrations as CoreIntegrations } from '@sentry/core';
1+
import { getCurrentHub, initAndBind, Integrations as CoreIntegrations, SDK_VERSION } from '@sentry/core';
22
import { getGlobalObject, SyncPromise } from '@sentry/utils';
33

44
import { BrowserOptions } from './backend';
@@ -88,6 +88,18 @@ export function init(options: BrowserOptions = {}): void {
8888
options.autoSessionTracking = false;
8989
}
9090

91+
options._metadata = options._metadata || {};
92+
options._metadata.sdk = {
93+
name: 'sentry.javascript.browser',
94+
packages: [
95+
{
96+
name: 'npm:@sentry/browser',
97+
version: SDK_VERSION,
98+
},
99+
],
100+
version: SDK_VERSION,
101+
};
102+
91103
initAndBind(BrowserClient, options);
92104

93105
if (options.autoSessionTracking) {

packages/browser/src/transports/base.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -26,7 +26,7 @@ export abstract class BaseTransport implements Transport {
2626
protected readonly _rateLimits: Record<string, Date> = {};
2727

2828
public constructor(public options: TransportOptions) {
29-
this._api = new API(this.options.dsn);
29+
this._api = new API(options.dsn, options._metadata);
3030
// eslint-disable-next-line deprecation/deprecation
3131
this.url = this._api.getStoreEndpointWithUrlEncodedAuth();
3232
}

packages/browser/src/version.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,2 +1,2 @@
1+
// TODO: Remove in the next major release and rely only on @sentry/core SDK_VERSION and SdkInfo metadata
12
export const SDK_NAME = 'sentry.javascript.browser';
2-
export const SDK_VERSION = '5.30.0';

0 commit comments

Comments
 (0)