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 5 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();
});
Copy link
Contributor

Choose a reason for hiding this comment

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

Would it make sense to have a little delay here, e.g. 1 second or so?

Copy link
Member Author

Choose a reason for hiding this comment

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

if I understand correctly it should work like this. When load event is being called then the performance is collecting the remaining metrics included "loadEnd", I assume this is synchronous so whenever this is finished the browser will start executing all the timeouts that were set together with the same load event. Then it really doesn't make sense to wait longer as the loadEnd metric should be there. If this is not the case then it will be hard to really say how long you should wait, 100ms, 1s, maybe 2s, but it seems like the moment the setTimeout calls the callback this metric is already there.

Copy link
Member Author

Choose a reason for hiding this comment

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

In the end this is not final, we can always put there 1s at any moment if for any reason it appeared that some browsers don't have it yet.

}

/**
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