Skip to content

Commit 39312e8

Browse files
committed
ref: Slight refactor of startSpan
1 parent 171e2a1 commit 39312e8

File tree

1 file changed

+4
-7
lines changed

1 file changed

+4
-7
lines changed

packages/apm/src/hubextensions.ts

Lines changed: 4 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -28,12 +28,7 @@ function traceHeaders(): { [key: string]: string } {
2828
*
2929
* @param context Properties with which the span should be created
3030
*/
31-
function startSpan(context: SpanContext | TransactionContext): Transaction | Span {
32-
// @ts-ignore
33-
const hub = this as Hub;
34-
const scope = hub.getScope();
35-
const client = hub.getClient();
36-
31+
function startSpan(this: Hub, context: SpanContext | TransactionContext): Transaction | Span {
3732
// This is our safeguard so people always get a Transaction in return.
3833
// We set `_isTransaction: true` in {@link Sentry.startTransaction} to have a runtime check
3934
// if the user really wanted to create a Transaction.
@@ -45,8 +40,9 @@ function startSpan(context: SpanContext | TransactionContext): Transaction | Spa
4540

4641
if ((context as TransactionContext).name) {
4742
// We are dealing with a Transaction
48-
const transaction = new Transaction(context as TransactionContext, hub);
43+
const transaction = new Transaction(context as TransactionContext, this);
4944

45+
const client = this.getClient();
5046
// We only roll the dice on sampling for root spans of transactions because all child spans inherit this state
5147
if (transaction.sampled === undefined) {
5248
const sampleRate = (client && client.getOptions().tracesSampleRate) || 0;
@@ -66,6 +62,7 @@ function startSpan(context: SpanContext | TransactionContext): Transaction | Spa
6662
return transaction;
6763
}
6864

65+
const scope = this.getScope();
6966
if (scope) {
7067
// If there is a Span on the Scope we start a child and return that instead
7168
const parentSpan = scope.getSpan();

0 commit comments

Comments
 (0)