Skip to content

Commit d5141f7

Browse files
obecnymayurkale22
authored andcommitted
chore: fixing problem with load event and performance for loadend (open-telemetry#469)
* chore: fixing problem with load event and performance for loadend * chore: clean up in unit tests * chore: removing delay from timeouts * chore: removing delay from timeout
1 parent ae904d5 commit d5141f7

File tree

2 files changed

+200
-134
lines changed

2 files changed

+200
-134
lines changed

packages/opentelemetry-plugin-document-load/src/documentLoad.ts

+13-4
Original file line numberDiff line numberDiff line change
@@ -44,7 +44,11 @@ export class DocumentLoad extends BasePlugin<unknown> {
4444
* callback to be executed when page is loaded
4545
*/
4646
private _onDocumentLoaded() {
47-
this._collectPerformance();
47+
// Timeout is needed as load event doesn't have yet the performance metrics for loadEnd.
48+
// Support for event "loadend" is very limited and cannot be used
49+
window.setTimeout(() => {
50+
this._collectPerformance();
51+
});
4852
}
4953

5054
/**
@@ -125,9 +129,14 @@ export class DocumentLoad extends BasePlugin<unknown> {
125129
entries: PerformanceEntries
126130
) {
127131
// span can be undefined when entries are missing the certain performance - the span will not be created
128-
if (typeof span !== 'undefined' && hasKey(entries, performanceName)) {
129-
this._addSpanEvent(span, performanceName, entries);
130-
span.end(entries[performanceName]);
132+
if (span) {
133+
if (hasKey(entries, performanceName)) {
134+
this._addSpanEvent(span, performanceName, entries);
135+
span.end(entries[performanceName]);
136+
} else {
137+
// just end span
138+
span.end();
139+
}
131140
}
132141
}
133142

0 commit comments

Comments
 (0)