Skip to content

Commit 6ec75e2

Browse files
author
Luca Forstner
committed
wtf
1 parent a660935 commit 6ec75e2

File tree

4 files changed

+20
-27
lines changed

4 files changed

+20
-27
lines changed

packages/core/src/index.ts

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -55,7 +55,6 @@ export { hasTracingEnabled } from './utils/hasTracingEnabled';
5555
export { isSentryRequestUrl } from './utils/isSentryRequestUrl';
5656
export { DEFAULT_ENVIRONMENT } from './constants';
5757
export { ModuleMetadata } from './integrations/metadata';
58-
export { instrumentFetchRequest } from './fetch';
5958
import * as Integrations from './integrations';
6059

6160
export { Integrations };

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

Lines changed: 2 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1,10 +1,5 @@
11
/* eslint-disable max-lines */
2-
import {
3-
getCurrentHub,
4-
getDynamicSamplingContextFromClient,
5-
hasTracingEnabled,
6-
instrumentFetchRequest,
7-
} from '@sentry/core';
2+
import { getCurrentHub, getDynamicSamplingContextFromClient, hasTracingEnabled } from '@sentry/core';
83
import type { Client, HandlerDataFetch, Scope, Span } from '@sentry/types';
94
import {
105
addInstrumentationHandler,
@@ -17,6 +12,7 @@ import {
1712
stringMatchesSomePattern,
1813
} from '@sentry/utils';
1914

15+
import { instrumentFetchRequest } from '../common/fetch';
2016
import { addPerformanceInstrumentationHandler } from './instrument';
2117

2218
export const DEFAULT_TRACE_PROPAGATION_TARGETS = ['localhost', /^\/(?!\/)/];

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

Lines changed: 1 addition & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,4 @@
1+
import { getCurrentHub, getDynamicSamplingContextFromClient } from '@sentry/core';
12
import type { Client, HandlerDataFetch, Scope, Span, SpanOrigin } from '@sentry/types';
23
import {
34
BAGGAGE_HEADER_NAME,
@@ -6,9 +7,6 @@ import {
67
isInstanceOf,
78
} from '@sentry/utils';
89

9-
import { getCurrentHub } from './hub';
10-
import { getDynamicSamplingContextFromClient } from './tracing';
11-
1210
type PolymorphicRequestHeaders =
1311
| Record<string, string | undefined>
1412
| Array<[string, string]>

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

Lines changed: 17 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -1,19 +1,20 @@
11
/* eslint-disable deprecation/deprecation */
22
import * as sentryCore from '@sentry/core';
3+
import type { HandlerDataFetch } from '@sentry/types';
34
import * as utils from '@sentry/utils';
45
import { SENTRY_XHR_DATA_KEY } from '@sentry/utils';
56

67
import type { Transaction } from '../../../tracing/src';
78
import { addExtensionMethods, Span, spanStatusfromHttpCode } from '../../../tracing/src';
89
import { getDefaultBrowserClientOptions } from '../../../tracing/test/testutils';
9-
import type { FetchData, XHRData } from '../../src/browser/request';
10+
import type { XHRData } from '../../src/browser/request';
1011
import {
1112
extractNetworkProtocol,
12-
fetchCallback,
1313
instrumentOutgoingRequests,
1414
shouldAttachHeaders,
1515
xhrCallback,
1616
} from '../../src/browser/request';
17+
import { instrumentFetchRequest } from '../../src/common/fetch';
1718
import { TestClient } from '../utils/TestClient';
1819

1920
beforeAll(() => {
@@ -76,7 +77,7 @@ describe('callbacks', () => {
7677
});
7778

7879
describe('fetchCallback()', () => {
79-
let fetchHandlerData: FetchData;
80+
let fetchHandlerData: HandlerDataFetch;
8081

8182
const fetchSpan = {
8283
data: {
@@ -109,7 +110,7 @@ describe('callbacks', () => {
109110
])(
110111
'span creation/header attachment interaction - shouldCreateSpan: %s, shouldAttachHeaders: %s',
111112
(shouldCreateSpanReturnValue, shouldAttachHeadersReturnValue, expectedSpan, expectedHeaderKeys) => {
112-
fetchCallback(
113+
instrumentFetchRequest(
113114
fetchHandlerData,
114115
() => shouldCreateSpanReturnValue,
115116
() => shouldAttachHeadersReturnValue,
@@ -126,10 +127,9 @@ describe('callbacks', () => {
126127
);
127128

128129
it('adds neither fetch request spans nor fetch request headers if there is no fetch data in handler data', () => {
129-
delete fetchHandlerData.fetchData;
130130
const spans = {};
131131

132-
fetchCallback(fetchHandlerData, alwaysCreateSpan, alwaysAttachHeaders, spans);
132+
instrumentFetchRequest(fetchHandlerData, alwaysCreateSpan, alwaysAttachHeaders, spans);
133133

134134
expect(spans).toEqual({});
135135

@@ -141,7 +141,7 @@ describe('callbacks', () => {
141141
hasTracingEnabled.mockReturnValueOnce(false);
142142
const spans = {};
143143

144-
fetchCallback(fetchHandlerData, alwaysCreateSpan, alwaysAttachHeaders, spans);
144+
instrumentFetchRequest(fetchHandlerData, alwaysCreateSpan, alwaysAttachHeaders, spans);
145145

146146
expect(spans).toEqual({});
147147

@@ -153,7 +153,7 @@ describe('callbacks', () => {
153153
const spans = {};
154154

155155
// triggered by request being sent
156-
fetchCallback(fetchHandlerData, alwaysCreateSpan, alwaysAttachHeaders, spans);
156+
instrumentFetchRequest(fetchHandlerData, alwaysCreateSpan, alwaysAttachHeaders, spans);
157157

158158
const newSpan = transaction.spanRecorder?.spans[1] as Span;
159159

@@ -174,7 +174,7 @@ describe('callbacks', () => {
174174
};
175175

176176
// triggered by response coming back
177-
fetchCallback(postRequestFetchHandlerData, alwaysCreateSpan, alwaysAttachHeaders, spans);
177+
instrumentFetchRequest(postRequestFetchHandlerData, alwaysCreateSpan, alwaysAttachHeaders, spans);
178178

179179
expect(newSpan.endTimestamp).toBeDefined();
180180
});
@@ -183,7 +183,7 @@ describe('callbacks', () => {
183183
const spans: Record<string, Span> = {};
184184

185185
// triggered by request being sent
186-
fetchCallback(fetchHandlerData, alwaysCreateSpan, alwaysAttachHeaders, spans);
186+
instrumentFetchRequest(fetchHandlerData, alwaysCreateSpan, alwaysAttachHeaders, spans);
187187

188188
const newSpan = transaction.spanRecorder?.spans[1] as Span;
189189

@@ -196,7 +196,7 @@ describe('callbacks', () => {
196196
};
197197

198198
// triggered by response coming back
199-
fetchCallback(postRequestFetchHandlerData, alwaysCreateSpan, alwaysAttachHeaders, spans);
199+
instrumentFetchRequest(postRequestFetchHandlerData, alwaysCreateSpan, alwaysAttachHeaders, spans);
200200

201201
expect(newSpan.status).toBe(spanStatusfromHttpCode(404));
202202
});
@@ -211,7 +211,7 @@ describe('callbacks', () => {
211211
};
212212

213213
// in that case, the response coming back will be ignored
214-
fetchCallback(postRequestFetchHandlerData, alwaysCreateSpan, alwaysAttachHeaders, {});
214+
instrumentFetchRequest(postRequestFetchHandlerData, alwaysCreateSpan, alwaysAttachHeaders, {});
215215

216216
const newSpan = transaction.spanRecorder?.spans[1];
217217

@@ -221,7 +221,7 @@ describe('callbacks', () => {
221221
it('uses active span to generate sentry-trace header', () => {
222222
const spans: Record<string, Span> = {};
223223
// triggered by request being sent
224-
fetchCallback(fetchHandlerData, alwaysCreateSpan, alwaysAttachHeaders, spans);
224+
instrumentFetchRequest(fetchHandlerData, alwaysCreateSpan, alwaysAttachHeaders, spans);
225225

226226
const activeSpan = transaction.spanRecorder?.spans[1] as Span;
227227

@@ -232,7 +232,7 @@ describe('callbacks', () => {
232232
};
233233

234234
// triggered by response coming back
235-
fetchCallback(postRequestFetchHandlerData, alwaysCreateSpan, alwaysAttachHeaders, spans);
235+
instrumentFetchRequest(postRequestFetchHandlerData, alwaysCreateSpan, alwaysAttachHeaders, spans);
236236

237237
const headers = (fetchHandlerData.args[1].headers as Record<string, string>) || {};
238238
expect(headers['sentry-trace']).toEqual(`${activeSpan.traceId}-${activeSpan.spanId}-1`);
@@ -242,7 +242,7 @@ describe('callbacks', () => {
242242
const spans: Record<string, Span> = {};
243243

244244
// triggered by request being sent
245-
fetchCallback(fetchHandlerData, alwaysCreateSpan, alwaysAttachHeaders, spans);
245+
instrumentFetchRequest(fetchHandlerData, alwaysCreateSpan, alwaysAttachHeaders, spans);
246246

247247
const newSpan = transaction.spanRecorder?.spans[1] as Span;
248248

@@ -252,10 +252,10 @@ describe('callbacks', () => {
252252
...fetchHandlerData,
253253
endTimestamp,
254254
response: { status: 404, headers: { get: () => 123 } },
255-
};
255+
} as unknown as HandlerDataFetch;
256256

257257
// triggered by response coming back
258-
fetchCallback(postRequestFetchHandlerData, alwaysCreateSpan, alwaysAttachHeaders, spans);
258+
instrumentFetchRequest(postRequestFetchHandlerData, alwaysCreateSpan, alwaysAttachHeaders, spans);
259259

260260
const finishedSpan = transaction.spanRecorder?.spans[1] as Span;
261261

0 commit comments

Comments
 (0)