Skip to content

Commit

Permalink
chore: fixing problem with load event and performance for loadend (#469)
Browse files Browse the repository at this point in the history
* 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
  • Loading branch information
obecny authored and mayurkale22 committed Nov 2, 2019
1 parent ae904d5 commit d5141f7
Show file tree
Hide file tree
Showing 2 changed files with 200 additions and 134 deletions.
17 changes: 13 additions & 4 deletions packages/opentelemetry-plugin-document-load/src/documentLoad.ts
Original file line number Diff line number Diff line change
Expand Up @@ -44,7 +44,11 @@ export class DocumentLoad extends BasePlugin<unknown> {
* callback to be executed when page is loaded
*/
private _onDocumentLoaded() {
this._collectPerformance();
// Timeout is needed as load event doesn't have yet the performance metrics for loadEnd.
// Support for event "loadend" is very limited and cannot be used
window.setTimeout(() => {
this._collectPerformance();
});
}

/**
Expand Down Expand Up @@ -125,9 +129,14 @@ export class DocumentLoad extends BasePlugin<unknown> {
entries: PerformanceEntries
) {
// span can be undefined when entries are missing the certain performance - the span will not be created
if (typeof span !== 'undefined' && hasKey(entries, performanceName)) {
this._addSpanEvent(span, performanceName, entries);
span.end(entries[performanceName]);
if (span) {
if (hasKey(entries, performanceName)) {
this._addSpanEvent(span, performanceName, entries);
span.end(entries[performanceName]);
} else {
// just end span
span.end();
}
}
}

Expand Down
Loading

0 comments on commit d5141f7

Please sign in to comment.