Skip to content

Commit 7ca3dce

Browse files
committed
use new way of finding transaction on scope
1 parent 48c6f29 commit 7ca3dce

File tree

1 file changed

+12
-2
lines changed

1 file changed

+12
-2
lines changed

packages/hub/src/scope.ts

Lines changed: 12 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -217,10 +217,20 @@ export class Scope implements ScopeInterface {
217217
* @inheritDoc
218218
*/
219219
public getTransaction(): Transaction | undefined {
220-
const span = this.getSpan() as Span & { spanRecorder: { spans: Span[] } };
221-
if (span && span.spanRecorder && span.spanRecorder.spans[0]) {
220+
// often, this span will be a transaction, but it's not guaranteed to be
221+
const span = this.getSpan() as undefined | (Span & { spanRecorder: { spans: Span[] } });
222+
223+
// try it the new way first
224+
if (span?.transaction) {
225+
return span?.transaction;
226+
}
227+
228+
// fallback to the old way (known bug: this only finds transactions with sampled = true)
229+
if (span?.spanRecorder?.spans[0]) {
222230
return span.spanRecorder.spans[0] as Transaction;
223231
}
232+
233+
// neither way found a transaction
224234
return undefined;
225235
}
226236

0 commit comments

Comments
 (0)