|
1 | 1 | /* eslint-disable @typescript-eslint/no-explicit-any */ |
2 | 2 | import type { SpanStatusType, User } from '@sentry/browser'; |
3 | | -import { BrowserClient } from '@sentry/browser'; |
| 3 | +import * as SentryBrowser from '@sentry/browser'; |
4 | 4 | import type { IdleTransaction } from '@sentry/core'; |
5 | 5 | import { addGlobalEventProcessor, Hub, Transaction } from '@sentry/core'; |
6 | 6 |
|
7 | 7 | import type { NativeAppStartResponse } from '../../src/js/NativeRNSentry'; |
8 | 8 | import { RoutingInstrumentation } from '../../src/js/tracing/routingInstrumentation'; |
9 | 9 |
|
| 10 | +const BrowserClient = SentryBrowser.BrowserClient; |
| 11 | + |
10 | 12 | jest.mock('../../src/js/wrapper', () => { |
11 | 13 | return { |
12 | 14 | NATIVE: { |
@@ -117,6 +119,148 @@ describe('ReactNativeTracing', () => { |
117 | 119 | jest.clearAllMocks(); |
118 | 120 | }); |
119 | 121 |
|
| 122 | + describe('trace propagation targets', () => { |
| 123 | + it('uses tracingOrigins', () => { |
| 124 | + const instrumentOutgoingRequests = jest.spyOn(SentryBrowser, 'instrumentOutgoingRequests'); |
| 125 | + const mockedHub = { |
| 126 | + getClient: () => ({ |
| 127 | + getOptions: () => ({}), |
| 128 | + }), |
| 129 | + }; |
| 130 | + |
| 131 | + const integration = new ReactNativeTracing({ |
| 132 | + tracingOrigins: ['test1', 'test2'], |
| 133 | + }); |
| 134 | + integration.setupOnce( |
| 135 | + () => {}, |
| 136 | + () => mockedHub as unknown as Hub, |
| 137 | + ); |
| 138 | + |
| 139 | + expect(instrumentOutgoingRequests).toBeCalledWith( |
| 140 | + expect.objectContaining({ |
| 141 | + tracePropagationTargets: ['test1', 'test2'], |
| 142 | + }), |
| 143 | + ); |
| 144 | + }); |
| 145 | + |
| 146 | + it('uses tracePropagationTargets', () => { |
| 147 | + const instrumentOutgoingRequests = jest.spyOn(SentryBrowser, 'instrumentOutgoingRequests'); |
| 148 | + const mockedHub = { |
| 149 | + getClient: () => ({ |
| 150 | + getOptions: () => ({}), |
| 151 | + }), |
| 152 | + }; |
| 153 | + |
| 154 | + const integration = new ReactNativeTracing({ |
| 155 | + tracePropagationTargets: ['test1', 'test2'], |
| 156 | + }); |
| 157 | + integration.setupOnce( |
| 158 | + () => {}, |
| 159 | + () => mockedHub as unknown as Hub, |
| 160 | + ); |
| 161 | + |
| 162 | + expect(instrumentOutgoingRequests).toBeCalledWith( |
| 163 | + expect.objectContaining({ |
| 164 | + tracePropagationTargets: ['test1', 'test2'], |
| 165 | + }), |
| 166 | + ); |
| 167 | + }); |
| 168 | + |
| 169 | + it('uses tracePropagationTargets from client options', () => { |
| 170 | + const instrumentOutgoingRequests = jest.spyOn(SentryBrowser, 'instrumentOutgoingRequests'); |
| 171 | + const mockedHub = { |
| 172 | + getClient: () => ({ |
| 173 | + getOptions: () => ({ |
| 174 | + tracePropagationTargets: ['test1', 'test2'], |
| 175 | + }), |
| 176 | + }), |
| 177 | + }; |
| 178 | + |
| 179 | + const integration = new ReactNativeTracing({}); |
| 180 | + integration.setupOnce( |
| 181 | + () => {}, |
| 182 | + () => mockedHub as unknown as Hub, |
| 183 | + ); |
| 184 | + |
| 185 | + expect(instrumentOutgoingRequests).toBeCalledWith( |
| 186 | + expect.objectContaining({ |
| 187 | + tracePropagationTargets: ['test1', 'test2'], |
| 188 | + }), |
| 189 | + ); |
| 190 | + }); |
| 191 | + |
| 192 | + it('uses defaults', () => { |
| 193 | + const instrumentOutgoingRequests = jest.spyOn(SentryBrowser, 'instrumentOutgoingRequests'); |
| 194 | + const mockedHub = { |
| 195 | + getClient: () => ({ |
| 196 | + getOptions: () => ({}), |
| 197 | + }), |
| 198 | + }; |
| 199 | + |
| 200 | + const integration = new ReactNativeTracing({}); |
| 201 | + integration.setupOnce( |
| 202 | + () => {}, |
| 203 | + () => mockedHub as unknown as Hub, |
| 204 | + ); |
| 205 | + |
| 206 | + expect(instrumentOutgoingRequests).toBeCalledWith( |
| 207 | + expect.objectContaining({ |
| 208 | + tracePropagationTargets: ['localhost', /^\/(?!\/)/], |
| 209 | + }), |
| 210 | + ); |
| 211 | + }); |
| 212 | + |
| 213 | + it('client tracePropagationTargets takes priority over integration options', () => { |
| 214 | + const instrumentOutgoingRequests = jest.spyOn(SentryBrowser, 'instrumentOutgoingRequests'); |
| 215 | + const mockedHub = { |
| 216 | + getClient: () => ({ |
| 217 | + getOptions: () => ({ |
| 218 | + tracePropagationTargets: ['test1', 'test2'], |
| 219 | + }), |
| 220 | + }), |
| 221 | + }; |
| 222 | + |
| 223 | + const integration = new ReactNativeTracing({ |
| 224 | + tracePropagationTargets: ['test3', 'test4'], |
| 225 | + tracingOrigins: ['test5', 'test6'], |
| 226 | + }); |
| 227 | + integration.setupOnce( |
| 228 | + () => {}, |
| 229 | + () => mockedHub as unknown as Hub, |
| 230 | + ); |
| 231 | + |
| 232 | + expect(instrumentOutgoingRequests).toBeCalledWith( |
| 233 | + expect.objectContaining({ |
| 234 | + tracePropagationTargets: ['test1', 'test2'], |
| 235 | + }), |
| 236 | + ); |
| 237 | + }); |
| 238 | + |
| 239 | + it('integration tracePropagationTargets takes priority over tracingOrigins', () => { |
| 240 | + const instrumentOutgoingRequests = jest.spyOn(SentryBrowser, 'instrumentOutgoingRequests'); |
| 241 | + const mockedHub = { |
| 242 | + getClient: () => ({ |
| 243 | + getOptions: () => ({}), |
| 244 | + }), |
| 245 | + }; |
| 246 | + |
| 247 | + const integration = new ReactNativeTracing({ |
| 248 | + tracePropagationTargets: ['test3', 'test4'], |
| 249 | + tracingOrigins: ['test5', 'test6'], |
| 250 | + }); |
| 251 | + integration.setupOnce( |
| 252 | + () => {}, |
| 253 | + () => mockedHub as unknown as Hub, |
| 254 | + ); |
| 255 | + |
| 256 | + expect(instrumentOutgoingRequests).toBeCalledWith( |
| 257 | + expect.objectContaining({ |
| 258 | + tracePropagationTargets: ['test3', 'test4'], |
| 259 | + }), |
| 260 | + ); |
| 261 | + }); |
| 262 | + }); |
| 263 | + |
120 | 264 | describe('App Start', () => { |
121 | 265 | describe('Without routing instrumentation', () => { |
122 | 266 | it('Starts route transaction (cold)', async () => { |
|
0 commit comments