Skip to content

Commit aa5a03b

Browse files
committed
make getTransaction return transaction on scope regardlesss of sampling decision
1 parent 573c49f commit aa5a03b

File tree

2 files changed

+11
-5
lines changed

2 files changed

+11
-5
lines changed

packages/hub/src/scope.ts

Lines changed: 1 addition & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -212,11 +212,7 @@ export class Scope implements ScopeInterface {
212212
* @inheritDoc
213213
*/
214214
public getTransaction(): Transaction | undefined {
215-
const span = this.getSpan() as Span & { spanRecorder: { spans: Span[] } };
216-
if (span && span.spanRecorder && span.spanRecorder.spans[0]) {
217-
return span.spanRecorder.spans[0] as Transaction;
218-
}
219-
return undefined;
215+
return this.getSpan() as Transaction;
220216
}
221217

222218
/**

packages/tracing/test/hub.test.ts

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -32,6 +32,16 @@ describe('Hub', () => {
3232
expect(hub.getScope()?.getTransaction()).toBe(transaction);
3333
});
3434

35+
it('should find an unsampled transaction which has been set on the scope', () => {
36+
const hub = new Hub(new BrowserClient({ tracesSampleRate: 1 }));
37+
const transaction = hub.startTransaction({ name: 'dogpark', sampled: false });
38+
hub.configureScope(scope => {
39+
scope.setSpan(transaction);
40+
});
41+
42+
expect(hub.getScope()?.getTransaction()).toBe(transaction);
43+
});
44+
3545
it("should not find an open transaction if it's not on the scope", () => {
3646
const hub = new Hub(new BrowserClient({ tracesSampleRate: 1 }));
3747
hub.startTransaction({ name: 'dogpark' });

0 commit comments

Comments
 (0)