Skip to content

Commit

Permalink
feat(core): Emit hooks for transaction start/finish (#7387)
Browse files Browse the repository at this point in the history
  • Loading branch information
AbhiPrasad authored Mar 9, 2023
1 parent c192c9a commit 295ea3d
Show file tree
Hide file tree
Showing 2 changed files with 11 additions and 1 deletion.
6 changes: 6 additions & 0 deletions packages/core/src/tracing/hubextensions.ts
Original file line number Diff line number Diff line change
Expand Up @@ -186,6 +186,9 @@ The transaction will not be sampled. Please use the ${configInstrumenter} instru
if (transaction.sampled) {
transaction.initSpanRecorder(options._experiments && (options._experiments.maxSpans as number));
}
if (client && client.emit) {
client.emit('startTransaction', transaction);
}
return transaction;
}

Expand Down Expand Up @@ -213,6 +216,9 @@ export function startIdleTransaction(
if (transaction.sampled) {
transaction.initSpanRecorder(options._experiments && (options._experiments.maxSpans as number));
}
if (client && client.emit) {
client.emit('startTransaction', transaction);
}
return transaction;
}

Expand Down
6 changes: 5 additions & 1 deletion packages/core/src/tracing/transaction.ts
Original file line number Diff line number Diff line change
Expand Up @@ -141,11 +141,15 @@ export class Transaction extends SpanClass implements TransactionInterface {
// just sets the end timestamp
super.finish(endTimestamp);

const client = this._hub.getClient();
if (client && client.emit) {
client.emit('finishTransaction', this);
}

if (this.sampled !== true) {
// At this point if `sampled !== true` we want to discard the transaction.
__DEBUG_BUILD__ && logger.log('[Tracing] Discarding transaction because its trace was not chosen to be sampled.');

const client = this._hub.getClient();
if (client) {
client.recordDroppedEvent('sample_rate', 'transaction');
}
Expand Down

0 comments on commit 295ea3d

Please sign in to comment.