Skip to content

Conversation

@Abinet18
Copy link
Contributor

Part of the client sdk project, Implement PageView event instrumentation
#2372

This PR adds the page view instrumentation which sends an event when a page is loaded (as soon as the html is loaded) or when a route change happens (tracking the history push and replace states)

Tested on an example app with generic routes that use the history api

@Abinet18 Abinet18 requested a review from a team August 16, 2024 21:04
@Abinet18 Abinet18 changed the title Add page view instrumentation plugin feat: Add page view instrumentation plugin Aug 19, 2024
@codecov
Copy link

codecov bot commented Aug 19, 2024

Codecov Report

All modified and coverable lines are covered by tests ✅

Project coverage is 90.74%. Comparing base (b043ffb) to head (562bca8).
Report is 220 commits behind head on main.

Additional details and impacted files
@@           Coverage Diff           @@
##             main    open-telemetry/opentelemetry-js-contrib#2386   +/-   ##
=======================================
  Coverage   90.74%   90.74%           
=======================================
  Files         156      156           
  Lines        7728     7728           
  Branches     1590     1590           
=======================================
  Hits         7013     7013           
  Misses        715      715           
🚀 New features to boost your workflow:
  • ❄️ Test Analytics: Detect flaky tests, report on failures, and find test suite problems.
  • 📦 JS Bundle Analysis: Save yourself from yourself by tracking and limiting bundle sizes in JS merges.

Copy link
Contributor

@martinkuba martinkuba left a comment

Choose a reason for hiding this comment

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

Couple small changes, but overall looks good. Failing tests need to be fixed.

@Abinet18 Abinet18 force-pushed the feat/add-page-view-instrumentation branch from 57ab371 to 3c980fa Compare August 27, 2024 17:30
@Abinet18 Abinet18 requested a review from martinkuba August 27, 2024 17:57
@Abinet18 Abinet18 requested a review from a team as a code owner October 8, 2024 17:42
@Abinet18 Abinet18 force-pushed the feat/add-page-view-instrumentation branch from bee412c to e204c33 Compare October 8, 2024 18:13
@martinkuba
Copy link
Contributor

@Abinet18 I have approved the PR, but forgot to mention that also these files should be updated:

  • .github/component-label-map.yml
  • .github/component_owners.yml

@Abinet18
Copy link
Contributor Author

@martinkuba , when can this be merged. I would fix the conflict just before the merge time so that I don't have to do it every time the main branch changes

