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

(4) ref(tracing): Extract UserInteractionTracing as standalone interaction #3999

Merged
merged 37 commits into from
Aug 13, 2024
Merged
Show file tree
Hide file tree
Changes from 36 commits
Commits
Show all changes
37 commits
Select commit Hold shift + click to select a range
c3dcfd3
chore(tracing): extract app start to a standalone integration
krystofwoldrich Jun 3, 2024
88d6988
Merge branch 'v6' into kw/ref-app-start-integration
krystofwoldrich Jun 11, 2024
fe53af5
fix merge
krystofwoldrich Jun 11, 2024
d4ac89f
fix spans, app start is now reported to Sentry
krystofwoldrich Jun 11, 2024
7c5dcaa
fix uikit init and minimal instrumentation edge cases
krystofwoldrich Jun 12, 2024
0b42472
update js docs
krystofwoldrich Jun 12, 2024
9765eaf
Merge branch 'v6' into kw/ref-app-start-integration
krystofwoldrich Aug 4, 2024
b9e9e9a
Add App Start Integration tests
krystofwoldrich Aug 5, 2024
b334931
Remove app start test from react native tracing
krystofwoldrich Aug 5, 2024
4d16787
clean up app start tests
krystofwoldrich Aug 5, 2024
4d84922
fix test affected by the app start extraction
krystofwoldrich Aug 5, 2024
0ff2020
Add standalone app start
krystofwoldrich Aug 5, 2024
b1eab51
fix
krystofwoldrich Aug 5, 2024
6d1cd70
ref(tracing): Extract NativeFrames as standalone integration
krystofwoldrich Aug 5, 2024
5eaaad2
Add integration handling test
krystofwoldrich Aug 6, 2024
eba6820
Merge branch 'kw/ref-app-start-integration' into kw/ref-native-frames…
krystofwoldrich Aug 6, 2024
91c1eb8
clean up integrations tests
krystofwoldrich Aug 6, 2024
db70c09
move native frames tests
krystofwoldrich Aug 6, 2024
e199244
add changelog
krystofwoldrich Aug 6, 2024
2956344
Merge branch 'kw/ref-app-start-integration' into kw/ref-native-frames…
krystofwoldrich Aug 6, 2024
adb53fc
fix
krystofwoldrich Aug 6, 2024
699fda7
move the app start test to tracing
krystofwoldrich Aug 6, 2024
7a386ab
Merge branch 'kw/ref-app-start-integration' into kw/ref-native-frames…
krystofwoldrich Aug 6, 2024
ad98ac0
fix tests
krystofwoldrich Aug 6, 2024
f2b9abe
add changelog
krystofwoldrich Aug 6, 2024
89b2354
ref(tracing): Extract Stall Tracking to a standalone integration
krystofwoldrich Aug 6, 2024
4f3ca7b
misc(tracing): Remove ReactNativeTracing deprecated options
krystofwoldrich Aug 6, 2024
5c12e5c
fix changelog
krystofwoldrich Aug 6, 2024
a111bdf
ref(tracing): Extract UserInteractionTracing as standalone interaction
krystofwoldrich Aug 6, 2024
92e04ee
Apply suggestions from code review
krystofwoldrich Aug 7, 2024
1168d4e
Revert "fix changelog"
krystofwoldrich Aug 7, 2024
a21e83d
Revert "misc(tracing): Remove ReactNativeTracing deprecated options"
krystofwoldrich Aug 7, 2024
af4c453
tests
krystofwoldrich Aug 7, 2024
3d33c02
fix tests
krystofwoldrich Aug 7, 2024
c71b900
fix tests
krystofwoldrich Aug 7, 2024
e632d53
Merge commit 'c71b9003a8934eca268d524732ab337325bc238d' into kw/ref-u…
krystofwoldrich Aug 7, 2024
76c22b4
Merge remote-tracking branch 'origin/v6' into kw/ref-user-interaction…
krystofwoldrich Aug 13, 2024
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
27 changes: 27 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,33 @@

## Unreleased

### Changes

