diff --git a/CHANGELOG.md b/CHANGELOG.md index 3917f792de..f1e3dda553 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -6,6 +6,12 @@ > make sure you follow our [migration guide](https://docs.sentry.io/platforms/react-native/migration/) first. +## Unreleased + +### Features + +- Adds support for `propagateTraceparent` ([#5277](https://github.com/getsentry/sentry-react-native/pull/5227)) + ## 7.3.0 ### Features diff --git a/packages/core/src/js/options.ts b/packages/core/src/js/options.ts index df830dfdd2..44bfecfd46 100644 --- a/packages/core/src/js/options.ts +++ b/packages/core/src/js/options.ts @@ -291,6 +291,20 @@ export interface BaseReactNativeOptions { * @deprecated This option will be removed in the next major version. Use `beforeSend` instead. */ useThreadsForMessageStack?: boolean; + + /** + * If set to `true`, the SDK propagates the W3C `traceparent` header to any outgoing requests, + * in addition to the `sentry-trace` and `baggage` headers. Use the {@link CoreOptions.tracePropagationTargets} + * option to control to which outgoing requests the header will be attached. + * + * **Important:** If you set this option to `true`, make sure that you configured your servers' + * CORS settings to allow the `traceparent` header. Otherwise, requests might get blocked. + * + * @see https://www.w3.org/TR/trace-context/ + * + * @default false + */ + propagateTraceparent?: boolean; } export type SentryReplayQuality = 'low' | 'medium' | 'high'; diff --git a/packages/core/src/js/sdk.tsx b/packages/core/src/js/sdk.tsx index 7e70ae492f..9b49a8bca6 100644 --- a/packages/core/src/js/sdk.tsx +++ b/packages/core/src/js/sdk.tsx @@ -45,6 +45,7 @@ const DEFAULT_OPTIONS: ReactNativeOptions = { enableNativeFramesTracking: true, enableStallTracking: true, enableUserInteractionTracing: false, + propagateTraceparent: false, }; /** diff --git a/packages/core/test/sdk.test.ts b/packages/core/test/sdk.test.ts index 0c48cad447..992240f5ad 100644 --- a/packages/core/test/sdk.test.ts +++ b/packages/core/test/sdk.test.ts @@ -1158,6 +1158,28 @@ describe('Tests the SDK functionality', () => { }); }); +it('propagateTraceparent is false by default', () => { + init({}); + + const actualOptions = usedOptions(); + expect(actualOptions).toEqual( + expect.objectContaining({ + propagateTraceparent: false, + }), + ); +}); + +it('propagateTraceparent is getting passed to the client', () => { + init({ propagateTraceparent: true }); + + const actualOptions = usedOptions(); + expect(actualOptions).toEqual( + expect.objectContaining({ + propagateTraceparent: true, + }), + ); +}); + function expectIntegration(name: string): void { const actualOptions = usedOptions(); const actualIntegrations = actualOptions?.integrations; diff --git a/packages/core/test/tracing/reactnativetracing.test.ts b/packages/core/test/tracing/reactnativetracing.test.ts index 7aab318b6d..69062e63f8 100644 --- a/packages/core/test/tracing/reactnativetracing.test.ts +++ b/packages/core/test/tracing/reactnativetracing.test.ts @@ -57,6 +57,7 @@ describe('ReactNativeTracing', () => { const instrumentOutgoingRequests = jest.spyOn(SentryBrowser, 'instrumentOutgoingRequests'); setupTestClient({ tracePropagationTargets: ['test1', 'test2'], + propagateTraceparent: true, enableStallTracking: false, integrations: [reactNativeTracingIntegration()], }); @@ -65,6 +66,7 @@ describe('ReactNativeTracing', () => { expect.anything(), expect.objectContaining({ tracePropagationTargets: ['test1', 'test2'], + propagateTraceparent: true, }), ); });