Skip to content

Commit 6386062

Browse files
author
Krystof Woldrich
committed
refactor react native tracing to new function style integration
1 parent 07d9f00 commit 6386062

20 files changed

+188
-264
lines changed

samples/react-native/src/App.tsx

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -66,11 +66,10 @@ Sentry.init({
6666
},
6767
integrations(integrations) {
6868
integrations.push(
69-
new Sentry.ReactNativeTracing({
69+
Sentry.reactNativeTracingIntegration({
7070
// The time to wait in ms until the transaction will be finished, For testing, default is 1000 ms
71-
idleTimeout: 5000,
71+
idleTimeoutMs: 5_000,
7272
routingInstrumentation: reactNavigationInstrumentation,
73-
enableUserInteractionTracing: true,
7473
ignoreEmptyBackNavigationTransactions: true,
7574
}),
7675
Sentry.httpClientIntegration({

src/js/client.ts

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -19,7 +19,7 @@ import { defaultSdkInfo } from './integrations/sdkinfo';
1919
import type { ReactNativeClientOptions } from './options';
2020
import type { mobileReplayIntegration } from './replay/mobilereplay';
2121
import { MOBILE_REPLAY_INTEGRATION_NAME } from './replay/mobilereplay';
22-
import type { ReactNativeTracing } from './tracing';
22+
import { getReactNativeTracingIntegration } from './tracing/reactnativetracing';
2323
import { createUserFeedbackEnvelope, items } from './utils/envelope';
2424
import { ignoreRequireCycleLogs } from './utils/ignorerequirecyclelogs';
2525
import { mergeOutcomes } from './utils/outcome';
@@ -141,7 +141,7 @@ export class ReactNativeClient extends BaseClient<ReactNativeClientOptions> {
141141
*/
142142
protected _setupIntegrations(): void {
143143
super._setupIntegrations();
144-
const tracing = this.getIntegrationByName<ReactNativeTracing>('ReactNativeTracing');
144+
const tracing = getReactNativeTracingIntegration(this);
145145
const routingName = tracing?.options?.routingInstrumentation?.name;
146146
if (routingName) {
147147
this.addIntegration(createIntegration(routingName));

src/js/index.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -58,7 +58,7 @@ export { init, wrap, nativeCrash, flush, close, captureUserFeedback, withScope }
5858
export { TouchEventBoundary, withTouchEventBoundary } from './touchevents';
5959

6060
export {
61-
ReactNativeTracing,
61+
reactNativeTracingIntegration,
6262
ReactNavigationV5Instrumentation,
6363
ReactNavigationInstrumentation,
6464
ReactNativeNavigationInstrumentation,

src/js/integrations/default.ts

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,7 @@ import type { BrowserOptions } from '@sentry/react';
33
import type { Integration } from '@sentry/types';
44

55
import type { ReactNativeClientOptions } from '../options';
6-
import { ReactNativeTracing } from '../tracing';
6+
import { reactNativeTracingIntegration } from '../tracing';
77
import { isExpoGo, notWeb } from '../utils/environment';
88
import {
99
appStartIntegration,
@@ -114,7 +114,7 @@ export function getDefaultIntegrations(options: ReactNativeClientOptions): Integ
114114
integrations.push(userInteractionIntegration());
115115
}
116116
if (hasTracingEnabled && options.enableAutoPerformanceTracing) {
117-
integrations.push(new ReactNativeTracing());
117+
integrations.push(reactNativeTracingIntegration());
118118
}
119119
if (options.enableCaptureFailedRequests) {
120120
integrations.push(httpClientIntegration());

src/js/touchevents.tsx

Lines changed: 0 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,6 @@ import type { GestureResponderEvent } from 'react-native';
66
import { StyleSheet, View } from 'react-native';
77

88
import { createIntegration } from './integrations/factory';
9-
import type { ReactNativeTracing } from './tracing';
109
import { startUserInteractionSpan } from './tracing/integrations/userInteraction';
1110
import { UI_ACTION_TOUCH } from './tracing/ops';
1211

@@ -92,17 +91,12 @@ class TouchEventBoundary extends React.Component<TouchEventBoundaryProps> {
9291

9392
public readonly name: string = 'TouchEventBoundary';
9493

95-
private _tracingIntegration: ReactNativeTracing | null = null;
96-
9794
/**
9895
* Registers the TouchEventBoundary as a Sentry Integration.
9996
*/
10097
public componentDidMount(): void {
10198
const client = getClient();
10299
client?.addIntegration?.(createIntegration(this.name));
103-
if (!this._tracingIntegration && client) {
104-
this._tracingIntegration = client.getIntegrationByName<ReactNativeTracing>('ReactNativeTracing') || null;
105-
}
106100
}
107101

108102
/**

src/js/tracing/index.ts

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,5 @@
1-
export { ReactNativeTracing } from './reactnativetracing';
1+
export { reactNativeTracingIntegration } from './reactnativetracing';
2+
export type { ReactNativeTracingIntegration } from './reactnativetracing';
23

34
export type { RoutingInstrumentationInstance } from './routingInstrumentation';
45
export { RoutingInstrumentation } from './routingInstrumentation';

src/js/tracing/integrations/appStart.ts

Lines changed: 4 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -22,7 +22,7 @@ import {
2222
APP_START_WARM as APP_START_WARM_OP,
2323
UI_LOAD as UI_LOAD_OP,
2424
} from '../ops';
25-
import { ReactNativeTracing } from '../reactnativetracing';
25+
// import { getReactNativeTracingIntegration } from '../reactnativetracing';
2626
import { SEMANTIC_ATTRIBUTE_SENTRY_OP } from '../semanticAttributes';
2727
import { createChildSpanJSON, createSpanJSON, getBundleStartTimestampMs } from '../utils';
2828

@@ -108,7 +108,7 @@ export const appStartIntegration = ({
108108
standalone?: boolean;
109109
} = {}): AppStartIntegration => {
110110
let _client: Client | undefined = undefined;
111-
let standalone = standaloneUserOption;
111+
const standalone = standaloneUserOption;
112112
let isEnabled = true;
113113
let appStartDataFlushed = false;
114114

@@ -123,11 +123,10 @@ export const appStartIntegration = ({
123123
}
124124
};
125125

126-
const afterAllSetup = (client: Client): void => {
126+
const afterAllSetup = (_client: Client): void => {
127127
if (standaloneUserOption === undefined) {
128128
// If not user defined, set based on the routing instrumentation presence
129-
standalone = !client.getIntegrationByName<ReactNativeTracing>(ReactNativeTracing.id)?.options
130-
.routingInstrumentation;
129+
// FIXME: standalone = getReactNativeTracingIntegration(client)?.options.routingInstrumentation;
131130
}
132131
};
133132

src/js/tracing/integrations/userInteraction.ts

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -45,7 +45,7 @@ export const startUserInteractionSpan = (userInteractionId: {
4545
logger.log(`[${INTEGRATION_NAME}] User Interaction Tracing can not create transaction with undefined elementId.`);
4646
return undefined;
4747
}
48-
if (!tracing.currentRoute) {
48+
if (!tracing.state.currentRoute) {
4949
logger.log(`[${INTEGRATION_NAME}] User Interaction Tracing can not create transaction without a current route.`);
5050
return undefined;
5151
}
@@ -61,7 +61,7 @@ export const startUserInteractionSpan = (userInteractionId: {
6161
return undefined;
6262
}
6363

64-
const name = `${tracing.currentRoute}.${elementId}`;
64+
const name = `${tracing.state.currentRoute}.${elementId}`;
6565
if (
6666
activeTransaction &&
6767
spanToJSON(activeTransaction).description === name &&

0 commit comments

Comments
 (0)