- New Native Frames Integration ([#3996](https://github.com/getsentry/sentry-react-native/pull/3996))
- New Stall Tracking Integration ([#3997](https://github.com/getsentry/sentry-react-native/pull/3997))
- New User Interaction Tracing Integration ([#3999](https://github.com/getsentry/sentry-react-native/pull/3999))
- New App Start Integration ([#3852](https://github.com/getsentry/sentry-react-native/pull/3852))

By default app start spans are attached to the first created transaction.
Standalone mode creates single root span (transaction) including only app start data.

```js
import Sentry from '@sentry/react-native';

Sentry.init({
tracesSampleRate: 1.0,
enableAppStartTracking: true, // default true
enableNativeFramesTracking: true, // default true
enableStallTracking: true, // default true
enableUserInteractionTracing: true, // default false
integrations: [
Sentry.appStartIntegration({
standalone: false, // default false
}),
],
});
```

### Fixes

- Pass `sampleRate` option to the Android SDK ([#3979](https://github.com/getsentry/sentry-react-native/pull/3979))
Expand Down
3 changes: 3 additions & 0 deletions samples/react-native/src/App.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -88,6 +88,9 @@ Sentry.init({
maskAllVectors: true,
// maskAllText: false,
}),
Sentry.appStartIntegration({
standalone: false,
}),
);
return integrations.filter(i => i.name !== 'Dedupe');
},
Expand Down
4 changes: 0 additions & 4 deletions src/js/client.ts
Original file line number Diff line number Diff line change
Expand Up @@ -146,10 +146,6 @@ export class ReactNativeClient extends BaseClient<ReactNativeClientOptions> {
if (routingName) {
this.addIntegration(createIntegration(routingName));
}
const enableUserInteractionTracing = tracing?.options.enableUserInteractionTracing;
if (enableUserInteractionTracing) {
this.addIntegration(createIntegration('ReactNativeUserInteractionTracing'));
}
}

/**
Expand Down
16 changes: 16 additions & 0 deletions src/js/integrations/default.ts
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@ import type { ReactNativeClientOptions } from '../options';
import { ReactNativeTracing } from '../tracing';
import { isExpoGo, notWeb } from '../utils/environment';
import {
appStartIntegration,
breadcrumbsIntegration,
browserApiErrorsIntegration,
browserGlobalHandlersIntegration,
Expand All @@ -23,13 +24,16 @@ import {
inboundFiltersIntegration,
mobileReplayIntegration,
modulesLoaderIntegration,
nativeFramesIntegration,
nativeLinkedErrorsIntegration,
nativeReleaseIntegration,
reactNativeErrorHandlersIntegration,
reactNativeInfoIntegration,
screenshotIntegration,
sdkInfoIntegration,
spotlightIntegration,
stallTrackingIntegration,
userInteractionIntegration,
viewHierarchyIntegration,
} from './exports';
import { createReactNativeRewriteFrames } from './rewriteframes';
Expand Down Expand Up @@ -97,6 +101,18 @@ export function getDefaultIntegrations(options: ReactNativeClientOptions): Integ
options.enableTracing ||
typeof options.tracesSampleRate === 'number' ||
typeof options.tracesSampler === 'function';
if (hasTracingEnabled && options.enableAppStartTracking) {
integrations.push(appStartIntegration());
}
if (hasTracingEnabled && options.enableNativeFramesTracking) {
integrations.push(nativeFramesIntegration());
}
if (hasTracingEnabled && options.enableStallTracking) {
integrations.push(stallTrackingIntegration());
}
if (hasTracingEnabled && options.enableUserInteractionTracing) {
integrations.push(userInteractionIntegration());
}
if (hasTracingEnabled && options.enableAutoPerformanceTracing) {
integrations.push(new ReactNativeTracing());
}
Expand Down
4 changes: 4 additions & 0 deletions src/js/integrations/exports.ts
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,10 @@ export { viewHierarchyIntegration } from './viewhierarchy';
export { expoContextIntegration } from './expocontext';
export { spotlightIntegration } from './spotlight';
export { mobileReplayIntegration } from '../replay/mobilereplay';
export { appStartIntegration } from '../tracing/integrations/appStart';
export { nativeFramesIntegration } from '../tracing/integrations/nativeFrames';
export { stallTrackingIntegration } from '../tracing/integrations/stalltracking';
export { userInteractionIntegration } from '../tracing/integrations/userInteraction';

export {
breadcrumbsIntegration,
Expand Down
32 changes: 32 additions & 0 deletions src/js/options.ts
Original file line number Diff line number Diff line change
Expand Up @@ -188,6 +188,38 @@ export interface BaseReactNativeOptions {
*/
beforeScreenshot?: (event: Event, hint: EventHint) => boolean;

/**
* Track the app start time by adding measurements to the first route transaction. If there is no routing instrumentation
* an app start transaction will be started.
*
* Requires performance monitoring to be enabled.
*
* @default true
*/
enableAppStartTracking?: boolean;

/**
* Track the slow and frozen frames in the application. Enabling this options will add
* slow and frozen frames measurements to all created root spans (transactions).
*
* @default true
*/
enableNativeFramesTracking?: boolean;

/**
* Track when and how long the JS event loop stalls for. Adds stalls as measurements to all transactions.
*
* @default true
*/
enableStallTracking?: boolean;

/**
* Trace User Interaction events like touch and gestures.
*
* @default false
*/
enableUserInteractionTracing?: boolean;

/**
* Options which are in beta, or otherwise not guaranteed to be stable.
*/
Expand Down
10 changes: 4 additions & 6 deletions src/js/sdk.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,6 @@ import type { ReactNativeClientOptions, ReactNativeOptions, ReactNativeWrapperOp
import { shouldEnableNativeNagger } from './options';
import { enableSyncToNative } from './scopeSync';
import { TouchEventBoundary } from './touchevents';
import type { ReactNativeTracing } from './tracing';
import { ReactNativeProfiler } from './tracing';
import { useEncodePolyfill } from './transports/encodePolyfill';
import { DEFAULT_BUFFER_SIZE, makeNativeTransportFactory } from './transports/native';
Expand All @@ -34,6 +33,10 @@ const DEFAULT_OPTIONS: ReactNativeOptions = {
attachStacktrace: true,
enableCaptureFailedRequests: false,
enableNdk: true,
enableAppStartTracking: true,
enableNativeFramesTracking: true,
enableStallTracking: true,
enableUserInteractionTracing: false,
};

/**
Expand Down Expand Up @@ -112,11 +115,6 @@ export function wrap<P extends Record<string, unknown>>(
RootComponent: React.ComponentType<P>,
options?: ReactNativeWrapperOptions
): React.ComponentType<P> {
const tracingIntegration = getClient()?.getIntegrationByName?.('ReactNativeTracing') as ReactNativeTracing | undefined;
if (tracingIntegration) {
tracingIntegration.useAppStartWithProfiler = true;
}

const profilerProps = {
...(options?.profilerProps ?? {}),
name: RootComponent.displayName ?? 'Root',
Expand Down
3 changes: 2 additions & 1 deletion src/js/touchevents.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@ import { StyleSheet, View } from 'react-native';

import { createIntegration } from './integrations/factory';
import type { ReactNativeTracing } from './tracing';
import { startUserInteractionSpan } from './tracing/integrations/userInteraction';
import { UI_ACTION_TOUCH } from './tracing/ops';

export type TouchEventBoundaryProps = {
Expand Down Expand Up @@ -200,7 +201,7 @@ class TouchEventBoundary extends React.Component<TouchEventBoundaryProps> {
this._logTouchEvent(touchPath, label);
}

this._tracingIntegration?.startUserInteractionSpan({
startUserInteractionSpan({
elementId: label,
op: UI_ACTION_TOUCH,
});
Expand Down
8 changes: 3 additions & 5 deletions src/js/tracing/gesturetracing.ts
Original file line number Diff line number Diff line change
@@ -1,9 +1,9 @@
import { addBreadcrumb, getClient } from '@sentry/core';
import { addBreadcrumb } from '@sentry/core';
import type { Breadcrumb } from '@sentry/types';
import { logger } from '@sentry/utils';

import { startUserInteractionSpan } from './integrations/userInteraction';
import { UI_ACTION } from './ops';
import type { ReactNativeTracing } from './reactnativetracing';

export const DEFAULT_BREADCRUMB_CATEGORY = 'gesture';
export const DEFAULT_BREADCRUMB_TYPE = 'user';
Expand Down Expand Up @@ -69,9 +69,7 @@ export function sentryTraceGesture<GestureT>(

const originalOnBegin = gestureCandidate.handlers.onBegin;
(gesture as unknown as Required<BaseGesture>).handlers.onBegin = (event: GestureEvent) => {
getClient()
?.getIntegrationByName<ReactNativeTracing>('ReactNativeTracing')
?.startUserInteractionSpan({ elementId: label, op: `${UI_ACTION}.${name}` });
startUserInteractionSpan({ elementId: label, op: `${UI_ACTION}.${name}` });

addGestureBreadcrumb(`Gesture ${label} begin.`, { event, name });

Expand Down
Loading
Loading