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

feat(instrumentation-document-load): Add ability to disable span events #2188

Conversation

pkanal
Copy link
Contributor

@pkanal pkanal commented May 9, 2024

Which problem is this PR solving?

Adds the option to turn off sending span events generated by the document load instrumentation.

This is useful because this instrumentation can generate 8-10 span events per span which can become noisy. There is precedent for this API in the instrumentation-fetch and instrumentation-xml-http packages so I decided to keep it consistent with that API.

Short description of the changes

  • Added a ignoreNetworkEvents optional option. If set to true, does not send network span events on any spans.
  • Added a ignorePerformanceEvents optional option. If set to true, does not send performance events span events.

Open questions

  • Should these be configurable per type of span? (e.g. have the ability to turn off network spans only for documentLoad events but not resourceFetch events)

Copy link

codecov bot commented May 9, 2024

Codecov Report

All modified and coverable lines are covered by tests ✅

Project coverage is 90.38%. Comparing base (dfb2dff) to head (8b6d9db).
Report is 145 commits behind head on main.

Additional details and impacted files
@@            Coverage Diff             @@
##             main    #2188      +/-   ##
==========================================
- Coverage   90.97%   90.38%   -0.60%     
==========================================
  Files         146      148       +2     
  Lines        7492     7509      +17     
  Branches     1502     1573      +71     
==========================================
- Hits         6816     6787      -29     
- Misses        676      722      +46     

see 45 files with indirect coverage changes

@pkanal pkanal marked this pull request as ready for review May 15, 2024 15:09
@pkanal pkanal requested a review from a team as a code owner May 15, 2024 15:09
Copy link
Member

@blumamir blumamir left a comment

Choose a reason for hiding this comment

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

LGTM, added one minor comment about documentation of the new options

I am not sure how a real span looks like and if it can be helpful to enumarte the events that might be recorded/ignored by each option, thus helping users decide if they want each one on or off. But this can also be addressed separately later if there is motivation.

Comment on lines 38 to 39
ignoreNetworkEvents?: boolean;
ignorePerformanceEvents?: boolean;
Copy link
Member

Choose a reason for hiding this comment

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

Please add a section in this package README.md to document these options for package users, like the one for applyCustomAttributesOnSpan We can also include a comment here to help users understand what each option does and when and why to use it. Similar to the comment few lines above the applyCustomAttributesOnSpan?: option.

Copy link

Choose a reason for hiding this comment

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

I think the names are misleading, as both are provided by Performance API. Ideally they should be called ignorePerformanceNavigationEvents and ignorePerformancePaintEvents. Since the name ignoreNetworkEvents has been already used in xhr and fetch instrumentation configs, I suggest changing at least the latter.

Comment on lines 38 to 39
ignoreNetworkEvents?: boolean;
ignorePerformanceEvents?: boolean;
Copy link

Choose a reason for hiding this comment

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

I think the names are misleading, as both are provided by Performance API. Ideally they should be called ignorePerformanceNavigationEvents and ignorePerformancePaintEvents. Since the name ignoreNetworkEvents has been already used in xhr and fetch instrumentation configs, I suggest changing at least the latter.


if (!this._getConfig().ignorePerformanceEvents) {
addSpanPerformancePaintEvents(rootSpan);
}
Copy link

Choose a reason for hiding this comment

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

There is a way to do better and avoid calling the Performance API altogether. The function getPerformanceNavigationEntries and in utils.js could return an empty entries map when this flag is turned off.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

I think doing it this way makes it very explicit in the code where this option is being used which is why I would prefer to do it this way. This function will not get called if ignorePerformanceEventsis set to true so the Performance API won't be called this way either.

Copy link

Choose a reason for hiding this comment

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

Copy link
Contributor Author

Choose a reason for hiding this comment

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

It looks like the entries variable is actively used by the _startSpan function to determine the start time so I'm inclined to leave this as is.

@JamieDanielson
Copy link
Member

It looks like the changes suggested have been implemented. @pkanal is there anything else you wanted to add here? If not I think this is good to go 🚀

@pkanal pkanal requested a review from scheler May 30, 2024 17:33
@pkanal pkanal merged commit 50ff98b into open-telemetry:main May 30, 2024
19 checks passed
@pkanal pkanal deleted the feat/user-interaction-instrumentation-span-events branch May 30, 2024 18:30
@dyladan dyladan mentioned this pull request May 30, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

7 participants