Replace NewRelic browser instrumentation with custom error handler#8950
Replace NewRelic browser instrumentation with custom error handler#8950
Conversation
I'll admit I don't look at it often, but I do like knowing we have access to some of the page load times, as reported by the browser. I worry about the number of logs we'd create if we tried to log that ourselves, but some of that could be nice (loading time, time to first paint, etc etc) |
It's a paradox where NewRelic's tooling to diagnose slow page loads would inevitably lead us to the conclusion that NewRelic's own tooling contributes most significantly to it? 😄 For this, I wasn't sure how much value we'd get out of this data vs. something we could debug or simulate locally, since I wouldn't really expect a lot of variability between usage in the wild. Alternatively, I'd wondered if the synthetic monitors would give us similar data in NewRelic, but act externally without needing to be part of each user's request. |
My understanding is that people's internet connections (which vary a lot) would definitely contribute to things like asset loading, etc etc, so we'd get much more value of the overall sense (and the long tail) by measuring real user usage. Maybe we could randomly sample 1/1000 pageviews and send that data so we get something but not an avalanche of everything |
I'm sure it's not 100% accurate, but we can simulate network conditions and even CPU conditions with Chrome's tooling:
Looks like it's even built-in to the new "Performance insights" tab: |
39cc667 to
547c42b
Compare
| if error_event? | ||
| NewRelic::Agent.notice_error(FrontendError.new, custom_params: log_params[:payload].to_h) | ||
| else | ||
| frontend_logger.track_event(log_params[:event], log_params[:payload].to_h) | ||
| end |
There was a problem hiding this comment.
what if we brought back the "symbol or proc" logic we used to have before #7110 in EVENT_MAP and then supply a proc for this event?
There was a problem hiding this comment.
what if we brought back the "symbol or proc" logic we used to have before #7110 in
EVENT_MAPand then supply a proc for this event?
Ooh, that's a very interesting idea! Let me give that a shot.
| interface NewRelicGlobals { | ||
| newrelic?: NewRelicAgent; | ||
| } | ||
| export { default as isTrackableErrorEvent } from './is-trackable-error-event'; |
There was a problem hiding this comment.
Follow-up task: Would like to move trackEvent and trackError to dedicated files track-event.ts and track-error.ts so this index.ts can actually be an index.
| false, | ||
| ) %> | ||
| <%= javascript_packs_tag_once('application', prepend: true) %> | ||
| <%= javascript_packs_tag_once('track-errors') if BrowserSupport.supported?(request.user_agent) %> |
There was a problem hiding this comment.
Question: Can we defer this?
There was a problem hiding this comment.
Question: Can we defer this?
I think we can and should make this <script async defer>, with the benefit being that the page can finish being considered "loaded" without being blocked by the tracker.
I still need to get some clarification about async script load order when combined with non-async scripts (related Slack discussion), and this'll require some revisions to ScriptHelper / AssetSources to make sure the extra attributes are carried across to the rendered script tag.
I'll plan to explore this as a follow-on task.
|
I think this is in mostly good shape as-is. One idea I'd been contemplating is checking to see if it's feasible enough to directly call to NewRelic's browser error logging endpoints, i.e. treat this as a tiny drop-in replacement for their existing browser agent for the error logging in particular. That's quite a departure from the initial direction and not sure it's worth pursuing, but figured I should at least check. |
I think that would be a great follow-up PR! Honestly I think it would be worth considering having this log to Or maybe set |
|
I investigated how JavaScript error logging is currently handled in the NewRelic client, and it does seem pretty straight forward as far as POST-ing to a URL with the application ID and an embedded payload of error details, but it might take some sleuthing through the internals of their browser agent code to fully understand what all of the parameters mean. I think to minimize the changes necessary to get this merged, I'll go ahead and add the |
changelog: Internal, Error Tracking, Implement replacement frontend error logger
Previously trying to avoid CDATA , but more standard
This reverts commit bafdea8.
…ller error reporting
… its thing - bind_call calls a specific method implementation, so it doesn't go through the Enhancer implementation
This reverts commit ae086b4.
The method signature is lost if read directly from analytics instance, since it's overridden by AnalyticsEventsEnhancer. We need the original method reference
62f9721 to
c9d605c
Compare
|
I tested this using @mitchellhenke 's personal environment and verified that the errors are being logged as expected errors to NewRelic with the custom parameters https://onenr.io/08wogAPAbwx |
There was a problem hiding this comment.
LGTM
I tested this using @mitchellhenke 's personal environment and verified that the errors are being logged as expected errors to NewRelic with the custom parameters https://onenr.io/08wogAPAbwx
This didn't quite match my expecations:
nameandmessageare the same?- the thing I expected to be
messagewas insidestack?Error: Example error at https://..../packs/js/password_toggle_component-fba98070.digested.js:1:360
Either way, I think it's good enough for now, and we can always iterate and improve later
That is strange! What I'm seeing sent from the browser matches my expectations, so not sure where it's getting lost along the way. Maybe NewRelic is doing its own thing with those parameters, since I could see Example payload I see in testing: |
Easier to see grouped in alphabetical order, avoid conflicting names
|
I think it's definitely a naming conflict thing. Also, namespacing helps make it more easy to see the properties together anyways, so this should be improved now after 4bdf111 . See https://onenr.io/0Owvg5MzaRv |


🛠 Summary of changes
Implements a frontend error logger, replacing the NewRelic browser instrumentation.
Why?
98.2%, from 6.84kb of uncacheable gzip-compressed JavaScript, to 124 bytes of cacheable brotli-compressed JavaScript.†Edit (after revisions): 99.0%, from 6.84kb to 67 bytes gzipped📜 Testing Plan
tail -n1 log/events.logname,message, andstackproperties