@@ -100,24 +100,48 @@ describe('Server init()', () => {
100100 expect ( onUncaughtExceptionIntegration ) . toBeDefined ( ) ;
101101 } ) ;
102102
103- it ( 'adds the `use cache` integration when tracing is enabled' , ( ) => {
104- init ( { tracesSampleRate : 1 } ) ;
103+ describe ( '`use cache` integration' , ( ) => {
104+ const CACHE_HANDLERS_INSTRUMENTED = Symbol . for ( 'sentry.nextjs.cacheHandlersInstrumented' ) ;
105+ const DSN = 'https://public@dsn.ingest.sentry.io/1337' ;
105106
106- expect ( nodeInit ) . toHaveBeenLastCalledWith (
107- expect . objectContaining ( {
108- defaultIntegrations : expect . arrayContaining ( [ expect . objectContaining ( { name : 'NextjsUseCache' } ) ] ) ,
109- } ) ,
110- ) ;
111- } ) ;
107+ function isUseCacheInstrumented ( ) : boolean {
108+ return ( globalThis as Record < symbol , unknown > ) [ CACHE_HANDLERS_INSTRUMENTED ] === true ;
109+ }
112110
113- it ( 'does not add the `use cache` integration when tracing is disabled' , ( ) => {
114- init ( { } ) ;
111+ afterEach ( ( ) => {
112+ vi . unstubAllEnvs ( ) ;
113+ Reflect . deleteProperty ( globalThis , CACHE_HANDLERS_INSTRUMENTED ) ;
114+ } ) ;
115115
116- expect ( nodeInit ) . toHaveBeenLastCalledWith (
117- expect . objectContaining ( {
118- defaultIntegrations : expect . not . arrayContaining ( [ expect . objectContaining ( { name : 'NextjsUseCache' } ) ] ) ,
119- } ) ,
120- ) ;
116+ it ( 'adds the integration to the default integrations' , ( ) => {
117+ init ( { } ) ;
118+
119+ expect ( nodeInit ) . toHaveBeenLastCalledWith (
120+ expect . objectContaining ( {
121+ defaultIntegrations : expect . arrayContaining ( [ expect . objectContaining ( { name : 'NextjsUseCache' } ) ] ) ,
122+ } ) ,
123+ ) ;
124+ } ) ;
125+
126+ it ( 'instruments the cache handlers when tracing is enabled' , ( ) => {
127+ init ( { dsn : DSN , tracesSampleRate : 1 } ) ;
128+
129+ expect ( isUseCacheInstrumented ( ) ) . toBe ( true ) ;
130+ } ) ;
131+
132+ it ( 'instruments the cache handlers when tracing is enabled via `SENTRY_TRACES_SAMPLE_RATE`' , ( ) => {
133+ vi . stubEnv ( 'SENTRY_TRACES_SAMPLE_RATE' , '1' ) ;
134+
135+ init ( { dsn : DSN } ) ;
136+
137+ expect ( isUseCacheInstrumented ( ) ) . toBe ( true ) ;
138+ } ) ;
139+
140+ it ( 'does not instrument the cache handlers when tracing is disabled' , ( ) => {
141+ init ( { dsn : DSN } ) ;
142+
143+ expect ( isUseCacheInstrumented ( ) ) . toBe ( false ) ;
144+ } ) ;
121145 } ) ;
122146
123147 it ( 'supports passing unrelated integrations through options' , ( ) => {
0 commit comments