Skip to content

Commit c4198d3

Browse files
committed
PR feedback
1 parent 1ac4159 commit c4198d3

File tree

2 files changed

+21
-12
lines changed

2 files changed

+21
-12
lines changed

packages/core/src/tracing/idleSpan.ts

Lines changed: 17 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -113,12 +113,25 @@ export function startIdleSpan(startSpanOptions: StartSpanOptions, options: Parti
113113
// Ensure we end with the last span timestamp, if possible
114114
const spans = getSpanDescendants(span).filter(child => child !== span);
115115

116-
const latestEndTimestamp = spans.length ? Math.max(...spans.map(span => spanToJSON(span).timestamp || 0)) : 0;
116+
// If we have no spans, we just end, nothing else to do here
117+
if (!spans.length) {
118+
span.end(timestamp);
119+
return;
120+
}
121+
122+
const latestEndTimestamp = Math.max(...spans.map(span => spanToJSON(span).timestamp || 0));
123+
124+
if (latestEndTimestamp <= 0) {
125+
span.end(timestamp);
126+
return;
127+
}
117128

118129
// If the timestamp is smaller than the latest end timestamp of a span, we still want to use it
119-
const endTimestamp = latestEndTimestamp
120-
? Math.min(spanTimeInputToSeconds(timestamp), latestEndTimestamp)
121-
: timestamp;
130+
// Need to convert the timestamp to seconds to ensure Math.min() works as expected
131+
// Note that other than this, we can just pass the timestamp as-is to `span.end()`
132+
// because that will convert to seconds internally anyhow
133+
const spanEndTimestamp = spanTimeInputToSeconds(timestamp);
134+
const endTimestamp = Math.min(spanEndTimestamp, latestEndTimestamp);
122135

123136
span.end(endTimestamp);
124137
}

packages/tracing-internal/src/browser/browserTracingIntegration.ts

Lines changed: 4 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -36,23 +36,23 @@ export interface BrowserTracingOptions {
3636
* The time that has to pass without any span being created.
3737
* If this time is exceeded, the idle span will finish.
3838
*
39-
* Default: 1000ms
39+
* Default: 1000 (ms)
4040
*/
4141
idleTimeout: number;
4242

4343
/**
4444
* The max. time an idle span may run.
4545
* If this time is exceeded, the idle span will finish no matter what.
4646
*
47-
* Default: 30000ms
47+
* Default: 30000 (ms)
4848
*/
4949
finalTimeout: number;
5050

5151
/**
5252
The max. time an idle span may run.
5353
* If this time is exceeded, the idle span will finish no matter what.
5454
*
55-
* Default: 15000ms
55+
* Default: 15000 (ms)
5656
*/
5757
childSpanTimeout: number;
5858

@@ -185,7 +185,7 @@ export const browserTracingIntegration = ((_options: Partial<BrowserTracingOptio
185185
let latestRouteSource: TransactionSource | undefined;
186186

187187
/** Create routing idle transaction. */
188-
function _createRouteSpan(client: Client, startSpanOptions: StartSpanOptions): Span | undefined {
188+
function _createRouteSpan(client: Client, startSpanOptions: StartSpanOptions): Span {
189189
const { beforeStartSpan, idleTimeout, finalTimeout, childSpanTimeout } = options;
190190

191191
const isPageloadTransaction = startSpanOptions.op === 'pageload';
@@ -219,10 +219,6 @@ export const browserTracingIntegration = ((_options: Partial<BrowserTracingOptio
219219
},
220220
});
221221

222-
if (!idleSpan) {
223-
return;
224-
}
225-
226222
if (isPageloadTransaction && WINDOW.document) {
227223
WINDOW.document.addEventListener('readystatechange', () => {
228224
if (['interactive', 'complete'].includes(WINDOW.document.readyState)) {

0 commit comments

Comments
 (0)