-
-
Notifications
You must be signed in to change notification settings - Fork 338
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
fix(stalls): Missing measurements when using new .end() span API (#3737)
- Loading branch information
1 parent
5a22220
commit 5ce5307
Showing
9 changed files
with
371 additions
and
517 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -13,6 +13,8 @@ import { resolvedSyncPromise } from '@sentry/utils'; | |
|
||
export function getDefaultTestClientOptions(options: Partial<TestClientOptions> = {}): TestClientOptions { | ||
return { | ||
dsn: 'https://[email protected]/4505526893805568', | ||
enabled: true, | ||
integrations: [], | ||
sendClientReports: true, | ||
transport: () => | ||
|
@@ -39,6 +41,7 @@ export class TestClient extends BaseClient<TestClientOptions> { | |
public static sendEventCalled?: (event: Event) => void; | ||
|
||
public event?: Event; | ||
public eventQueue: Array<Event> = []; | ||
public hint?: EventHint; | ||
public session?: Session; | ||
|
||
|
@@ -74,6 +77,7 @@ export class TestClient extends BaseClient<TestClientOptions> { | |
|
||
public sendEvent(event: Event, hint?: EventHint): void { | ||
this.event = event; | ||
this.eventQueue.push(event); | ||
this.hint = hint; | ||
|
||
// In real life, this will get deleted as part of envelope creation. | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,69 @@ | ||
import { | ||
addGlobalEventProcessor, | ||
getCurrentHub, | ||
getCurrentScope, | ||
getGlobalScope, | ||
getIsolationScope, | ||
setCurrentClient, | ||
startSpanManual, | ||
} from '@sentry/core'; | ||
|
||
import { ReactNativeTracing, ReactNavigationInstrumentation } from '../../src/js'; | ||
import { _addTracingExtensions } from '../../src/js/tracing/addTracingExtensions'; | ||
import { RN_GLOBAL_OBJ } from '../../src/js/utils/worldwide'; | ||
import { getDefaultTestClientOptions, TestClient } from '../mocks/client'; | ||
import { createMockNavigationAndAttachTo } from './reactnavigationutils'; | ||
import { expectStallMeasurements } from './stalltrackingutils'; | ||
|
||
jest.useFakeTimers({ advanceTimers: true }); | ||
|
||
describe('StallTracking with ReactNavigation', () => { | ||
let client: TestClient; | ||
let mockNavigation: ReturnType<typeof createMockNavigationAndAttachTo>; | ||
|
||
beforeEach(() => { | ||
RN_GLOBAL_OBJ.__sentry_rn_v5_registered = false; | ||
_addTracingExtensions(); | ||
|
||
getCurrentScope().clear(); | ||
getIsolationScope().clear(); | ||
getGlobalScope().clear(); | ||
|
||
const rnavigation = new ReactNavigationInstrumentation(); | ||
mockNavigation = createMockNavigationAndAttachTo(rnavigation); | ||
|
||
const rnTracing = new ReactNativeTracing({ | ||
routingInstrumentation: rnavigation, | ||
enableStallTracking: true, | ||
enableNativeFramesTracking: false, | ||
enableAppStartTracking: false, | ||
}); | ||
|
||
const options = getDefaultTestClientOptions({ | ||
tracesSampleRate: 1.0, | ||
integrations: [rnTracing], | ||
}); | ||
client = new TestClient(options); | ||
setCurrentClient(client); | ||
client.init(); | ||
|
||
// We have to call this manually as setupOnce is executed once per runtime (global var check) | ||
rnTracing.setupOnce(addGlobalEventProcessor, getCurrentHub); | ||
}); | ||
|
||
afterEach(() => { | ||
jest.clearAllMocks(); | ||
}); | ||
|
||
it('Stall tracking supports idleTransaction with unfinished spans', async () => { | ||
jest.runOnlyPendingTimers(); // Flush app start transaction | ||
mockNavigation.navigateToNewScreen(); | ||
startSpanManual({ name: 'This child span will never finish' }, () => {}); | ||
|
||
jest.runOnlyPendingTimers(); // Flush new screen transaction | ||
|
||
await client.flush(); | ||
|
||
expectStallMeasurements(client.event?.measurements); | ||
}); | ||
}); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,67 @@ | ||
import type { NavigationRoute, ReactNavigationInstrumentation } from '../../src/js/tracing/reactnavigation'; | ||
|
||
export function createMockNavigationAndAttachTo(sut: ReactNavigationInstrumentation) { | ||
const mockedNavigationContained = mockNavigationContainer(); | ||
const mockedNavigation = { | ||
navigateToNewScreen: () => { | ||
mockedNavigationContained.listeners['__unsafe_action__']({ | ||
// this object is not used by the instrumentation | ||
}); | ||
mockedNavigationContained.currentRoute = { | ||
key: 'new_screen', | ||
name: 'New Screen', | ||
}; | ||
mockedNavigationContained.listeners['state']({ | ||
// this object is not used by the instrumentation | ||
}); | ||
}, | ||
navigateToInitialScreen: () => { | ||
mockedNavigationContained.listeners['__unsafe_action__']({ | ||
// this object is not used by the instrumentation | ||
}); | ||
mockedNavigationContained.currentRoute = { | ||
key: 'initial_screen', | ||
name: 'Initial Screen', | ||
}; | ||
mockedNavigationContained.listeners['state']({ | ||
// this object is not used by the instrumentation | ||
}); | ||
}, | ||
finishAppStartNavigation: () => { | ||
mockedNavigationContained.currentRoute = { | ||
key: 'initial_screen', | ||
name: 'Initial Screen', | ||
}; | ||
mockedNavigationContained.listeners['state']({ | ||
// this object is not used by the instrumentation | ||
}); | ||
}, | ||
}; | ||
sut.registerNavigationContainer(mockRef(mockedNavigationContained)); | ||
|
||
return mockedNavigation; | ||
} | ||
|
||
function mockRef<T>(wat: T): { current: T } { | ||
return { | ||
current: wat, | ||
}; | ||
} | ||
|
||
function mockNavigationContainer(): MockNavigationContainer { | ||
return new MockNavigationContainer(); | ||
} | ||
|
||
export class MockNavigationContainer { | ||
currentRoute: NavigationRoute = { | ||
key: 'initial_screen', | ||
name: 'Initial Screen', | ||
}; | ||
listeners: Record<string, (e: any) => void> = {}; | ||
addListener: any = jest.fn((eventType: string, listener: (e: any) => void): void => { | ||
this.listeners[eventType] = listener; | ||
}); | ||
getCurrentRoute(): NavigationRoute | undefined { | ||
return this.currentRoute; | ||
} | ||
} |
Oops, something went wrong.