Skip to content

Commit 8116695

Browse files
committed
feat(core): Emit hooks for transaction start/finish
1 parent f68eb4e commit 8116695

File tree

2 files changed

+11
-1
lines changed

2 files changed

+11
-1
lines changed

packages/core/src/tracing/hubextensions.ts

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -186,6 +186,9 @@ The transaction will not be sampled. Please use the ${configInstrumenter} instru
186186
if (transaction.sampled) {
187187
transaction.initSpanRecorder(options._experiments && (options._experiments.maxSpans as number));
188188
}
189+
if (client) {
190+
client.emit('startTransaction', transaction);
191+
}
189192
return transaction;
190193
}
191194

@@ -213,6 +216,9 @@ export function startIdleTransaction(
213216
if (transaction.sampled) {
214217
transaction.initSpanRecorder(options._experiments && (options._experiments.maxSpans as number));
215218
}
219+
if (client && client.emit) {
220+
client.emit('startTransaction', transaction);
221+
}
216222
return transaction;
217223
}
218224

packages/core/src/tracing/transaction.ts

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -141,11 +141,15 @@ export class Transaction extends SpanClass implements TransactionInterface {
141141
// just sets the end timestamp
142142
super.finish(endTimestamp);
143143

144+
const client = this._hub.getClient();
145+
if (client && client.emit) {
146+
client.emit('finishTransaction', this);
147+
}
148+
144149
if (this.sampled !== true) {
145150
// At this point if `sampled !== true` we want to discard the transaction.
146151
__DEBUG_BUILD__ && logger.log('[Tracing] Discarding transaction because its trace was not chosen to be sampled.');
147152

148-
const client = this._hub.getClient();
149153
if (client) {
150154
client.recordDroppedEvent('sample_rate', 'transaction');
151155
}

0 commit comments

Comments
 (0)