Skip to content

Commit 9c7b75c

Browse files
Lms24AbhiPrasad
authored andcommitted
fix(tracing): Remove isInstanceOf check in Hub constructor (#5046)
fix a bug which assigned the wrong Hub instance to a Transaction in the Transaction constructor. Remove the isInstanceOf check which incorrectly failed when passing a user-created Hub the constructor. Overall, simplify the hub initialization by deciding in the constructor if the passed Hub should be used. As a fallback, the Hub returned from getCurrentHub is used. Co-authored by: @lobsterkatie
1 parent aef107e commit 9c7b75c

File tree

1 file changed

+3
-5
lines changed

1 file changed

+3
-5
lines changed

packages/tracing/src/transaction.ts

Lines changed: 3 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,7 @@ import {
66
TransactionContext,
77
TransactionMetadata,
88
} from '@sentry/types';
9-
import { dropUndefinedKeys, isInstanceOf, logger } from '@sentry/utils';
9+
import { dropUndefinedKeys, logger } from '@sentry/utils';
1010

1111
import { IS_DEBUG_BUILD } from './flags';
1212
import { Span as SpanClass, SpanRecorder } from './span';
@@ -22,7 +22,7 @@ export class Transaction extends SpanClass implements TransactionInterface {
2222
/**
2323
* The reference to the current hub.
2424
*/
25-
private readonly _hub: Hub = getCurrentHub() as unknown as Hub;
25+
private readonly _hub: Hub;
2626

2727
private _trimEnd?: boolean;
2828

@@ -36,9 +36,7 @@ export class Transaction extends SpanClass implements TransactionInterface {
3636
public constructor(transactionContext: TransactionContext, hub?: Hub) {
3737
super(transactionContext);
3838

39-
if (isInstanceOf(hub, Hub)) {
40-
this._hub = hub as Hub;
41-
}
39+
this._hub = hub || getCurrentHub();
4240

4341
this.name = transactionContext.name || '';
4442

0 commit comments

Comments
 (0)