Skip to content

Commit cb6912a

Browse files
authored
ref(core): Make on and emit required on client (#10603)
This allows us to remove a bunch of code around fallbacks etc. Esp. in replay this also allows us to remove a bunch of code around breadcrumbs etc. note @JonasBa I did not remove this in profiling-node yet because the test rely on this quite a bunch, can you take a look at this when you've got some time?
1 parent d2ef1cb commit cb6912a

File tree

34 files changed

+75
-397
lines changed

34 files changed

+75
-397
lines changed

packages/angular/src/errorhandler.ts

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -118,7 +118,7 @@ class SentryErrorHandler implements AngularErrorHandler {
118118
if (this._options.showDialog) {
119119
const client = Sentry.getClient();
120120

121-
if (client && client.on && !this._registeredAfterSendEventHandler) {
121+
if (client && !this._registeredAfterSendEventHandler) {
122122
client.on('afterSendEvent', (event: Event) => {
123123
if (!event.type) {
124124
// eslint-disable-next-line deprecation/deprecation
@@ -128,7 +128,7 @@ class SentryErrorHandler implements AngularErrorHandler {
128128

129129
// We only want to register this hook once in the lifetime of the error handler
130130
this._registeredAfterSendEventHandler = true;
131-
} else if (!client || !client.on) {
131+
} else if (!client) {
132132
Sentry.showReportDialog({ ...this._options.dialogOptions, eventId });
133133
}
134134
}

packages/browser/src/integrations/breadcrumbs.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -88,7 +88,7 @@ const _breadcrumbsIntegration = ((options: Partial<BreadcrumbsOptions> = {}) =>
8888
if (_options.history) {
8989
addHistoryInstrumentationHandler(_getHistoryBreadcrumbHandler(client));
9090
}
91-
if (_options.sentry && client.on) {
91+
if (_options.sentry) {
9292
client.on('beforeSendEvent', _getSentryBreadcrumbHandler(client));
9393
}
9494
},

packages/browser/src/profiling/integration.ts

Lines changed: 0 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -35,11 +35,6 @@ const _browserProfilingIntegration = (() => {
3535
}
3636
}
3737

38-
if (typeof client.on !== 'function') {
39-
logger.warn('[Profiling] Client does not support hooks, profiling will be disabled');
40-
return;
41-
}
42-
4338
client.on('startTransaction', (transaction: Transaction) => {
4439
if (shouldProfileTransaction(transaction)) {
4540
startProfileForTransaction(transaction);

packages/core/src/hub.ts

Lines changed: 1 addition & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -419,9 +419,7 @@ export class Hub implements HubInterface {
419419

420420
if (finalBreadcrumb === null) return;
421421

422-
if (client.emit) {
423-
client.emit('beforeAddBreadcrumb', finalBreadcrumb, hint);
424-
}
422+
client.emit('beforeAddBreadcrumb', finalBreadcrumb, hint);
425423

426424
// TODO(v8): I know this comment doesn't make much sense because the hub will be deprecated but I still wanted to
427425
// write it down. In theory, we would have to add the breadcrumbs to the isolation scope here, however, that would

packages/core/src/integration.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -140,7 +140,7 @@ export function setupIntegration(client: Client, integration: Integration, integ
140140
integration.setup(client);
141141
}
142142

143-
if (client.on && typeof integration.preprocessEvent === 'function') {
143+
if (typeof integration.preprocessEvent === 'function') {
144144
const callback = integration.preprocessEvent.bind(integration) as typeof integration.preprocessEvent;
145145
client.on('preprocessEvent', (event, hint) => callback(event, hint, client));
146146
}

packages/core/src/integrations/metadata.ts

Lines changed: 0 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -12,10 +12,6 @@ const _moduleMetadataIntegration = (() => {
1212
// TODO v8: Remove this
1313
setupOnce() {}, // eslint-disable-line @typescript-eslint/no-empty-function
1414
setup(client) {
15-
if (typeof client.on !== 'function') {
16-
return;
17-
}
18-
1915
// We need to strip metadata from stack frames before sending them to Sentry since these are client side only.
2016
client.on('beforeEnvelope', envelope => {
2117
forEachEnvelopeItem(envelope, (item, type) => {

packages/core/src/tracing/dynamicSamplingContext.ts

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -23,7 +23,7 @@ export function getDynamicSamplingContextFromClient(trace_id: string, client: Cl
2323
trace_id,
2424
}) as DynamicSamplingContext;
2525

26-
client.emit && client.emit('createDsc', dsc);
26+
client.emit('createDsc', dsc);
2727

2828
return dsc;
2929
}
@@ -81,7 +81,7 @@ export function getDynamicSamplingContextFromSpan(span: Span): Readonly<Partial<
8181

8282
dsc.sampled = String(spanIsSampled(txn));
8383

84-
client.emit && client.emit('createDsc', dsc);
84+
client.emit('createDsc', dsc);
8585

8686
return dsc;
8787
}

packages/core/src/tracing/hubextensions.ts

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -78,7 +78,7 @@ The transaction will not be sampled. Please use the ${configInstrumenter} instru
7878
if (transaction.isRecording()) {
7979
transaction.initSpanRecorder(options._experiments && (options._experiments.maxSpans as number));
8080
}
81-
if (client && client.emit) {
81+
if (client) {
8282
client.emit('startTransaction', transaction);
8383
}
8484
return transaction;
@@ -125,7 +125,7 @@ export function startIdleTransaction(
125125
if (transaction.isRecording()) {
126126
transaction.initSpanRecorder(options._experiments && (options._experiments.maxSpans as number));
127127
}
128-
if (client && client.emit) {
128+
if (client) {
129129
client.emit('startTransaction', transaction);
130130
}
131131
return transaction;

packages/core/src/tracing/transaction.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -276,7 +276,7 @@ export class Transaction extends SpanClass implements TransactionInterface {
276276

277277
// eslint-disable-next-line deprecation/deprecation
278278
const client = this._hub.getClient();
279-
if (client && client.emit) {
279+
if (client) {
280280
client.emit('finishTransaction', this);
281281
}
282282

packages/core/test/lib/base.test.ts

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1957,11 +1957,11 @@ describe('BaseClient', () => {
19571957
traceId: '86f39e84263a4de99c326acab3bfe3bd',
19581958
} as Transaction;
19591959

1960-
client.on?.('startTransaction', transaction => {
1960+
client.on('startTransaction', transaction => {
19611961
expect(transaction).toEqual(mockTransaction);
19621962
});
19631963

1964-
client.emit?.('startTransaction', mockTransaction);
1964+
client.emit('startTransaction', mockTransaction);
19651965
});
19661966

19671967
it('should call a beforeEnvelope hook', () => {
@@ -1974,11 +1974,11 @@ describe('BaseClient', () => {
19741974
{},
19751975
] as Envelope;
19761976

1977-
client.on?.('beforeEnvelope', envelope => {
1977+
client.on('beforeEnvelope', envelope => {
19781978
expect(envelope).toEqual(mockEnvelope);
19791979
});
19801980

1981-
client.emit?.('beforeEnvelope', mockEnvelope);
1981+
client.emit('beforeEnvelope', mockEnvelope);
19821982
});
19831983
});
19841984
});

0 commit comments

Comments
 (0)