1
+ /* eslint-disable max-lines */
1
2
import {
2
3
SENTRY_XHR_DATA_KEY ,
3
4
addPerformanceInstrumentationHandler ,
@@ -76,7 +77,16 @@ export interface RequestInstrumentationOptions {
76
77
*
77
78
* Default: true
78
79
*/
79
- traceXHR : boolean ;
80
+ traceXHR : boolean /**
81
+ * Flag to disable tracking of long-lived streams, like server-sent events (SSE) via fetch.
82
+ * Do not enable this in case you have live streams or very long running streams.
83
+ *
84
+ * Disabled by default since it can lead to issues with streams using the `cancel()` api
85
+ * (https://github.com/getsentry/sentry-javascript/issues/13950)
86
+ *
87
+ * Default: false
88
+ */ ;
89
+ trackFetchStreamPerformance : boolean ;
80
90
81
91
/**
82
92
* If true, Sentry will capture http timings and add them to the corresponding http spans.
@@ -101,13 +111,22 @@ export const defaultRequestInstrumentationOptions: RequestInstrumentationOptions
101
111
traceFetch : true ,
102
112
traceXHR : true ,
103
113
enableHTTPTimings : true ,
114
+ trackFetchStreamPerformance : false ,
104
115
} ;
105
116
106
117
/** Registers span creators for xhr and fetch requests */
107
118
export function instrumentOutgoingRequests ( client : Client , _options ?: Partial < RequestInstrumentationOptions > ) : void {
108
- const { traceFetch, traceXHR, shouldCreateSpanForRequest, enableHTTPTimings, tracePropagationTargets } = {
119
+ const {
120
+ traceFetch,
121
+ traceXHR,
122
+ trackFetchStreamPerformance,
123
+ shouldCreateSpanForRequest,
124
+ enableHTTPTimings,
125
+ tracePropagationTargets,
126
+ } = {
109
127
traceFetch : defaultRequestInstrumentationOptions . traceFetch ,
110
128
traceXHR : defaultRequestInstrumentationOptions . traceXHR ,
129
+ trackFetchStreamPerformance : defaultRequestInstrumentationOptions . trackFetchStreamPerformance ,
111
130
..._options ,
112
131
} ;
113
132
@@ -136,14 +155,16 @@ export function instrumentOutgoingRequests(client: Client, _options?: Partial<Re
136
155
return event ;
137
156
} ) ;
138
157
139
- addFetchEndInstrumentationHandler ( handlerData => {
140
- if ( handlerData . response ) {
141
- const span = responseToSpanId . get ( handlerData . response ) ;
142
- if ( span && handlerData . endTimestamp ) {
143
- spanIdToEndTimestamp . set ( span , handlerData . endTimestamp ) ;
158
+ if ( trackFetchStreamPerformance ) {
159
+ addFetchEndInstrumentationHandler ( handlerData => {
160
+ if ( handlerData . response ) {
161
+ const span = responseToSpanId . get ( handlerData . response ) ;
162
+ if ( span && handlerData . endTimestamp ) {
163
+ spanIdToEndTimestamp . set ( span , handlerData . endTimestamp ) ;
164
+ }
144
165
}
145
- }
146
- } ) ;
166
+ } ) ;
167
+ }
147
168
148
169
addFetchInstrumentationHandler ( handlerData => {
149
170
const createdSpan = instrumentFetchRequest ( handlerData , shouldCreateSpan , shouldAttachHeadersWithTargets , spans ) ;
0 commit comments