File tree Expand file tree Collapse file tree 3 files changed +30
-5
lines changed
dev-packages/node-integration-tests/suites/sessions
packages/node/src/integrations/http Expand file tree Collapse file tree 3 files changed +30
-5
lines changed Original file line number Diff line number Diff line change @@ -5,6 +5,12 @@ Sentry.init({
55 dsn :
'https://[email protected] /1337' , 66 release : '1.0' ,
77 transport : loggingTransport ,
8+ integrations : [
9+ Sentry . httpIntegration ( {
10+ // Flush after 2 seconds (to avoid waiting for the default 60s)
11+ sessionFlushingDelayMS : 2_000 ,
12+ } ) ,
13+ ] ,
814} ) ;
915
1016import { startExpressServerAndSendPortToRunner } from '@sentry-internal/node-integration-tests' ;
Original file line number Diff line number Diff line change @@ -59,6 +59,13 @@ type SentryHttpInstrumentationOptions = InstrumentationConfig & {
5959 * Defaults to `true`.
6060 */
6161 trackIncomingRequestsAsSessions ?: boolean ;
62+
63+ /**
64+ * Number of milliseconds until sessions tracked with `trackIncomingRequestsAsSessions` will be flushed as a session aggregate.
65+ *
66+ * Defaults to `60000` (60s).
67+ */
68+ sessionFlushingDelayMS ?: number ;
6269} ;
6370
6471// We only want to capture request bodies up to 1mb.
@@ -212,6 +219,7 @@ export class SentryHttpInstrumentation extends InstrumentationBase<SentryHttpIns
212219 ( [ timestamp , value ] ) => ( {
213220 started : timestamp ,
214221 exited : value . exited ,
222+ errored : value . errored ,
215223 crashed : value . crashed ,
216224 } ) ,
217225 ) ;
@@ -222,10 +230,13 @@ export class SentryHttpInstrumentation extends InstrumentationBase<SentryHttpIns
222230 DEBUG_BUILD && logger . debug ( 'Sending request session aggregate due to client flush' ) ;
223231 flushPendingClientAggregates ( ) ;
224232 } ) ;
225- const timeout = setTimeout ( ( ) => {
226- DEBUG_BUILD && logger . debug ( 'Sending request session aggregate due to flushing schedule' ) ;
227- flushPendingClientAggregates ( ) ;
228- } , 60_000 ) . unref ( ) ;
233+ const timeout = setTimeout (
234+ ( ) => {
235+ DEBUG_BUILD && logger . debug ( 'Sending request session aggregate due to flushing schedule' ) ;
236+ flushPendingClientAggregates ( ) ;
237+ } ,
238+ instrumentation . getConfig ( ) . sessionFlushingDelayMS ?? 60_000 ,
239+ ) . unref ( ) ;
229240 }
230241 }
231242 } ) ;
Original file line number Diff line number Diff line change @@ -38,9 +38,15 @@ interface HttpOptions {
3838 *
3939 * Defaults to `true`.
4040 */
41- // TODO(v9): Remove the note above.
4241 trackIncomingRequestsAsSessions ?: boolean ;
4342
43+ /**
44+ * Number of milliseconds until sessions tracked with `trackIncomingRequestsAsSessions` will be flushed as a session aggregate.
45+ *
46+ * Defaults to `60000` (60s).
47+ */
48+ sessionFlushingDelayMS ?: number ;
49+
4450 /**
4551 * Do not capture spans or breadcrumbs for outgoing HTTP requests to URLs where the given callback returns `true`.
4652 * This controls both span & breadcrumb creation - spans will be non recording if tracing is disabled.
@@ -95,11 +101,13 @@ const instrumentSentryHttp = generateInstrumentOnce<{
95101 breadcrumbs ?: HttpOptions [ 'breadcrumbs' ] ;
96102 ignoreOutgoingRequests ?: HttpOptions [ 'ignoreOutgoingRequests' ] ;
97103 trackIncomingRequestsAsSessions ?: HttpOptions [ 'trackIncomingRequestsAsSessions' ] ;
104+ sessionFlushingDelayMS ?: HttpOptions [ 'sessionFlushingDelayMS' ] ;
98105} > ( `${ INTEGRATION_NAME } .sentry` , options => {
99106 return new SentryHttpInstrumentation ( {
100107 breadcrumbs : options ?. breadcrumbs ,
101108 ignoreOutgoingRequests : options ?. ignoreOutgoingRequests ,
102109 trackIncomingRequestsAsSessions : options ?. trackIncomingRequestsAsSessions ,
110+ sessionFlushingDelayMS : options ?. sessionFlushingDelayMS ,
103111 } ) ;
104112} ) ;
105113
You can’t perform that action at this time.
0 commit comments