-
-
Notifications
You must be signed in to change notification settings - Fork 1.9k
Expand file tree
/
Copy pathtracingIntegration.ts
More file actions
65 lines (59 loc) · 2.64 KB
/
Copy pathtracingIntegration.ts
File metadata and controls
65 lines (59 loc) · 2.64 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
import { browserTracingIntegration as originalBrowserTracingIntegration } from '@sentry/browser';
import type { Integration } from '@sentry/core';
import type { ClientInstrumentation } from 'react-router';
import {
createSentryClientInstrumentation,
type CreateSentryClientInstrumentationOptions,
} from './createClientInstrumentation';
import { instrumentHydratedRouter } from './hydratedRouter';
/**
* Options for the React Router tracing integration.
*/
export interface ReactRouterTracingIntegrationOptions {
/**
* Options for React Router's instrumentation API.
*/
instrumentationOptions?: CreateSentryClientInstrumentationOptions;
/** @deprecated `clientInstrumentation` is always built, so this flag is a no-op. Will be removed in a future major. */
useInstrumentationAPI?: boolean;
}
/**
* React Router tracing integration with support for the instrumentation API.
*/
export interface ReactRouterTracingIntegration extends Integration {
/**
* Client instrumentation to pass to `HydratedRouter`'s `instrumentations` prop.
*
* @deprecated Use the standalone `createSentryClientInstrumentation()` export instead and pass its
* result to `HydratedRouter`'s `instrumentations` prop. This mirrors the server-side
* `createSentryServerInstrumentation()` API. Will be removed in a future major.
*/
readonly clientInstrumentation: ClientInstrumentation;
}
/**
* Browser tracing integration for React Router (Framework) applications.
* This integration will create navigation spans and enhance transaction names with parameterized routes.
*/
export function reactRouterTracingIntegration(
options: ReactRouterTracingIntegrationOptions = {},
): ReactRouterTracingIntegration {
const browserTracingIntegrationInstance = originalBrowserTracingIntegration({
// Navigation transactions are started within the hydrated router instrumentation
instrumentNavigation: false,
});
// Built eagerly so it can be passed to HydratedRouter's `instrumentations` prop. This has no
// side effects - the API is only marked "used" once React Router invokes the `router()` hook.
const clientInstrumentationInstance = createSentryClientInstrumentation(options.instrumentationOptions);
return {
...browserTracingIntegrationInstance,
name: 'ReactRouterTracingIntegration',
afterAllSetup(client) {
browserTracingIntegrationInstance.afterAllSetup(client);
instrumentHydratedRouter();
},
// oxlint-disable-next-line typescript/no-deprecated -- exposes the deprecated getter for back-compat until it is removed
get clientInstrumentation(): ClientInstrumentation {
return clientInstrumentationInstance;
},
};
}