* executes callback {_onDOMContentLoaded } when the page is viewed
*/
private _waitForPageLoad() {
document.addEventListener('DOMContentLoaded', this._onPageView.bind(this));
Copy link

@williazz williazz Jan 28, 2025

Choose a reason for hiding this comment

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

Suggestion: it might make sense to use a buffered PerformanceObserver to listen for PerformanceNavigationTimings, insead of DOMEventListener for DOMContentLoaded. I have seen users be unable to find their PageViews because eventListener needs registered at runtime before DOMContentLoaded in order to scrape any data. This problem will also be worse for those have want to install this package via CDN

/**
* callback to be executed when using hard navigation
*/
private _onPageView() {
Copy link

@williazz williazz Feb 4, 2025

Choose a reason for hiding this comment

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

Issue: can we also teardown the event listener for DomContentLoaded? I believe it only happens once, so there's no need for it anymore.

@dyladan
Copy link
Member

dyladan commented May 14, 2025

I'm sorry I think we just dropped the ball on this. If you fix the conflicts I can get this merged

@david-luna
Copy link
Contributor

@Abinet18 @martinkuba

Semantic conventions for this instrumentation are not available yet open-telemetry/semantic-conventions#1910 and one of the goals of the new Browser SIG is to have an implementation of this and other instrumentations optimised for browser.

should we put this on hold? or should we continue with the possible breaking changes that will come with the optimization?

Copy link
Member

@dyladan dyladan left a comment

Choose a reason for hiding this comment

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

Can you please address #2386 (comment)

If you want to move forward with this anyway, I will dismiss this review.

@Abinet18
Copy link
Contributor Author

@Abinet18 @martinkuba

Semantic conventions for this instrumentation are not available yet open-telemetry/semantic-conventions#1910 and one of the goals of the new Browser SIG is to have an implementation of this and other instrumentations optimised for browser.

should we put this on hold? or should we continue with the possible breaking changes that will come with the optimization?

I am ok with putting it on hold for now but just wanted to work on migrating to logs

@trentm trentm added the Target: Browser Targets on Browser label Jul 30, 2025
@pichlermarc
Copy link
Member

@Abinet18 - we discussed this in the SIG today, and we'd prefer if new instrumentation targeting the browser would go hand-in-hand with efforts to add semantic conventions for this as well. Is that something that you'd be interested in contributing to?

@martinkuba
Copy link
Contributor

martinkuba commented Aug 1, 2025

@Abinet18 - we discussed this in the SIG today, and we'd prefer if new instrumentation targeting the browser would go hand-in-hand with efforts to add semantic conventions for this as well. Is that something that you'd be interested in contributing to?

@pichlermarc There is already a corresponding semconv PR here
open-telemetry/semantic-conventions#1910

@dyladan
Copy link
Member

dyladan commented Aug 6, 2025

@martinkuba so i guess this is a prototype for that semconv? Would you want to merge this as development, experimental, unreleased, or some other status?

@dyladan dyladan self-requested a review August 6, 2025 16:25
@martinkuba
Copy link
Contributor

@martinkuba so i guess this is a prototype for that semconv? Would you want to merge this as development, experimental, unreleased, or some other status?

@dyladan I am not sure about the advantage merging this as development. If we want to merge this before the semconv is merged, I guess this would be unreleased/development? But once the semconv discussion is finished and merged, then IMO this could be experimental and published for others to try.

@dyladan
Copy link
Member

dyladan commented Aug 7, 2025

@martinkuba so i guess this is a prototype for that semconv? Would you want to merge this as development, experimental, unreleased, or some other status?

@dyladan I am not sure about the advantage merging this as development. If we want to merge this before the semconv is merged, I guess this would be unreleased/development? But once the semconv discussion is finished and merged, then IMO this could be experimental and published for others to try.

I guess it depends if you want it released or not. As a prototype it provides some value without being merged (shows what attributes can be collected and how), but until it is merged and released it is very difficult for end-users to test it and make sure it works for their use cases. With the appropriate disclaimer I think it could be merged and released, but not included in auto-instrumentations (require users to manually install and enable it), which would make it easier for users to provide feedback to the semconv. I'm asking if you think this is required/helpful for semconv or no.

@martinkuba
Copy link
Contributor

I'm asking if you think this is required/helpful for semconv or no.

Yes, I think this is helpful to get feedback from users on the semantic conventions. I am in favor of releasing this as experimental.

@Abinet18 Abinet18 force-pushed the feat/add-page-view-instrumentation branch from 20037ff to 6e2859e Compare August 12, 2025 20:56
@pichlermarc
Copy link
Member

@Abinet18 - looks like the build is failing - would you mind having a look? Other than that this looks like it's good to merge.

@Abinet18 Abinet18 force-pushed the feat/add-page-view-instrumentation branch from 3735b4a to b321b19 Compare August 13, 2025 17:28
@Abinet18
Copy link
Contributor Author

Abinet18 commented Aug 13, 2025

@Abinet18 - looks like the build is failing - would you mind having a look? Other than that this looks like it's good to merge.

@pichlermarc not sure why npm run lint is failing here, I can run it successfully in local

Copy link
Contributor

@martinkuba martinkuba left a comment

Choose a reason for hiding this comment

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

I have previously approved this. However, the semantic conventions are still not merged and will be different from what is implemented in this PR (body fields vs attributes, human-readable enum values for the type field). We can merge this now either as a development package (private set to true in package.json). Or, we can wait for the semconv PR to be merged first.

@Abinet18 Abinet18 changed the title feat: Add page view instrumentation plugin feat: Add page view instrumentation Sep 8, 2025
@pichlermarc
Copy link
Member

@Abinet18 please also resolve the conflicts to get the workflows to run.

@Abinet18 Abinet18 force-pushed the feat/add-page-view-instrumentation branch from b6ae786 to 4d4ca8f Compare September 10, 2025 17:53
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

Target: Browser Targets on Browser

Projects

None yet

Development

Successfully merging this pull request may close these issues.