|
1 | | -import { EventProcessor, Hub, Integration, Span, SpanContext, SpanStatus } from '@sentry/types'; |
| 1 | +import { Event, EventProcessor, Hub, Integration, Span, SpanContext, SpanStatus } from '@sentry/types'; |
2 | 2 | import { |
3 | 3 | addInstrumentationHandler, |
4 | 4 | getGlobalObject, |
@@ -67,9 +67,10 @@ interface TracingOptions { |
67 | 67 | /** |
68 | 68 | * The maximum time a transaction can be before it will be dropped. This is for some edge cases where a browser |
69 | 69 | * completely freezes the JS state and picks it up later. So after this timeout, the SDK will not send the event. |
| 70 | + * If you want to have an unlimited timeout set it to 0. |
70 | 71 | * Time is in ms. |
71 | 72 | * |
72 | | - * Default: 120000 |
| 73 | + * Default: 600000 = 10min |
73 | 74 | */ |
74 | 75 | maxTransactionTimeout: number; |
75 | 76 | } |
@@ -126,7 +127,7 @@ export class Tracing implements Integration { |
126 | 127 | const defaultTracingOrigins = ['localhost', /^\//]; |
127 | 128 | const defaults = { |
128 | 129 | idleTimeout: 500, |
129 | | - maxTransactionTimeout: 120000, |
| 130 | + maxTransactionTimeout: 600000, |
130 | 131 | shouldCreateSpanForRequest(url: string): boolean { |
131 | 132 | const origins = (_options && _options.tracingOrigins) || defaultTracingOrigins; |
132 | 133 | return ( |
@@ -155,7 +156,7 @@ export class Tracing implements Integration { |
155 | 156 | /** |
156 | 157 | * @inheritDoc |
157 | 158 | */ |
158 | | - public setupOnce(_: (callback: EventProcessor) => void, getCurrentHub: () => Hub): void { |
| 159 | + public setupOnce(addGlobalEventProcessor: (callback: EventProcessor) => void, getCurrentHub: () => Hub): void { |
159 | 160 | Tracing._getCurrentHub = getCurrentHub; |
160 | 161 |
|
161 | 162 | if (!Tracing._isEnabled()) { |
@@ -192,6 +193,25 @@ export class Tracing implements Integration { |
192 | 193 | sampled: true, |
193 | 194 | }); |
194 | 195 | } |
| 196 | + |
| 197 | + // This EventProcessor makes sure that we never send an transaction that is older than maxTransactionTimeout |
| 198 | + addGlobalEventProcessor((event: Event) => { |
| 199 | + const self = getCurrentHub().getIntegration(Tracing); |
| 200 | + if (!self) { |
| 201 | + return event; |
| 202 | + } |
| 203 | + |
| 204 | + if ( |
| 205 | + event.type === 'transaction' && |
| 206 | + event.timestamp && |
| 207 | + Tracing.options.maxTransactionTimeout !== 0 && |
| 208 | + timestampWithMs() > event.timestamp + Tracing.options.maxTransactionTimeout |
| 209 | + ) { |
| 210 | + return null; |
| 211 | + } |
| 212 | + |
| 213 | + return event; |
| 214 | + }); |
195 | 215 | } |
196 | 216 |
|
197 | 217 | /** |
@@ -282,7 +302,10 @@ export class Tracing implements Integration { |
282 | 302 | public static finishIdleTransaction(): void { |
283 | 303 | const active = Tracing._activeTransaction as SpanClass; |
284 | 304 | if (active) { |
285 | | - if (timestampWithMs() > active.startTimestamp + Tracing.options.maxTransactionTimeout) { |
| 305 | + if ( |
| 306 | + Tracing.options.maxTransactionTimeout !== 0 && |
| 307 | + timestampWithMs() > active.startTimestamp + Tracing.options.maxTransactionTimeout |
| 308 | + ) { |
286 | 309 | // If we reached the max timeout of the transaction, we will just not finish it and therefore discard it. |
287 | 310 | Tracing._activeTransaction = undefined; |
288 | 311 | } else { |
|
0 commit comments