Open DrewML opened 1 month ago
Hi @DrewML could you verify which version of the browser agent you are seeing this issue? Did you confirm there is a trend showing this is mainly Chrome on Windows? Is it a specific version of Chrome? The code in question is synchronous and executes immediately when the agent is injected to the browser HTML. We could make a small change to verify val.api
but I don't know that we could test the issue since the code is synchronous.
Hi @DrewML We have not received a reply to the last message asking to confirm the version of the browser agent. We also recently pushed out an update and you should be getting that. Let me know if you are still having this issue. If you are, can you provide some info around timing of your call to newrelic.setCustomAttribute
? Is that happening after the browser agent script? If your site is public, a link to it would also be helpful if you are comfortable providing that here. Thanks.
Planning to add safeguard to this code; would still like further information on how this is reproduced if possible.
(Moved from https://github.com/newrelic/node-newrelic/issues/2238)
Description
I'm using the
newrelic@11.12.0
package in a node.js @20.11.0
web app. This project usesnewrelic.getBrowserTimingHeader()
to load the browser SDK for clients. According to the inlined code, I think the version of the browser agent loaded is1.260.1
Although it's not recommended, this app uses another 3rd party client-side error monitoring tool in addition to New Relic. Through this 3rd party tool, I've noticed the New Relic browser SDK occasionally throwing the exception
Cannot read properties of undefined (reading 'setCustomAttribute')
.The stack trace reported by the 3rd party tool starts at my app's helper function,
setNewRelicAttribute
. The body of that function is a tiny wrapper aroundwindow.newrelic.setCustomAttribute(key, val)
with some safety checks to make surenewrelic
is present onwindow
.To try and narrow down a culprit for the exception, I set a breakpoint in my
setNewRelicAttribute
function in the browser, and walked through the calls into the browser agent, trying to match stack frames from the browser and from the 3rd party tool to their source on Github. Here's the trail I found into the browser agent:src/loaders/api/api.js
used to expose public API methods from the agentcaller
functionforEach
loop iterating over each initialized agentBased on this trail, I suspect that the check for
val.exposed && val.api[fnName]
is throwing an exception due toval.api
beingundefined
at that point in execution for some reason, for some clients.Expected Behavior
Calls to
window.newrelic.setCustomAttribute
should not throw an exceptionTroubleshooting or NR Diag results
Steps to Reproduce
I've not yet been able to replicate the exception myself. Based on events in the 3rd party tool, this seems to predominantly impact clients using Chrome on Windows.
Additional Info
This isn't a critical issue since I can just wrap the body of the
setNewRelicAttribute
wrapper function in atry/catch
for the time being.We'll also try updating to the latest version of the agent in the near future to rule out a fix already being
main
.