Skip to content

Commit f971b62

Browse files
committed
fixes
1 parent 234b803 commit f971b62

File tree

3 files changed

+9
-13
lines changed

3 files changed

+9
-13
lines changed

packages/tracing-internal/src/browser/request.ts

Lines changed: 2 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -15,13 +15,6 @@ import {
1515
import { instrumentFetchRequest } from '../common/fetch';
1616
import { addPerformanceInstrumentationHandler } from './instrument';
1717

18-
/** Exported only for tests. */
19-
export type ExtendedSentryWrappedXMLHttpRequest = SentryWrappedXMLHttpRequest & {
20-
__sentry_xhr_span_id__?: string;
21-
setRequestHeader?: (key: string, val: string) => void;
22-
getRequestHeader?: (key: string) => string;
23-
};
24-
2518
export const DEFAULT_TRACE_PROPAGATION_TARGETS = ['localhost', /^\/(?!\/)/];
2619

2720
/** Options for Request Instrumentation */
@@ -263,7 +256,7 @@ export function xhrCallback(
263256
shouldAttachHeaders: (url: string) => boolean,
264257
spans: Record<string, Span>,
265258
): Span | undefined {
266-
const xhr = handlerData.xhr as ExtendedSentryWrappedXMLHttpRequest;
259+
const xhr = handlerData.xhr;
267260
const sentryXhrData = xhr && xhr[SENTRY_XHR_DATA_KEY];
268261

269262
if (!hasTracingEnabled() || (xhr && xhr.__sentry_own_request__) || !xhr || !sentryXhrData) {
@@ -332,7 +325,7 @@ export function xhrCallback(
332325
}
333326

334327
function setHeaderOnXhr(
335-
xhr: ExtendedSentryWrappedXMLHttpRequest,
328+
xhr: SentryWrappedXMLHttpRequest,
336329
sentryTraceHeader: string,
337330
sentryBaggageHeader: string | undefined,
338331
): void {

packages/tracing-internal/test/browser/request.test.ts

Lines changed: 3 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,13 +1,12 @@
11
/* eslint-disable deprecation/deprecation */
22
import * as sentryCore from '@sentry/core';
3-
import type { HandlerDataFetch } from '@sentry/types';
3+
import type { HandlerDataFetch, SentryWrappedXMLHttpRequest } from '@sentry/types';
44
import * as utils from '@sentry/utils';
55
import { SENTRY_XHR_DATA_KEY } from '@sentry/utils';
66

77
import type { Transaction } from '../../../tracing/src';
88
import { addExtensionMethods, Span, spanStatusfromHttpCode } from '../../../tracing/src';
99
import { getDefaultBrowserClientOptions } from '../../../tracing/test/testutils';
10-
import type { ExtendedSentryWrappedXMLHttpRequest } from '../../src/browser/request';
1110
import {
1211
extractNetworkProtocol,
1312
instrumentOutgoingRequests,
@@ -296,7 +295,7 @@ describe('callbacks', () => {
296295
},
297296
__sentry_xhr_span_id__: '1231201211212012',
298297
setRequestHeader,
299-
} as ExtendedSentryWrappedXMLHttpRequest,
298+
} as SentryWrappedXMLHttpRequest,
300299
startTimestamp,
301300
};
302301
});
@@ -352,7 +351,7 @@ describe('callbacks', () => {
352351
});
353352
expect(newSpan.description).toBe('GET http://dogs.are.great/');
354353
expect(newSpan.op).toBe('http.client');
355-
const spanId = (xhrHandlerData.xhr as ExtendedSentryWrappedXMLHttpRequest | undefined)?.__sentry_xhr_span_id__;
354+
const spanId = xhrHandlerData.xhr?.__sentry_xhr_span_id__;
356355
expect(spanId).toBeDefined();
357356
expect(spanId).toEqual(newSpan?.spanId);
358357

packages/types/src/instrument.ts

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,10 @@ export type ConsoleLevel = 'debug' | 'info' | 'warn' | 'error' | 'log' | 'assert
88
export interface SentryWrappedXMLHttpRequest {
99
__sentry_xhr_v3__?: SentryXhrData;
1010
__sentry_own_request__?: boolean;
11+
// span id for the xhr request
12+
__sentry_xhr_span_id__?: string;
13+
setRequestHeader?: (key: string, val: string) => void;
14+
getRequestHeader?: (key: string) => string;
1115
}
1216

1317
// WARNING: When the shape of this type is changed bump the version in `SentryWrappedXMLHttpRequest`

0 commit comments

Comments
 (0)