Skip to content

Commit 045fd88

Browse files
committed
ref: CodeReview
1 parent c327c03 commit 045fd88

File tree

3 files changed

+9
-13
lines changed

3 files changed

+9
-13
lines changed

packages/apm/test/hub.test.ts

+3-7
Original file line numberDiff line numberDiff line change
@@ -11,27 +11,23 @@ describe('Hub', () => {
1111
jest.useRealTimers();
1212
});
1313

14-
describe('getSpan', () => {
14+
describe('getTransaction', () => {
1515
test('simple invoke', () => {
1616
const hub = new Hub(new BrowserClient({ tracesSampleRate: 1 }));
1717
const transaction = hub.startTransaction({ name: 'foo' });
1818
hub.configureScope(scope => {
1919
scope.setSpan(transaction);
2020
});
2121
hub.configureScope(s => {
22-
s.getTransaction(t => {
23-
expect(t).toBe(transaction);
24-
});
22+
expect(s.getTransaction()).toBe(transaction);
2523
});
2624
});
2725

2826
test('not invoke', () => {
2927
const hub = new Hub(new BrowserClient({ tracesSampleRate: 1 }));
3028
const transaction = hub.startTransaction({ name: 'foo' });
3129
hub.configureScope(s => {
32-
s.getTransaction(_ => {
33-
expect(true).toBe(false);
34-
});
30+
expect(s.getTransaction()).toBeUndefined();
3531
});
3632
transaction.finish();
3733
});

packages/hub/src/scope.ts

+3-2
Original file line numberDiff line numberDiff line change
@@ -229,13 +229,14 @@ export class Scope implements ScopeInterface {
229229
/**
230230
* @inheritDoc
231231
*/
232-
public getTransaction(callback: (transaction: Transaction) => void): void {
232+
public getTransaction(): Transaction | undefined {
233233
const span = this.getSpan() as Span & { spanRecorder: { spans: Span[] } };
234234
if (span) {
235235
if (span.spanRecorder && span.spanRecorder.spans[0]) {
236-
callback(span.spanRecorder.spans[0] as Transaction);
236+
return span.spanRecorder.spans[0] as Transaction;
237237
}
238238
}
239+
return undefined;
239240
}
240241

241242
/**

packages/types/src/scope.ts

+3-4
Original file line numberDiff line numberDiff line change
@@ -90,15 +90,14 @@ export interface Scope {
9090
setSpan(span?: Span): this;
9191

9292
/**
93-
* Returns the current set span if there is one
93+
* Returns the `Span` if there is one
9494
*/
9595
getSpan(): Span | undefined;
9696

9797
/**
98-
* Callback to retrieve an ongoing Transaction in case there is one.
99-
* @param callback Will only be invoked in case there is an active transaction
98+
* Returns the `Transaction` if there is one
10099
*/
101-
getTransaction(callback: (transaction: Transaction) => void): void;
100+
getTransaction(): Transaction | undefined;
102101

103102
/**
104103
* Updates the scope with provided data. Can work in three variations:

0 commit comments

Comments
 (0)