Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix(tracing-internal): Only collect request/response spans when browser performance timing is available #10207

Merged
merged 3 commits into from
Jan 17, 2024
Merged
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
34 changes: 20 additions & 14 deletions packages/tracing-internal/src/browser/metrics/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -369,21 +369,27 @@ function _addPerformanceNavigationTiming(
/** Create request and response related spans */
// eslint-disable-next-line @typescript-eslint/no-explicit-any
function _addRequest(transaction: Transaction, entry: Record<string, any>, timeOrigin: number): void {
_startChild(transaction, {
op: 'browser',
origin: 'auto.browser.browser.metrics',
description: 'request',
startTimestamp: timeOrigin + msToSec(entry.requestStart as number),
endTimestamp: timeOrigin + msToSec(entry.responseEnd as number),
});
// It is possible that we are collecting these metrics when the page hasn't finished loading yet, for example when the HTML slowly streams in.
// In this case, ie. when the document request hasn't finished yet, `entry.responseEnd` will be 0.
// In order not to produce faulty spans, where the end timestamp is before the start timestamp, we will only collect
// these spans when the responseEnd value is available. Relay would drop the entire transaction if it contained faulty spans.
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
// these spans when the responseEnd value is available. Relay would drop the entire transaction if it contained faulty spans.
// these spans when the responseEnd value is available. The backend would drop the entire transaction if it contained faulty spans.

Maybe a bit more generic, for outside readers :)

if (entry.responseEnd !== 0) {
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
if (entry.responseEnd !== 0) {
if (entry.responseEnd) {

save a few bytes and should be equally correct here?

_startChild(transaction, {
op: 'browser',
origin: 'auto.browser.browser.metrics',
description: 'request',
startTimestamp: timeOrigin + msToSec(entry.requestStart as number),
endTimestamp: timeOrigin + msToSec(entry.responseEnd as number),
});

_startChild(transaction, {
op: 'browser',
origin: 'auto.browser.browser.metrics',
description: 'response',
startTimestamp: timeOrigin + msToSec(entry.responseStart as number),
endTimestamp: timeOrigin + msToSec(entry.responseEnd as number),
});
_startChild(transaction, {
op: 'browser',
origin: 'auto.browser.browser.metrics',
description: 'response',
startTimestamp: timeOrigin + msToSec(entry.responseStart as number),
endTimestamp: timeOrigin + msToSec(entry.responseEnd as number),
});
}
}

export interface ResourceEntry extends Record<string, unknown> {
Expand Down