@@ -3,15 +3,15 @@ import { browserProfilingIntegration } from '@sentry/browser';
33
44window . Sentry = Sentry ;
55
6- Sentry . init ( {
6+ const client = Sentry . init ( {
77 dsn : 'https://public@dsn.ingest.sentry.io/1337' ,
88 integrations : [ browserProfilingIntegration ( ) ] ,
99 tracesSampleRate : 1 ,
1010 profileSessionSampleRate : 1 ,
1111 profileLifecycle : 'trace' ,
1212} ) ;
1313
14- function largeSum ( amount = 1000000 ) {
14+ function largeSum ( amount ) {
1515 let sum = 0 ;
1616 for ( let i = 0 ; i < amount ; i ++ ) {
1717 sum += Math . sqrt ( i ) * Math . sin ( i ) ;
@@ -28,7 +28,8 @@ function fibonacci(n) {
2828let firstSpan ;
2929
3030Sentry . startSpanManual ( { name : 'root-largeSum-1' , parentSpan : null , forceTransaction : true } , span => {
31- largeSum ( ) ;
31+ // Enough iterations that largeSum stays on-stack across several profiler ticks (10ms interval); otherwise sampling can miss it entirely.
32+ largeSum ( 2_500_000 ) ;
3233 firstSpan = span ;
3334} ) ;
3435
@@ -39,14 +40,13 @@ await Sentry.startSpanManual({ name: 'root-fibonacci-2', parentSpan: null, force
3940 console . log ( 'child span' ) ;
4041 } ) ;
4142
42- // Timeout to prevent flaky tests. Integration samples every 20ms, if function is too fast it might not get sampled
43- await new Promise ( resolve => setTimeout ( resolve , 21 ) ) ;
43+ // Profiler uses a 10ms sample interval — wait long enough for multiple ticks
44+ await new Promise ( resolve => setTimeout ( resolve , 40 ) ) ;
4445 span . end ( ) ;
4546} ) ;
4647
47- await new Promise ( r => setTimeout ( r , 21 ) ) ;
48+ await new Promise ( r => setTimeout ( r , 40 ) ) ;
4849
4950firstSpan . end ( ) ;
5051
51- const client = Sentry . getClient ( ) ;
5252await client ?. flush ( 5000 ) ;
0 commit comments