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

Fix potential access to deprecated web API's #496

Merged
merged 33 commits into from
Aug 10, 2023

Conversation

Hamish-taylor
Copy link
Contributor

@Hamish-taylor Hamish-taylor commented Aug 4, 2023

The problem

This is the timing object, and on this line we are accessing .responseEnd which has been deprecated in favor of this. We do actually collect this timing object when we get the performance metrics here, but I don't fully understand what happens with that information.

The result

The result of this is that the events are still sent, but due to missing/bad data the events are never displayed on the frontend.

The fix

  • Added checks to make sure we are not accessing the undefined property. <- there's probably a better way of handling this
  • Allowed the new timing object to be used

My current questions

  • How do we ensure the fix is backwards compatible
    • According to caniuse.com The 'new' metric is supported across 93.12% or users compared to 95.71% with the old method (a difference of 2.59%).
  • Do the new timing events measure the same things?
    • From my testing it appears that they do

Copy link
Collaborator

@Olwiba Olwiba left a comment

Choose a reason for hiding this comment

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

Nice work on this & nice write-up. Appreciate the links to make review easier 😄
I've added some comments/thoughts

@@ -24,7 +24,7 @@
errorQueue = window[window['RaygunObject']].q;
var rg = Raygun;

var delayedExecutionFunctions = ['trackEvent', 'send', 'recordBreadcrumb'];
var delayedExecutionFunctions = ['trackEvent', 'send', 'recordBreadcrumb','captureMissineRequests'];
Copy link
Collaborator

Choose a reason for hiding this comment

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

can you tell me more about this change?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Well firstly I just noticed that its spelt wrong 😅 This is mostly unrelated to the primary issue that the PR is trying to solve. However, the captureMissingRequests function uses the offset var which I had modified, so when testing I wanted to verify that I hadn't broken it. This is when I found that in this function _rum seems to always be undefined which results in captureMissingRequests never being set. Adding it into the delayedExecutionFunctions means that it is run after the _rum object is created. Now that I think about it this might result in the first page load missing any of these requests as the property might be set after the occur? 🤔

Copy link
Collaborator

Choose a reason for hiding this comment

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

hmm, possibly something to test - it makes sense to delay this as it's calling the _rum.captureMissingRequests and if _rum is always null then it wouldn't have been doing anything anyway. I do see a null check inside the captureMissingRequests, I wonder if this was to mitigate this

src/raygun.rum/index.js Outdated Show resolved Hide resolved
src/raygun.rum/index.js Outdated Show resolved Hide resolved
Olwiba
Olwiba previously approved these changes Aug 8, 2023
Copy link
Collaborator

@Olwiba Olwiba left a comment

Choose a reason for hiding this comment

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

Thanks for the changes - The code changes are looking good to me.
Please make sure you test this thoroughly & pre-soak because I've not had a chance to test this out myself 🚀

If you're unsure or would like some help with testing feel free to reach out otherwise I'll leave it in your hands

src/raygun.rum/index.js Outdated Show resolved Hide resolved
src/raygun.rum/index.js Outdated Show resolved Hide resolved
@darcythomas
Copy link
Contributor

Looks like you have a broken test.

Other than that it looks good :P

Copy link
Contributor

@darcythomas darcythomas left a comment

Choose a reason for hiding this comment

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

LGTM

PanosNB
PanosNB previously approved these changes Aug 10, 2023
Copy link

@PanosNB PanosNB left a comment

Choose a reason for hiding this comment

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

I did a code review with Hamish who explained the work to me. Everything made sense to me: I suggested he adds in some comments to explain the ideas.

Overall, I understood the following:

  • In raygun.loader.js, we register a new callback to the new navigationPerformanceObserver object, if it exists, that will call our onLoadHandler(), indicating page loaded, after the navigation event has been triggered. The latter is achieved adding to the observer the name of the desired entry type
  • In index.js, because the new way of measuring starts the timing from 0 rather the current UNIX timestamp that the old object uses, we set the timestamp offset to 0 for both virtual pages and the new way but to the current timestamp for the old way
  • Also in index.js, instead of directly accessing fields that might not exist, a bridge pattern is used that stores either the or the old type of object in the timing reference. Then, a method getTimingDuration() requests the right type of fields per type
  • Finally, also in index.js, we exclude navigation and visibility-state objects from being further investigated as it is enough to be reported at the top level of the session: adding them to secondary, resulted into nans

@@ -280,7 +280,14 @@

if (!Raygun.Utilities.isReactNative()) {
if (document.readyState === 'complete') {
onLoadHandler();
onLoadHandler();
} else if (!!window.PerformanceObserver && !!window.PerformanceObserver.supportedEntryTypes && window.PerformanceObserver.supportedEntryTypes.includes('navigation')) {
Copy link
Collaborator

@Olwiba Olwiba Aug 10, 2023

Choose a reason for hiding this comment

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

Optional: A possible clarity improvement here could be to split this check out into a variable so it's obvious what the containing code is for.

Something like (var name could be improved):

var supportsPerformanceNavigationEntries =  !!window.PerformanceObserver && !!window.PerformanceObserver.supportedEntryTypes && window.PerformanceObserver.supportedEntryTypes.includes('navigation');

Then the conditional is simplified to:

else if (supportsPerformanceNavigationEntries)...

Copy link
Collaborator

@Olwiba Olwiba left a comment

Choose a reason for hiding this comment

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

I've reviewed the code changes since the last review & nothing stands out to me as off.
Great work here 🚀

Leaving approval for others, but I'm happy with the update

xenolightning
xenolightning previously approved these changes Aug 10, 2023
bower.json Outdated Show resolved Hide resolved
@xenolightning
Copy link
Contributor

Great work @Hamish-taylor!

The only comment I had was to maybe bump minor version, but not required

Copy link
Contributor

@xenolightning xenolightning left a comment

Choose a reason for hiding this comment

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

Update versions

CHANGELOG.md Outdated Show resolved Hide resolved
CHANGELOG.md Outdated Show resolved Hide resolved
xenolightning
xenolightning previously approved these changes Aug 10, 2023
@Hamish-taylor Hamish-taylor merged commit 15f4b86 into master Aug 10, 2023
1 check passed
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.

5 participants