Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
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
6 changes: 5 additions & 1 deletion packages/core/src/js/tracing/integrations/nativeFrames.ts
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
import type { Client, Event, Integration, Measurements, MeasurementUnit, Span } from '@sentry/core';
import { debug, getRootSpan, spanToJSON, timestampInSeconds } from '@sentry/core';
import { debug, getRootSpan, spanIsSampled, spanToJSON, timestampInSeconds } from '@sentry/core';
import type { NativeFramesResponse } from '../../NativeRNSentry';
import { AsyncExpiringMap } from '../../utils/AsyncExpiringMap';
import { isRootSpan } from '../../utils/span';
Expand Down Expand Up @@ -86,6 +86,10 @@ export const nativeFramesIntegration = (): Integration => {
};

const fetchStartFramesForSpan = (span: Span): void => {
if (!spanIsSampled(span)) {
return;
}

const spanId = span.spanContext().spanId;
const spanType = isRootSpan(span) ? 'root' : 'child';
debug.log(`[${INTEGRATION_NAME}] Fetching frames for ${spanType} span start (${spanId}).`);
Expand Down
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
/* eslint-disable max-lines */
import type { Client, Integration, Measurements, MeasurementUnit, Span } from '@sentry/core';
import { debug, getRootSpan, spanToJSON, timestampInSeconds } from '@sentry/core';
import { debug, getRootSpan, spanIsSampled, spanToJSON, timestampInSeconds } from '@sentry/core';
import type { AppStateStatus } from 'react-native';
import { AppState } from 'react-native';
import { STALL_COUNT, STALL_LONGEST_TIME, STALL_TOTAL_TIME } from '../../measurements';
Expand Down Expand Up @@ -123,6 +123,10 @@ export const stallTrackingIntegration = ({
return;
}

if (!spanIsSampled(rootSpan)) {
return;
}

if (statsByRootSpan.has(rootSpan)) {
debug.error(
'[StallTracking] Tried to start stall tracking on a transaction already being tracked. Measurements might be lost.',
Expand Down
27 changes: 27 additions & 0 deletions packages/core/test/tracing/integrations/nativeframes.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -520,4 +520,31 @@ describe('NativeFramesInstrumentation', () => {
}),
);
});

describe('unsampled spans', () => {
beforeEach(() => {
global.Date.now = jest.fn(() => mockDate.getTime());

getCurrentScope().clear();
getIsolationScope().clear();
getGlobalScope().clear();

const options = getDefaultTestClientOptions({
tracesSampleRate: 0,
enableNativeFramesTracking: true,
integrations: [nativeFramesIntegration()],
});
client = new TestClient(options);
setCurrentClient(client);
client.init();
});

it('does not fetch native frames for unsampled spans', () => {
startSpan({ name: 'unsampled transaction', forceTransaction: true }, () => {
// span starts and ends โ€” no work expected
});

expect(NATIVE.fetchNativeFrames).not.toHaveBeenCalled();
});
});
});
Original file line number Diff line number Diff line change
Expand Up @@ -225,4 +225,31 @@ describe('StallTracking', () => {

expect(client.eventQueue[0].measurements).toBeUndefined();
});

it('does not track stalls for unsampled spans', async () => {
getCurrentScope().clear();
getIsolationScope().clear();
getGlobalScope().clear();

const unsampledOptions = getDefaultTestClientOptions({
tracesSampleRate: 0,
enableStallTracking: true,
integrations: [stallTrackingIntegration()],
enableAppStartTracking: false,
});
const unsampledClient = new TestClient(unsampledOptions);
setCurrentClient(unsampledClient);
unsampledClient.init();

startSpan({ name: 'unsampled transaction', forceTransaction: true }, () => {
expensiveOperation();
jest.runOnlyPendingTimers();
});

await unsampledClient.flush();

// Event is either not sent or has no stall measurements
const event = unsampledClient.eventQueue[0];
expect(event?.measurements?.stall_count).toBeUndefined();
});
});
Loading