Skip to content

feat[apm]: Add discardBackgroundSpans option #2471

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

Merged
merged 2 commits into from
Mar 4, 2020
Merged

feat[apm]: Add discardBackgroundSpans option #2471

merged 2 commits into from
Mar 4, 2020

Conversation

HazAT
Copy link
Member

@HazAT HazAT commented Mar 4, 2020

This PR discards spans/transactions (also does not add the sentry-trace header for xhr & fetch) if the tab is/gets moved to the background by using the visibility API https://developers.google.com/web/updates/2017/03/background_tabs#optimising_an_application_for_background

Timing in background is off, but the code comment for the option is explaining why it's there.

@HazAT HazAT requested a review from kamilogorek as a code owner March 4, 2020 11:27
@HazAT HazAT self-assigned this Mar 4, 2020
@@ -389,7 +414,7 @@ export class Tracing implements Integration {
* Removes activity and finishes the span in case there is one
*/
public static popActivity(id: number, spanData?: { [key: string]: any }): void {
if (!Tracing._isEnabled()) {
if (!Tracing._isEnabled() || !id) {
Copy link
Contributor

Choose a reason for hiding this comment

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

Suggested change
if (!Tracing._isEnabled() || !id) {
if (!Tracing._isEnabled() || id == null) {

or typeof id === 'undefined' since !0 is truthy.

Copy link
Member Author

Choose a reason for hiding this comment

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

This is on purpose, will add a code comment.

Copy link
Member

Choose a reason for hiding this comment

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

id <= 0 would also work 👍

@@ -202,6 +213,16 @@ export class Tracing implements Integration {
});
}

// tslint:disable-next-line: no-non-null-assertion
if (this._options!.discardBackgroundSpans && global.document) {
Copy link
Contributor

Choose a reason for hiding this comment

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

Why do we have this._options! in the first place? We should allow this._options to be undefined by this point.

@HazAT HazAT changed the title feat: Add discardBackgroundSpans option feat[apm]: Add discardBackgroundSpans option Mar 4, 2020
@HazAT HazAT merged commit e57aeb7 into master Mar 4, 2020
@HazAT HazAT deleted the apm-background branch March 4, 2020 11:51
@@ -114,9 +124,9 @@ export class Tracing implements Integration {

private static _activeTransaction?: Span;

private static _currentIndex: number = 0;
private static _currentIndex: number = 1;
Copy link
Contributor

Choose a reason for hiding this comment

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

Why did this change from 0 to 1?

Copy link
Member

Choose a reason for hiding this comment

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

@rhcarvalho it looks like 0 is a magic constant returned by pushActivity() in certain cases; primarily to indicate that the activity was not pushed.

Comment on lines +415 to +416
// The !id is on purpose to also fail with 0
// Since 0 is returned by push activity in case tracing is not enabled
Copy link
Contributor

Choose a reason for hiding this comment

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

Isn't this case already covered by !Tracing._isEnabled()?

Copy link
Member

Choose a reason for hiding this comment

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

@rhcarvalho there are cases when popActivity() is called within a setTimeout()

Tracing._activeTransaction = undefined;
Tracing._activities = {};
}
});
Copy link
Member

@dashed dashed Mar 4, 2020

Choose a reason for hiding this comment

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

@HazAT Should startIdleTransaction() be called whenever document.hidden === false? e.g. user focuses the tab.

Copy link
Member

Choose a reason for hiding this comment

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

@dashed What would that be measuring? Normally our auto-created transactions are about pageload, but if the page is already loaded, and you just refocus the tab...

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

6 participants