-
Notifications
You must be signed in to change notification settings - Fork 227
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
require("elastic-apm-node") influences stacktrace generated with "node --enable-source-maps ..." #2833
Comments
TIL that
I agree with that statement, in general: that just require'ing the agent should not impact behaviour of the app, at least as much as possible. Starting the agent, ideally, should not impact behaviour of the app either, but I suppose there is more latitude for some impact when the agent is active. Why
|
Hi thanks for the quick and detailed reply :-).
However in our source code we have code to start the APM agent and then to interact with the APM Agent API for example to customize the transaction name:
When developing locally, the agent is never active because we always set the standard APM agent environment variable ELASTIC_APM_ACTIVE=false but in a target production environment the agent is active. As a workaround we could wrap above in an if:
but ideally we could like to avoid this because if in the rest of the code we also use the APM Agent API, then these should be wrapped as well. Or could this condition on ELASTIC_APM_ACTIVE be considered within the require('elastic-apm-node') call itself? |
I think your use case would be handled by doing this:
More specifically we should avoid Thanks for clarifying the use case; that helps. I'll see about getting this scheduled for our next planning session. |
* feat: Delay loading error-callsites module to avoid side effects. #2833
elastic-apm-node@3.39.0 is release with this now |
Hi @trentm, sorry to bump such an old issue, but I'm wondering if it still holds true to this day with a node@18 and apm@4.1.0 for example. I've been experimenting around this since we have this problem in production, and with the following minimal example in typescript: import apm from 'elastic-apm-node';
apm.start();
function foo() {
throw new Error('A');
}
try {
foo();
} catch (e) {
console.info((e as any).stack);
} Building this file with With
Without
Passing |
Hi @Marsup. I believe what you are seeing is what is currently expected from the above discussion, though obviously it isn't ideal. The change in elastic-apm-node@3.39.0 made it so node's my repro
foo.ts import apm from 'elastic-apm-node'; apm
// apm.start()
interface Foo {
}
function aFunc() {
throw new Error('boom')
}
aFunc() foo-start-apm.ts import apm from 'elastic-apm-node'; apm
apm.start()
interface Foo {
}
function aFunc() {
throw new Error('boom')
}
aFunc() Showing with and without
This shows that starting the APM agent results in different handling of
possible improvementsTo improve on this situation will take new work on the APM agent.
However, this only handles the % cat foo-internal-error.ts
interface Foo {
}
function aFunc() {
throw new Error('boom')
}
try {
aFunc()
} catch (err) {
console.log('caught an err:', err.stack)
}
% ./node_modules/.bin/tsc --sourceMap --esModuleInterop foo-internal-error.ts
% node foo-internal-error.js
caught an err: Error: boom
at aFunc (/Users/trentm/tmp/asdf.20231103T165932/foo-internal-error.js:2:11)
at Object.<anonymous> (/Users/trentm/tmp/asdf.20231103T165932/foo-internal-error.js:5:5)
at Module._compile (node:internal/modules/cjs/loader:1256:14)
at Module._extensions..js (node:internal/modules/cjs/loader:1310:10)
at Module.load (node:internal/modules/cjs/loader:1119:32)
at Module._load (node:internal/modules/cjs/loader:960:12)
at Function.executeUserEntryPoint [as runMain] (node:internal/modules/run_main:86:12)
at node:internal/main/run_main_module:23:47
% node --enable-source-maps foo-internal-error.js
caught an err: Error: boom
at aFunc (/Users/trentm/tmp/asdf.20231103T165932/foo-internal-error.ts:4:11)
at Object.<anonymous> (/Users/trentm/tmp/asdf.20231103T165932/foo-internal-error.ts:7:5)
at Module._compile (node:internal/modules/cjs/loader:1256:14)
at Module._extensions..js (node:internal/modules/cjs/loader:1310:10)
at Module.load (node:internal/modules/cjs/loader:1119:32)
at Module._load (node:internal/modules/cjs/loader:960:12)
at Function.executeUserEntryPoint [as runMain] (node:internal/modules/run_main:86:12)
at node:internal/main/run_main_module:23:47
Would you be willing to open a separate feature request issue for this? It is very helpful to have real user use cases on issues to motivate development. |
* feat: Delay loading error-callsites module to avoid side effects. elastic#2833
Describe the bug
To Reproduce
A. package.json
B. tsconfig.json
C. src/main.js
D. src/mod1.ts (CJS module)
E. src/mod2.ts (ES6 module)
Then using node 16 :
Running above script results in :
However when in src\main.js the first line (const apm = require('elastic-apm-node')) is put in comment, you will get the right stack trace:
Expected behavior
Doing require('elastic-apm-node') should not influence the stacktrace generated by "node --enable-source-maps ...".
Environment (please complete the following information)
How are you starting the agent? (please tick one of the boxes)
agent.start()
directly (e.g.require('elastic-apm-node').start(...)
)elastic-apm-node/start
from within the source code-r elastic-apm-node/start
Additional context
Agent config options
Click to expand
package.json
dependencies:Click to expand
The text was updated successfully, but these errors were encountered: