Skip to content

Commit 2fd8389

Browse files
committed
split hook signatures
1 parent 225b8a3 commit 2fd8389

File tree

2 files changed

+57
-18
lines changed

2 files changed

+57
-18
lines changed

packages/core/src/baseclient.ts

Lines changed: 19 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -376,15 +376,22 @@ export abstract class BaseClient<O extends ClientOptions> implements Client<O> {
376376
}
377377

378378
// Keep on() & emit() signatures in sync with types' client.ts interface
379+
/* eslint-disable @typescript-eslint/unified-signatures */
379380

380381
/** @inheritdoc */
381-
public on(hook: 'startTransaction' | 'finishTransaction', callback: (transaction: Transaction) => void): void;
382+
public on(hook: 'startTransaction', callback: (transaction: Transaction) => void): void;
383+
384+
/** @inheritdoc */
385+
public on(hook: 'finishTransaction', callback: (transaction: Transaction) => void): void;
382386

383387
/** @inheritdoc */
384388
public on(hook: 'beforeEnvelope', callback: (envelope: Envelope) => void): void;
385389

386390
/** @inheritdoc */
387-
public on(hook: 'beforeSendEvent' | 'preprocessEvent', callback: (event: Event, hint?: EventHint) => void): void;
391+
public on(hook: 'beforeSendEvent', callback: (event: Event, hint?: EventHint) => void): void;
392+
393+
/** @inheritdoc */
394+
public on(hook: 'preprocessEvent', callback: (event: Event, hint?: EventHint) => void): void;
388395

389396
/** @inheritdoc */
390397
public on(
@@ -412,13 +419,19 @@ export abstract class BaseClient<O extends ClientOptions> implements Client<O> {
412419
}
413420

414421
/** @inheritdoc */
415-
public emit(hook: 'startTransaction' | 'finishTransaction', transaction: Transaction): void;
422+
public emit(hook: 'startTransaction', transaction: Transaction): void;
423+
424+
/** @inheritdoc */
425+
public emit(hook: 'finishTransaction', transaction: Transaction): void;
416426

417427
/** @inheritdoc */
418428
public emit(hook: 'beforeEnvelope', envelope: Envelope): void;
419429

420430
/** @inheritdoc */
421-
public emit(hook: 'beforeSendEvent' | 'preprocessEvent', event: Event, hint?: EventHint): void;
431+
public emit(hook: 'beforeSendEvent', event: Event, hint?: EventHint): void;
432+
433+
/** @inheritdoc */
434+
public emit(hook: 'preprocessEvent', event: Event, hint?: EventHint): void;
422435

423436
/** @inheritdoc */
424437
public emit(hook: 'afterSendEvent', event: Event, sendResponse: TransportMakeRequestResponse | void): void;
@@ -439,6 +452,8 @@ export abstract class BaseClient<O extends ClientOptions> implements Client<O> {
439452
}
440453
}
441454

455+
/* eslint-enable @typescript-eslint/unified-signatures */
456+
442457
/** Updates existing session based on the provided event */
443458
protected _updateSessionFromEvent(session: Session, event: Event): void {
444459
let crashed = false;

packages/types/src/client.ts

Lines changed: 38 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -165,11 +165,19 @@ export interface Client<O extends ClientOptions = ClientOptions> {
165165

166166
// HOOKS
167167
// TODO(v8): Make the hooks non-optional.
168+
/* eslint-disable @typescript-eslint/unified-signatures */
168169

169170
/**
170-
* Register a callback for transaction start and finish.
171+
* Register a callback for transaction start.
172+
* Receives the transaction as argument.
171173
*/
172-
on?(hook: 'startTransaction' | 'finishTransaction', callback: (transaction: Transaction) => void): void;
174+
on?(hook: 'startTransaction', callback: (transaction: Transaction) => void): void;
175+
176+
/**
177+
* Register a callback for transaction finish.
178+
* Receives the transaction as argument.
179+
*/
180+
on?(hook: 'finishTransaction', callback: (transaction: Transaction) => void): void;
173181

174182
/**
175183
* Register a callback for transaction start and finish.
@@ -178,14 +186,17 @@ export interface Client<O extends ClientOptions = ClientOptions> {
178186

179187
/**
180188
* Register a callback for before sending an event.
181-
* `beforeSendEvent` is called right before an event is sent and should not be used to mutate the event.
182-
* `preprocessEvent` is called before all global event processors.
189+
* This is called right before an event is sent and should not be used to mutate the event.
183190
* Receives an Event & EventHint as arguments.
184191
*/
185-
on?(
186-
hook: 'beforeSendEvent' | 'preprocessEvent',
187-
callback: (event: Event, hint?: EventHint | undefined) => void,
188-
): void;
192+
on?(hook: 'beforeSendEvent', callback: (event: Event, hint?: EventHint | undefined) => void): void;
193+
194+
/**
195+
* Register a callback for preprocessing an event,
196+
* before it is passed to (global) event processors.
197+
* Receives an Event & EventHint as arguments.
198+
*/
199+
on?(hook: 'preprocessEvent', callback: (event: Event, hint?: EventHint | undefined) => void): void;
189200

190201
/**
191202
* Register a callback for when an event has been sent.
@@ -212,10 +223,16 @@ export interface Client<O extends ClientOptions = ClientOptions> {
212223
on?(hook: 'otelSpanEnd', callback: (otelSpan: unknown, mutableOptions: { drop: boolean }) => void): void;
213224

214225
/**
215-
* Fire a hook event for transaction start and finish. Expects to be given a transaction as the
216-
* second argument.
226+
* Fire a hook event for transaction start.
227+
* Expects to be given a transaction as the second argument.
217228
*/
218-
emit?(hook: 'startTransaction' | 'finishTransaction', transaction: Transaction): void;
229+
emit?(hook: 'startTransaction', transaction: Transaction): void;
230+
231+
/**
232+
* Fire a hook event for transaction finish.
233+
* Expects to be given a transaction as the second argument.
234+
*/
235+
emit?(hook: 'finishTransaction', transaction: Transaction): void;
219236

220237
/*
221238
* Fire a hook event for envelope creation and sending. Expects to be given an envelope as the
@@ -225,11 +242,16 @@ export interface Client<O extends ClientOptions = ClientOptions> {
225242

226243
/**
227244
* Fire a hook event before sending an event.
228-
* `beforeSendEvent` is called right before an event is sent and should not be used to mutate the event.
229-
* `preprocessEvent` is called before all global event processors.
245+
* This is called right before an event is sent and should not be used to mutate the event.
230246
* Expects to be given an Event & EventHint as the second/third argument.
231247
*/
232-
emit?(hook: 'beforeSendEvent' | 'preprocessEvent', event: Event, hint?: EventHint): void;
248+
emit?(hook: 'beforeSendEvent', event: Event, hint?: EventHint): void;
249+
250+
/**
251+
* Fire a hook event to process events before they are passed to (global) event processors.
252+
* Expects to be given an Event & EventHint as the second/third argument.
253+
*/
254+
emit?(hook: 'preprocessEvent', event: Event, hint?: EventHint): void;
233255

234256
/*
235257
* Fire a hook event after sending an event. Expects to be given an Event as the
@@ -253,4 +275,6 @@ export interface Client<O extends ClientOptions = ClientOptions> {
253275
* The option argument may be mutated to drop the span.
254276
*/
255277
emit?(hook: 'otelSpanEnd', otelSpan: unknown, mutableOptions: { drop: boolean }): void;
278+
279+
/* eslint-enable @typescript-eslint/unified-signatures */
256280
}

0 commit comments

Comments
 (0)