-
Notifications
You must be signed in to change notification settings - Fork 837
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(instrumentation-fetch): perf observer bugs #1868
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -32,7 +32,7 @@ import { VERSION } from './version'; | |
// hard to say how long it should really wait, seems like 300ms is | ||
// safe enough | ||
const OBSERVER_WAIT_TIME_MS = 300; | ||
|
||
const urlNormalizingA = document.createElement('a'); | ||
/** | ||
* FetchPlugin Config | ||
*/ | ||
|
@@ -252,11 +252,10 @@ export class FetchInstrumentation extends InstrumentationBase< | |
response: FetchResponse | ||
) { | ||
const endTime = core.hrTime(); | ||
spanData.observer?.disconnect(); | ||
|
||
this._addFinalSpanAttributes(span, response); | ||
|
||
setTimeout(() => { | ||
spanData.observer?.disconnect(); | ||
this._findResourceAndAddNetworkEvents(span, spanData, endTime); | ||
this._tasksCount--; | ||
this._clearResources(); | ||
|
@@ -352,15 +351,18 @@ export class FetchInstrumentation extends InstrumentationBase< | |
private _prepareSpanData(spanUrl: string): SpanData { | ||
const startTime = core.hrTime(); | ||
const entries: PerformanceResourceTiming[] = []; | ||
|
||
if (typeof window.PerformanceObserver === 'undefined') { | ||
return { entries, startTime, spanUrl }; | ||
} | ||
|
||
const observer: PerformanceObserver = new PerformanceObserver(list => { | ||
const entries = list.getEntries() as PerformanceResourceTiming[]; | ||
entries.forEach(entry => { | ||
if (entry.initiatorType === 'fetch' && entry.name === spanUrl) { | ||
const perfObsEntries = list.getEntries() as PerformanceResourceTiming[]; | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Feels like we should have a separate PR to turn on There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. If you think that would avoid more bugs, could you open an issue so someone can handle it at some point ? (i could have opened it but i don't really understand whats shadowing exactly) |
||
urlNormalizingA.href = spanUrl; | ||
perfObsEntries.forEach(entry => { | ||
if ( | ||
entry.initiatorType === 'fetch' && | ||
entry.name === urlNormalizingA.href | ||
) { | ||
entries.push(entry); | ||
} | ||
}); | ||
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This was really subtle; thanks for catching it.