Skip to content

Commit b5f820b

Browse files
authored
feat(v8/core): Move addTracingHeadersToFetchRequest and instrumentFetchRequest to core (#10918)
With this change we should be ready to move browser tracing into the browser package ref: #9885
1 parent a818271 commit b5f820b

File tree

7 files changed

+15
-21
lines changed

7 files changed

+15
-21
lines changed

packages/tracing-internal/src/common/fetch.ts renamed to packages/core/src/fetch.ts

Lines changed: 11 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -1,23 +1,21 @@
1-
import {
2-
SEMANTIC_ATTRIBUTE_SENTRY_ORIGIN,
3-
SPAN_STATUS_ERROR,
4-
getClient,
5-
getCurrentScope,
6-
getDynamicSamplingContextFromClient,
7-
getDynamicSamplingContextFromSpan,
8-
getIsolationScope,
9-
hasTracingEnabled,
10-
setHttpStatus,
11-
spanToTraceHeader,
12-
startInactiveSpan,
13-
} from '@sentry/core';
141
import type { Client, HandlerDataFetch, Scope, Span, SpanOrigin } from '@sentry/types';
152
import {
163
BAGGAGE_HEADER_NAME,
174
dynamicSamplingContextToSentryBaggageHeader,
185
generateSentryTraceHeader,
196
isInstanceOf,
207
} from '@sentry/utils';
8+
import { getClient, getCurrentScope, getIsolationScope } from './currentScopes';
9+
import { SEMANTIC_ATTRIBUTE_SENTRY_ORIGIN } from './semanticAttributes';
10+
import {
11+
SPAN_STATUS_ERROR,
12+
getDynamicSamplingContextFromClient,
13+
getDynamicSamplingContextFromSpan,
14+
setHttpStatus,
15+
startInactiveSpan,
16+
} from './tracing';
17+
import { hasTracingEnabled } from './utils/hasTracingEnabled';
18+
import { spanToTraceHeader } from './utils/spanUtils';
2119

2220
type PolymorphicRequestHeaders =
2321
| Record<string, string | undefined>
@@ -110,7 +108,6 @@ export function instrumentFetchRequest(
110108
// eslint-disable-next-line @typescript-eslint/no-explicit-any
111109
const options: { [key: string]: any } = handlerData.args[1];
112110

113-
// eslint-disable-next-line @typescript-eslint/no-explicit-any, @typescript-eslint/no-unsafe-member-access
114111
options.headers = addTracingHeadersToFetchRequest(request, client, scope, options, span);
115112
}
116113

packages/core/src/index.ts

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -113,3 +113,4 @@ export { metrics } from './metrics/exports';
113113
export type { MetricData } from './metrics/exports';
114114
export { metricsDefault } from './metrics/exports-default';
115115
export { BrowserMetricsAggregator } from './metrics/browser-aggregator';
116+
export { addTracingHeadersToFetchRequest, instrumentFetchRequest } from './fetch';

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

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,7 @@ import {
66
getDynamicSamplingContextFromSpan,
77
getIsolationScope,
88
hasTracingEnabled,
9+
instrumentFetchRequest,
910
setHttpStatus,
1011
spanToJSON,
1112
spanToTraceHeader,
@@ -23,7 +24,6 @@ import {
2324
stringMatchesSomePattern,
2425
} from '@sentry/utils';
2526

26-
import { instrumentFetchRequest } from '../common/fetch';
2727
import { addPerformanceInstrumentationHandler } from './instrument';
2828
import { WINDOW } from './types';
2929

packages/tracing-internal/src/index.ts

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -25,6 +25,4 @@ export {
2525
addLcpInstrumentationHandler,
2626
} from './browser';
2727

28-
export { addTracingHeadersToFetchRequest, instrumentFetchRequest } from './common/fetch';
29-
3028
export type { RequestInstrumentationOptions } from './browser';

packages/vercel-edge/package.json

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -29,7 +29,6 @@
2929
"access": "public"
3030
},
3131
"dependencies": {
32-
"@sentry-internal/tracing": "8.0.0-alpha.2",
3332
"@sentry/core": "8.0.0-alpha.2",
3433
"@sentry/types": "8.0.0-alpha.2",
3534
"@sentry/utils": "8.0.0-alpha.2"

packages/vercel-edge/src/integrations/wintercg-fetch.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,9 @@
1-
import { instrumentFetchRequest } from '@sentry-internal/tracing';
21
import {
32
addBreadcrumb,
43
convertIntegrationFnToClass,
54
defineIntegration,
65
getClient,
6+
instrumentFetchRequest,
77
isSentryRequestUrl,
88
} from '@sentry/core';
99
import type {

packages/vercel-edge/test/wintercg-fetch.test.ts

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,3 @@
1-
import * as internalTracing from '@sentry-internal/tracing';
21
import * as sentryCore from '@sentry/core';
32
import type { HandlerDataFetch, Integration } from '@sentry/types';
43
import * as sentryUtils from '@sentry/utils';
@@ -14,7 +13,7 @@ class FakeClient extends VercelEdgeClient {
1413
}
1514

1615
const addFetchInstrumentationHandlerSpy = jest.spyOn(sentryUtils, 'addFetchInstrumentationHandler');
17-
const instrumentFetchRequestSpy = jest.spyOn(internalTracing, 'instrumentFetchRequest');
16+
const instrumentFetchRequestSpy = jest.spyOn(sentryCore, 'instrumentFetchRequest');
1817
const addBreadcrumbSpy = jest.spyOn(sentryCore, 'addBreadcrumb');
1918

2019
describe('WinterCGFetch instrumentation', () => {

0 commit comments

Comments
 (0)