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

chore: fixing problem with load event and performance for loadend #469

Merged
merged 6 commits into from
Nov 2, 2019
Merged
Show file tree
Hide file tree
Changes from 3 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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();
}, 1);
obecny marked this conversation as resolved.
Show resolved Hide resolved
}

/**
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 (typeof span !== 'undefined') {
obecny marked this conversation as resolved.
Show resolved Hide resolved
if (hasKey(entries, performanceName)) {
this._addSpanEvent(span, performanceName, entries);
span.end(entries[performanceName]);
} else {
// just end span
span.end();
}
}
}

Expand Down
Loading