-
Notifications
You must be signed in to change notification settings - Fork 43
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
NewRelic overwrites window.Promise #187
Comments
Hey @graemechapman, is there a specific issue that you're running into where our Promise instrumentation is interfering with other code? |
Hi @aubreymasten I have a class extending from Promise, when run in conjunction with newrelic the additional methods on these class instances are not accessible. I have been able to work around this for now by grabbing the original promise constructor from |
@kucaahbe I'm unable to reproduce this issue on a vanilla page's agent for the current (unreleased) version and a production customer's website v1216 agent. I haven't looked into TinyMCE specifically, but a potential cause for conflict as had happened before is other libraries or API implementations that also touches the global |
Hi @graemechapman, could you clarify a little more about what and where the friction is please? I did not find any issue with calling the instance method of an inherited-from-Promise class--am I misunderstanding? Specifically, the (spa flavor) agent will wrap around the |
hello @cwli24 , thanks for the reply. In our case TinyMCE wasn't the cause of the issue: its code uses the <!DOCTYPE html>
<html lang="en">
<head>
<meta charset="utf-8">
<meta http-equiv="X-UA-Compatible" content="IE=edge">
<meta name="viewport" content="width=device-width, initial-scale=1">
<title>NewRelic issue #187 test case</title>
<script>
if (Promise.allSettled) {
alert('Promise.allSettled initially exists')
} else {
alert('Promise.allSettled does not exist')
}
</script>
<script type="text/javascript">
NewRelic agent code snippet here
</script>
<script src="https://cdn.jsdelivr.net/gh/paulmillr/es6-shim@0.35.6/es6-shim.js"></script>
</head>
<body>
<script>
console.log('Promise.allSettled:', Promise.allSettled)
if (Promise.allSettled) {
alert('Promise.allSettled exists')
} else {
alert('Promise.allSettled is overrided')
}
</script>
</body>
</html> |
Jira CommentId: 116274 Since our instrumentation relies on knowing when a promise is created and subsequent methods like |
Jira CommentId: 116275 We should create a couple test cases: Compare the static methods of window.NREUM.o._PR and window.Promise and verify those static methods existCompare the methods of an instance of window.NREUM.o._PR and window.Promise and verify those methods existCreate test case that uses handlers with a set context and verify that context is retained within the handler |
Jira CommentId: 138424 Promise methods like 'any' and 'allSettled' are already returned as 'Native Code' when the customer's shim is not loaded into the page, so this bug ticket is actually just an integration issue with whatever shim the reporter was using (and likely others that expect native code). So I am just going to put in a backlog ticket to re-evaluate the way we wrap promise instead of overwriting the global and close this bug ticket. |
Work has been completed on this issue. |
@samdenty Can you look to see what version of the agent is being loaded? Maybe provide a link to your website? I just checked another site that is loading the latest version of our agent (1225) and |
the URL is https://stackblitz.com/~/github.com/withastro/docs (temp disabled until next week when a solution comes up) |
Thanks for bringing this up & to our attention. v1225 included a re-working of our Promise wrapping because what we were doing before was directly modifying the native Promise that async/await implements. -- Apologies for causing breakage! Going forward, our (wrapped) Promise will likely remain that way; we may re-discuss the implementation, though I feel this is the right thing to do. It's very similar to Bluebird's dilemma in that async/await's returned Promise cannot be replaced with our custom Promise. I'm not sure you're going to get the (revert) solution from this agent, to be frank. However, there are ways on your end to "fix" it:
|
we're running a fork of microsoft's vscode codebase directly in the browser. We try to keep modifications to a minimum, so only the last resort option (swapping the original promise back) would work. Maybe we do that hack to keep using new relic? @fvsch I could imagine that I'm not personally a fan of overriding globals, I would much prefer this as an option (disabled by default maybe?) - but that's just my opinion 🙂 I'm not deeply familiar with new relic though and what features overriding promise gives |
@samdenty Do you have a staging environment/site that we can use to debug? |
To clarify, it's not particularly Regardless, the native global is still there (hidden) and left untouched, which to me is better than modifying its prototype, irrespective of the global ref replacement. And unfortunately, that means |
I presumed you were already doing this and this bug was an edge case where this didn't work (hence my suggestion to add an option to disable) - but are you defining a Symbol.hasInstance on your custom promise, that returns true when both a native promise and mocked promise is passed |
@samdenty I am going to open a new issue for this so we can better track it. |
Description
As per the title, replacing browser built-ins is generally a bad idea, and can interfere with other code which relies on this functionality.
Steps to Reproduce
Visit a website running NewRelic, and try to use window.Promise.
Expected Behavior
Relevant Logs / Console output
Your Environment
Browser name and version: Chrome 98
Operating System and version: macOS Big Sur
Additional context
n/a
The text was updated successfully, but these errors were encountered: