Skip to content

Commit 8168f83

Browse files
committed
always return the active transaction, even if sampled = false
1 parent 4240557 commit 8168f83

File tree

2 files changed

+16
-6
lines changed

2 files changed

+16
-6
lines changed

packages/hub/src/scope.ts

Lines changed: 1 addition & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -217,11 +217,7 @@ 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]) {
222-
return span.spanRecorder.spans[0] as Transaction;
223-
}
224-
return undefined;
220+
return this.getSpan() as Transaction;
225221
}
226222

227223
/**

packages/tracing/test/hub.test.ts

Lines changed: 15 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -23,9 +23,23 @@ describe('Hub', () => {
2323
});
2424

2525
describe('getTransaction()', () => {
26-
it('should find a transaction which has been set on the scope', () => {
26+
it('should find a transaction which has been set on the scope if sampled = true', () => {
2727
const hub = new Hub(new BrowserClient({ tracesSampleRate: 1 }));
2828
const transaction = hub.startTransaction({ name: 'dogpark' });
29+
transaction.sampled = true;
30+
31+
hub.configureScope(scope => {
32+
scope.setSpan(transaction);
33+
});
34+
35+
expect(hub.getScope()?.getTransaction()).toBe(transaction);
36+
});
37+
38+
it('should find a transaction which has been set on the scope if sampled = false', () => {
39+
const hub = new Hub(new BrowserClient({ tracesSampleRate: 1 }));
40+
const transaction = hub.startTransaction({ name: 'dogpark' });
41+
transaction.sampled = false;
42+
2943
hub.configureScope(scope => {
3044
scope.setSpan(transaction);
3145
});

0 commit comments

Comments
 (0)