Skip to content

Commit ebd3680

Browse files
committed
ref: Code Review
1 parent e0273ad commit ebd3680

File tree

3 files changed

+37
-26
lines changed

3 files changed

+37
-26
lines changed

packages/apm/test/hub.test.ts

-22
Original file line numberDiff line numberDiff line change
@@ -11,28 +11,6 @@ describe('Hub', () => {
1111
jest.useRealTimers();
1212
});
1313

14-
describe('getTransaction', () => {
15-
test('simple invoke', () => {
16-
const hub = new Hub(new BrowserClient({ tracesSampleRate: 1 }));
17-
const transaction = hub.startTransaction({ name: 'foo' });
18-
hub.configureScope(scope => {
19-
scope.setSpan(transaction);
20-
});
21-
hub.configureScope(s => {
22-
expect(s.getTransaction()).toBe(transaction);
23-
});
24-
});
25-
26-
test('not invoke', () => {
27-
const hub = new Hub(new BrowserClient({ tracesSampleRate: 1 }));
28-
const transaction = hub.startTransaction({ name: 'foo' });
29-
hub.configureScope(s => {
30-
expect(s.getTransaction()).toBeUndefined();
31-
});
32-
transaction.finish();
33-
});
34-
});
35-
3614
describe('spans', () => {
3715
describe('sampling', () => {
3816
test('set tracesSampleRate 0 on span', () => {

packages/apm/test/scope.test.ts

+35
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,35 @@
1+
import { BrowserClient } from '@sentry/browser';
2+
import { Hub } from '@sentry/hub';
3+
4+
import { addExtensionMethods } from '../src/hubextensions';
5+
6+
addExtensionMethods();
7+
8+
describe('Scope', () => {
9+
afterEach(() => {
10+
jest.resetAllMocks();
11+
jest.useRealTimers();
12+
});
13+
14+
describe('getTransaction', () => {
15+
test('simple invoke', () => {
16+
const hub = new Hub(new BrowserClient({ tracesSampleRate: 1 }));
17+
const transaction = hub.startTransaction({ name: 'foo' });
18+
hub.configureScope(scope => {
19+
scope.setSpan(transaction);
20+
});
21+
hub.configureScope(s => {
22+
expect(s.getTransaction()).toBe(transaction);
23+
});
24+
});
25+
26+
test('not invoke', () => {
27+
const hub = new Hub(new BrowserClient({ tracesSampleRate: 1 }));
28+
const transaction = hub.startTransaction({ name: 'foo' });
29+
hub.configureScope(s => {
30+
expect(s.getTransaction()).toBeUndefined();
31+
});
32+
transaction.finish();
33+
});
34+
});
35+
});

packages/hub/src/scope.ts

+2-4
Original file line numberDiff line numberDiff line change
@@ -230,10 +230,8 @@ export class Scope implements ScopeInterface {
230230
*/
231231
public getTransaction(): Transaction | undefined {
232232
const span = this.getSpan() as Span & { spanRecorder: { spans: Span[] } };
233-
if (span) {
234-
if (span.spanRecorder && span.spanRecorder.spans[0]) {
235-
return span.spanRecorder.spans[0] as Transaction;
236-
}
233+
if (span && span.spanRecorder && span.spanRecorder.spans[0]) {
234+
return span.spanRecorder.spans[0] as Transaction;
237235
}
238236
return undefined;
239237
}

0 commit comments

Comments
 (0)