Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
44 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
474ee37
misc(tracing): Remove ReactNativeTracing deprecated options
krystofwoldrich Aug 6, 2024
07d9f00
fix changelog
krystofwoldrich Aug 6, 2024
6386062
refactor react native tracing to new function style integration
krystofwoldrich Aug 7, 2024
3002393
update changelog
krystofwoldrich Aug 7, 2024
2bbb93a
fix test, changelog and samples
krystofwoldrich Aug 8, 2024
9dd899e
fix(tracing): ReactNativeTracing and initial navigation spans have to…
krystofwoldrich Aug 8, 2024
5d98ded
fix background test
krystofwoldrich Aug 9, 2024
ecd26ed
Merge branch 'v6' into kw/tracing-integrations-independent-order
krystofwoldrich Aug 14, 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
1 change: 0 additions & 1 deletion src/js/tracing/integrations/nativeFrames.ts
Original file line number Diff line number Diff line change
Expand Up @@ -73,7 +73,6 @@ export const nativeFramesIntegration = (): Integration => {

NATIVE.enableNativeFramesTracking();

// TODO: Ensure other integrations like ReactNativeTracing and ReactNavigation create spans after all integration are setup.
client.on('spanStart', _onSpanStart);
client.on('spanEnd', _onSpanFinish);
logger.log('[ReactNativeTracing] Native frames instrumentation initialized.');
Expand Down
21 changes: 12 additions & 9 deletions src/js/tracing/reactnativetracing.ts
Original file line number Diff line number Diff line change
Expand Up @@ -111,6 +111,17 @@ export const reactNativeTracingIntegration = (
};

const setup = (client: Client): void => {
addDefaultOpForSpanFrom(client);

instrumentOutgoingRequests({
traceFetch: finalOptions.traceFetch,
traceXHR: finalOptions.traceXHR,
shouldCreateSpanForRequest: finalOptions.shouldCreateSpanForRequest,
tracePropagationTargets: client.getOptions().tracePropagationTargets || DEFAULT_TRACE_PROPAGATION_TARGETS,
});
};

const afterAllSetup = (): void => {
if (finalOptions.routingInstrumentation) {
const idleNavigationSpanOptions = {
finalTimeout: finalOptions.finalTimeoutMs,
Expand Down Expand Up @@ -139,15 +150,6 @@ export const reactNativeTracingIntegration = (
} else {
logger.log(`[${INTEGRATION_NAME}] Not instrumenting route changes as routingInstrumentation has not been set.`);
}

addDefaultOpForSpanFrom(client);

instrumentOutgoingRequests({
traceFetch: finalOptions.traceFetch,
traceXHR: finalOptions.traceXHR,
shouldCreateSpanForRequest: finalOptions.shouldCreateSpanForRequest,
tracePropagationTargets: client.getOptions().tracePropagationTargets || DEFAULT_TRACE_PROPAGATION_TARGETS,
});
};

const processEvent = (event: Event): Event => {
Expand All @@ -160,6 +162,7 @@ export const reactNativeTracingIntegration = (
return {
name: INTEGRATION_NAME,
setup,
afterAllSetup,
processEvent,
options: finalOptions,
state,
Expand Down
1 change: 1 addition & 0 deletions test/tracing/reactnativetracing.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -129,6 +129,7 @@ describe('ReactNativeTracing', () => {
});

integration.setup(client);
integration.afterAllSetup(client);
// wait for internal promises to resolve, fetch app start data from mocked native
await Promise.resolve();

Expand Down
85 changes: 83 additions & 2 deletions test/tracing/reactnavigation.test.ts
Original file line number Diff line number Diff line change
@@ -1,9 +1,9 @@
/* eslint-disable deprecation/deprecation */
/* eslint-disable @typescript-eslint/no-explicit-any */
import { getCurrentScope, getGlobalScope, getIsolationScope, SentrySpan, setCurrentClient } from '@sentry/core';
import type { StartSpanOptions } from '@sentry/types';
import type { Event, Measurements, StartSpanOptions } from '@sentry/types';

import { reactNativeTracingIntegration } from '../../src/js';
import { nativeFramesIntegration, reactNativeTracingIntegration } from '../../src/js';
import { DEFAULT_NAVIGATION_SPAN_NAME } from '../../src/js/tracing/reactnativetracing';
import type { NavigationRoute } from '../../src/js/tracing/reactnavigation';
import { ReactNavigationInstrumentation } from '../../src/js/tracing/reactnavigation';
Expand All @@ -21,13 +21,15 @@ import {
} from '../../src/js/tracing/semanticAttributes';
import { RN_GLOBAL_OBJ } from '../../src/js/utils/worldwide';
import { getDefaultTestClientOptions, TestClient } from '../mocks/client';
import { NATIVE } from '../mockWrapper';
import { createMockNavigationAndAttachTo } from './reactnavigationutils';

const dummyRoute = {
name: 'Route',
key: '0',
};

jest.mock('../../src/js/wrapper.ts', () => jest.requireActual('../mockWrapper.ts'));
jest.useFakeTimers({ advanceTimers: true });

class MockNavigationContainer {
Expand Down Expand Up @@ -82,6 +84,85 @@ describe('ReactNavigationInstrumentation', () => {
);
});

describe('initial navigation span is created after all integrations are setup', () => {
let rnTracing: ReturnType<typeof reactNativeTracingIntegration>;

beforeEach(() => {
const startFrames = {
totalFrames: 100,
slowFrames: 20,
frozenFrames: 5,
};
const finishFrames = {
totalFrames: 200,
slowFrames: 40,
frozenFrames: 10,
};
NATIVE.fetchNativeFrames.mockResolvedValueOnce(startFrames).mockResolvedValueOnce(finishFrames);

const rNavigation = new ReactNavigationInstrumentation({
routeChangeTimeoutMs: 200,
});
mockNavigation = createMockNavigationAndAttachTo(rNavigation);

rnTracing = reactNativeTracingIntegration({
routingInstrumentation: rNavigation,
});
});

test('initial navigation span contains native frames when nativeFrames integration is after react native tracing', async () => {
const options = getDefaultTestClientOptions({
enableNativeFramesTracking: true,
enableStallTracking: false,
tracesSampleRate: 1.0,
integrations: [rnTracing, nativeFramesIntegration()],
enableAppStartTracking: false,
});
client = new TestClient(options);
setCurrentClient(client);
client.init();

// Flush the init transaction, must be async to allow for the native start frames to be fetched
await jest.runOnlyPendingTimersAsync();
await client.flush();

expectInitNavigationSpanWithNativeFrames(client.event);
});

test('initial navigation span contains native frames when nativeFrames integration is before react native tracing', async () => {
const options = getDefaultTestClientOptions({
enableNativeFramesTracking: true,
enableStallTracking: false,
tracesSampleRate: 1.0,
integrations: [nativeFramesIntegration(), rnTracing],
enableAppStartTracking: false,
});
client = new TestClient(options);
setCurrentClient(client);
client.init();

// Flush the init transaction, must be async to allow for the native start frames to be fetched
await jest.runOnlyPendingTimersAsync();
await client.flush();

expectInitNavigationSpanWithNativeFrames(client.event);
});

function expectInitNavigationSpanWithNativeFrames(event: Event): void {
expect(event).toEqual(
expect.objectContaining<Event>({
type: 'transaction',
transaction: 'Initial Screen',
measurements: expect.objectContaining<Measurements>({
frames_total: expect.toBeObject(),
frames_slow: expect.toBeObject(),
frames_frozen: expect.toBeObject(),
}),
}),
);
}
});

test('transaction sent on navigation', async () => {
setupTestClient();
jest.runOnlyPendingTimers(); // Flush the init transaction
Expand Down