Skip to content

Commit f0fefc0

Browse files
committed
refactor how we do integration options
1 parent 2950ca6 commit f0fefc0

File tree

4 files changed

+23
-17
lines changed

4 files changed

+23
-17
lines changed

packages/node/src/integrations/http.ts

Lines changed: 21 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -108,13 +108,20 @@ export class Http implements Integration {
108108
return;
109109
}
110110

111-
// TODO (v8): `tracePropagationTargets` and `shouldCreateSpanForRequest` will be removed from clientOptions
112-
// and we will no longer have to do this optional merge, we can just pass `this._tracing` directly.
113-
const tracingOptions = this._tracing ? { ...clientOptions, ...this._tracing } : undefined;
111+
const shouldCreateSpanForRequest =
112+
// eslint-disable-next-line deprecation/deprecation
113+
this._tracing?.shouldCreateSpanForRequest || clientOptions?.shouldCreateSpanForRequest;
114+
// eslint-disable-next-line deprecation/deprecation
115+
const tracePropagationTargets = clientOptions?.tracePropagationTargets || this._tracing?.tracePropagationTargets;
114116

115117
// eslint-disable-next-line @typescript-eslint/no-var-requires
116118
const httpModule = require('http');
117-
const wrappedHttpHandlerMaker = _createWrappedRequestMethodFactory(this._breadcrumbs, tracingOptions, httpModule);
119+
const wrappedHttpHandlerMaker = _createWrappedRequestMethodFactory(
120+
httpModule,
121+
this._breadcrumbs,
122+
shouldCreateSpanForRequest,
123+
tracePropagationTargets,
124+
);
118125
fill(httpModule, 'get', wrappedHttpHandlerMaker);
119126
fill(httpModule, 'request', wrappedHttpHandlerMaker);
120127

@@ -125,9 +132,10 @@ export class Http implements Integration {
125132
// eslint-disable-next-line @typescript-eslint/no-var-requires
126133
const httpsModule = require('https');
127134
const wrappedHttpsHandlerMaker = _createWrappedRequestMethodFactory(
128-
this._breadcrumbs,
129-
tracingOptions,
130135
httpsModule,
136+
this._breadcrumbs,
137+
shouldCreateSpanForRequest,
138+
tracePropagationTargets,
131139
);
132140
fill(httpsModule, 'get', wrappedHttpsHandlerMaker);
133141
fill(httpsModule, 'request', wrappedHttpsHandlerMaker);
@@ -150,16 +158,17 @@ type WrappedRequestMethodFactory = (original: OriginalRequestMethod) => WrappedR
150158
* @returns A function which accepts the exiting handler and returns a wrapped handler
151159
*/
152160
function _createWrappedRequestMethodFactory(
153-
breadcrumbsEnabled: boolean,
154-
tracingOptions: TracingOptions | undefined,
155161
httpModule: typeof http | typeof https,
162+
breadcrumbsEnabled: boolean,
163+
shouldCreateSpanForRequest: ((url: string) => boolean) | undefined,
164+
tracePropagationTargets: TracePropagationTargets | undefined,
156165
): WrappedRequestMethodFactory {
157166
// We're caching results so we don't have to recompute regexp every time we create a request.
158167
const createSpanUrlMap = new LRUMap<string, boolean>(100);
159168
const headersUrlMap = new LRUMap<string, boolean>(100);
160169

161170
const shouldCreateSpan = (url: string): boolean => {
162-
if (tracingOptions?.shouldCreateSpanForRequest === undefined) {
171+
if (shouldCreateSpanForRequest === undefined) {
163172
return true;
164173
}
165174

@@ -168,14 +177,13 @@ function _createWrappedRequestMethodFactory(
168177
return cachedDecision;
169178
}
170179

171-
const decision = tracingOptions.shouldCreateSpanForRequest(url);
180+
const decision = shouldCreateSpanForRequest(url);
172181
createSpanUrlMap.set(url, decision);
173182
return decision;
174183
};
175184

176185
const shouldAttachTraceData = (url: string): boolean => {
177-
// eslint-disable-next-line deprecation/deprecation
178-
if (tracingOptions?.tracePropagationTargets === undefined) {
186+
if (tracePropagationTargets === undefined) {
179187
return true;
180188
}
181189

@@ -184,8 +192,7 @@ function _createWrappedRequestMethodFactory(
184192
return cachedDecision;
185193
}
186194

187-
// eslint-disable-next-line deprecation/deprecation
188-
const decision = stringMatchesSomePattern(url, tracingOptions.tracePropagationTargets);
195+
const decision = stringMatchesSomePattern(url, tracePropagationTargets);
189196
headersUrlMap.set(url, decision);
190197
return decision;
191198
};

packages/node/test/integrations/http.test.ts

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -330,7 +330,6 @@ describe('tracing', () => {
330330
return transaction;
331331
}
332332

333-
// TODO (v8): These can be removed once we remove these properties from client options
334333
describe('as client options', () => {
335334
it('creates span with propagation context if shouldCreateSpanForRequest returns false', () => {
336335
const url = 'http://dogs.are.great/api/v1/index/';

packages/remix/test/integration/app_v1/entry.server.tsx

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,7 @@ import * as Sentry from '@sentry/remix';
66
Sentry.init({
77
dsn: 'https://[email protected]/1337',
88
tracesSampleRate: 1,
9-
tracePropagationTargets: [/^(?!.*^\/).*$/],
9+
tracePropagationTargets: ['example.org'],
1010
// Disabling to test series of envelopes deterministically.
1111
autoSessionTracking: false,
1212
});

packages/remix/test/integration/app_v2/entry.server.tsx

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,7 @@ import * as Sentry from '@sentry/remix';
66
Sentry.init({
77
dsn: 'https://[email protected]/1337',
88
tracesSampleRate: 1,
9-
tracePropagationTargets: [/^(?!.*^\/).*$/],
9+
tracePropagationTargets: ['example.org'],
1010
// Disabling to test series of envelopes deterministically.
1111
autoSessionTracking: false,
1212
});

0 commit comments

Comments
 (0)