File tree Expand file tree Collapse file tree 1 file changed +12
-2
lines changed Expand file tree Collapse file tree 1 file changed +12
-2
lines changed Original file line number Diff line number Diff 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
You can’t perform that action at this time.
0 commit comments