Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

feat(types): Add tracePropagationTargets to top level options #8395

Merged
merged 1 commit into from
Jun 23, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
8 changes: 8 additions & 0 deletions packages/node/src/integrations/http.ts
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

We probably want to delete this comment then:

// TODO (v8): `tracePropagationTargets` and `shouldCreateSpanForRequest` will be removed from clientOptions
// and we will no longer have to do this optional merge, we can just pass `this._tracing` directly.
const tracingOptions = this._tracing ? { ...clientOptions, ...this._tracing } : undefined;

Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,12 @@ interface TracingOptions {
* requests. If this option is provided, the SDK will match the
* request URL of outgoing requests against the items in this
* array, and only attach tracing headers if a match was found.
*
* @deprecated Use top level `tracePropagationTargets` option instead.
* ```
* Sentry.init({
* tracePropagationTargets: ['api.site.com'],
* })
*/
tracePropagationTargets?: TracePropagationTargets;

Expand Down Expand Up @@ -156,6 +162,7 @@ function _createWrappedRequestMethodFactory(
};

const shouldAttachTraceData = (url: string): boolean => {
// eslint-disable-next-line deprecation/deprecation
if (tracingOptions?.tracePropagationTargets === undefined) {
return true;
}
Expand All @@ -165,6 +172,7 @@ function _createWrappedRequestMethodFactory(
return cachedDecision;
}

// eslint-disable-next-line deprecation/deprecation
const decision = stringMatchesSomePattern(url, tracingOptions.tracePropagationTargets);
headersUrlMap.set(url, decision);
return decision;
Expand Down
20 changes: 1 addition & 19 deletions packages/node/src/types.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import type { ClientOptions, Options, SamplingContext, TracePropagationTargets } from '@sentry/types';
import type { ClientOptions, Options, SamplingContext } from '@sentry/types';

import type { NodeTransportOptions } from './transports';

Expand Down Expand Up @@ -32,24 +32,6 @@ export interface BaseNodeOptions {
*/
includeLocalVariables?: boolean;

/**
* List of strings/regex controlling to which outgoing requests
* the SDK will attach tracing headers.
*
* By default the SDK will attach those headers to all outgoing
* requests. If this option is provided, the SDK will match the
* request URL of outgoing requests against the items in this
* array, and only attach tracing headers if a match was found.
*
* @example
* ```js
* Sentry.init({
* tracePropagationTargets: ['api.site.com'],
* });
* ```
*/
tracePropagationTargets?: TracePropagationTargets;

// TODO (v8): Remove this in v8
/**
* @deprecated Moved to constructor options of the `Http` and `Undici` integration.
Expand Down
19 changes: 19 additions & 0 deletions packages/types/src/options.ts
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@ import type { Integration } from './integration';
import type { CaptureContext } from './scope';
import type { SdkMetadata } from './sdkmetadata';
import type { StackLineParser, StackParser } from './stacktrace';
import type { TracePropagationTargets } from './tracing';
import type { SamplingContext } from './transaction';
import type { BaseTransportOptions, Transport } from './transport';

Expand Down Expand Up @@ -221,6 +222,24 @@ export interface ClientOptions<TO extends BaseTransportOptions = BaseTransportOp
*/
denyUrls?: Array<string | RegExp>;

/**
* List of strings/regex controlling to which outgoing requests
* the SDK will attach tracing headers.
*
* By default the SDK will attach those headers to all outgoing
* requests. If this option is provided, the SDK will match the
* request URL of outgoing requests against the items in this
* array, and only attach tracing headers if a match was found.
*
* @example
* ```js
* Sentry.init({
* tracePropagationTargets: ['api.site.com'],
* });
* ```
*/
tracePropagationTargets?: TracePropagationTargets;

/**
* Function to compute tracing sample rate dynamically and filter unwanted traces.
*
Expand Down