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: check supportedEntryTypes when starting observer #1246
fix: check supportedEntryTypes when starting observer #1246
Conversation
* observed for unknown entry types as longtasks and lcp is | ||
* not supported at the moment | ||
*/ | ||
try { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I've removed try-catch based on the description in the comment, if folks think it's too risky, I will put it back.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I would remove the comment but I wouldn't remove the try-catch.
- Main reason: It's a browser API, I would treat it as an external dependency and I would follow a defensive approach.
- The spec mention "error" and "exception" multiple times. Theoretically the only that can affect the agent (due to the way we are using the API) is the one about the invalid entry type, theoretically... 😄
- There are a ton of browsers (and versions) out there that we are supporting on 5.x versions. Besides, to see bugs like the one commented on this issue: https://github.com/elastic/sdh-kibana/issues/2547#issuecomment-1029054684 it's not completely ruled out.
We can add a comment inside the catch if you think that might be helpful for the future us and future contributors. Something like this
WDYT?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Thanks Alberto, it all makes 💯 sense!! I've put back try-catch and added some comment inside catch 🙏
📦 Bundlesize report
|
83851f3
to
0a31399
Compare
*/ | ||
try { | ||
const supportedEntryTypes = | ||
window.PerformanceObserver?.supportedEntryTypes || [] |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
You can use the isPerfTypeSupported util instead.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Oh wow, I didn't know it existed!! 🌟
e1d17f0
to
4563bc0
Compare
try { | ||
const supportedEntryTypes = | ||
window.PerformanceObserver?.supportedEntryTypes || [] | ||
if (supportedEntryTypes.indexOf(type) === -1) { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Just thinking out loud:
supportedEntryTypes became available later than observe
For instance:
If we stop reporting based on supportedEntryTypes we might start missing data. Okay, maybe in the case of Chrome and Firefox it's not a big deal since versions before 73 and 68 are old. Besides, they are evergreen browsers.
The case of Safari might be different. We support older versions such the 12. What is more, Safari is not an evergreen browser. 😭 As you can see here and here
It seems that we might be adding a breaking change discreetly.
Questions:
- Does the firefox warning has more importance than the versioning thingy?
- Is firefox the only browser reporting the warnings?
If firefox is the only one complaining and you both believe that what I commented above might be a problem, a possible proposal might be:
Step 1:
We are in 5.x version, we don't want new releases to cause unexpected regressions. What about checking if the user agent is firefox for the following entry types: largest-contentul-paint, layout-shift, and long-task. I know that checking user-agents is tricky. But I wanted to share this at least.
Step 2:
Once we go to 6.x version, there is where we can do breaking changes. For instance, "We support the following browsers, etc, etc". And then we can remove the logic added in Step 1
--
I considered that at least was important to bring out this concern
What are your thoughts, @kyungeunni @vigneshshanmugam?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This is a great point, thanks for bringing this up.
As you mentioned, most of the browsers shipped supportedEntryTypes
later than observe
so I can see this change will introduce regression as fewer metrics will be observed, even though the entryType is supported for the browsers.
I appreciate your suggestion on Step1, although would it be fair to assume the possibility each version of FF could have a different set of supported entry types? (e.g. let's say version 57 supports 3 entry types, version 60 supports 5 so not only largest-contentul-paint, layout-shift, and long-task would log the warning messages but other unsupported ones too). Also, there are uninvestigated browsers too that could possibly log the warning messages as same as FF does. That being said, it seems like we can't be sure to cover all the cases with this approach, It'd look like we didn't really fix this bug as we didn't cover all the cases.
I'd love to chat about plans for supported browsers for 6.x
and plan this change accordingly. Meanwhile, could we communicate with users that this is how Firefox-specific behavior and if we try to mute the log, it would introduce regression as we will capture fewer metrics? If it's not a critical bug from the user's perspective, that is.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I agree with you here. Likely, the most sensible thing we can do is not to mute the log since a clean solution without supportedEntryTypes seems a bit tricky and probably it's not worth the effort. So I also think that we can wait until 6.x to retackle this. I would like to know @vigneshshanmugam thoughts before closing the PR though.
The issue related to this PR probably will end up having the breaking-change label. And also we will need inform about our decision to the support engineer that brought out this issue.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I would like us to think this in a different way. The main types we use for Observer are largest-contentful-paint
, long-tasks
, paint
, input-delay
-
apm-agent-rum-js/packages/rum-core/src/performance-monitoring/transaction-service.js
Lines 166 to 169 in 96c7e69
this.recorder.start(LARGEST_CONTENTFUL_PAINT) | |
this.recorder.start(PAINT) | |
this.recorder.start(FIRST_INPUT) | |
this.recorder.start(LAYOUT_SHIFT) |
I believe none of those metrics would be supported by the older browsers such as Safari 11
. If we can confirm that, then we should be good to do just doing a check with supportedEntryTypes
even in 5.x versions.
Let me know your thoughts.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
@vigneshshanmugam thanks for your comment.
It's true, PAINT started to be compatible on Safari 14.1. I wouldn't worried about Chrome either, even if PAINT was available on 60 and supportedEntryTypes on 73. I understand that we rely on Chrome being an evergreen browser and that allows us to be a bit more flexible with the browser support here.
🎉
🌐 Coverage report
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
LGTM 🎉
fixes #1245
This PR checks
PerformanceObserver.supportedEntryTypes
before starting an observer for a certain entryType so that it doesn't print a warning on Firefox browser and doesn't trigger errors on Safari when it starts observer for unsupported types.Before the change on Firefox (latest version):
After the change on Firefox (local build of this PR):
Note
List of supported entry types:
['element', 'event', 'first-input', 'largest-contentful-paint', 'layout-shift', 'longtask', 'mark', 'measure', 'navigation', 'paint', 'resource']
[ "event", "first-input", "mark", "measure", "navigation", "paint", "resource"]
["mark", "measure", "navigation", "paint", "resource"]