Skip to content

Commit 4065199

Browse files
committed
make tracing enablement check work without arguments
1 parent bf3c161 commit 4065199

File tree

3 files changed

+13
-16
lines changed

3 files changed

+13
-16
lines changed

packages/tracing/src/browser/request.ts

Lines changed: 4 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,3 @@
1-
import { getCurrentHub } from '@sentry/hub';
21
import { addInstrumentationHandler, isInstanceOf, isMatchingPattern } from '@sentry/utils';
32

43
import { Span } from '../span';
@@ -145,13 +144,7 @@ export function fetchCallback(
145144
shouldCreateSpan: (url: string) => boolean,
146145
spans: Record<string, Span>,
147146
): void {
148-
const currentClientOptions = getCurrentHub()
149-
.getClient()
150-
?.getOptions();
151-
if (
152-
!(currentClientOptions && hasTracingEnabled(currentClientOptions)) ||
153-
!(handlerData.fetchData && shouldCreateSpan(handlerData.fetchData.url))
154-
) {
147+
if (!hasTracingEnabled() || !(handlerData.fetchData && shouldCreateSpan(handlerData.fetchData.url))) {
155148
return;
156149
}
157150

@@ -219,13 +212,10 @@ export function xhrCallback(
219212
shouldCreateSpan: (url: string) => boolean,
220213
spans: Record<string, Span>,
221214
): void {
222-
const currentClientOptions = getCurrentHub()
223-
.getClient()
224-
?.getOptions();
225215
if (
226-
!(currentClientOptions && hasTracingEnabled(currentClientOptions)) ||
227-
!(handlerData.xhr && handlerData.xhr.__sentry_xhr__ && shouldCreateSpan(handlerData.xhr.__sentry_xhr__.url)) ||
228-
handlerData.xhr.__sentry_own_request__
216+
!hasTracingEnabled() ||
217+
handlerData.xhr?.__sentry_own_request__ ||
218+
!(handlerData.xhr?.__sentry_xhr__ && shouldCreateSpan(handlerData.xhr.__sentry_xhr__.url))
229219
) {
230220
return;
231221
}

packages/tracing/src/hubextensions.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -43,7 +43,7 @@ function traceHeaders(this: Hub): { [key: string]: string } {
4343
*/
4444
function sample<T extends Transaction>(transaction: T, options: Options, samplingContext: SamplingContext): T {
4545
// nothing to do if tracing is not enabled
46-
if (!hasTracingEnabled(options)) {
46+
if (!hasTracingEnabled()) {
4747
transaction.sampled = false;
4848
return transaction;
4949
}

packages/tracing/src/utils.ts

Lines changed: 8 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -14,7 +14,14 @@ export const TRACEPARENT_REGEXP = new RegExp(
1414
*
1515
* Tracing is enabled when at least one of `tracesSampleRate` and `tracesSampler` is defined in the SDK config.
1616
*/
17-
export function hasTracingEnabled(options: Options): boolean {
17+
export function hasTracingEnabled(
18+
options: Options | undefined = getCurrentHub()
19+
.getClient()
20+
?.getOptions(),
21+
): boolean {
22+
if (!options) {
23+
return false;
24+
}
1825
return 'tracesSampleRate' in options || 'tracesSampler' in options;
1926
}
2027

0 commit comments

Comments
 (0)