-
Notifications
You must be signed in to change notification settings - Fork 230
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
improve agent docs for use with TypeScript, bundlers, and perhaps ESM #1967
Comments
Note #2318 and this comment explaining my understanding: #2318 (comment) |
node -r elastic-apm-node/start app.js
|
The "weird, hard" case I'm thinking about is: a future Fleet-based deployment that:
What changes (docs and agent support) do we need for this to work? One likely agent change needed here is for the Agent singleton handling to move from depending on require.cache to using a property on |
A possible webpack-using test case should perhaps have a case for ".json" not being in that set to see if things still work. If not, and if ".json" is not in the default webpack.config.js (via docs or whatever generator), then see if we can drop those deps. Update 2022-07-26: This transitive dep on |
Note the excellent Fastify TypeScript intro docs that might be worth using as inspiration: https://github.com/fastify/fastify/blob/main/docs/TypeScript.md#getting-started Update: Now here: https://github.com/fastify/fastify/blob/main/docs/Reference/TypeScript.md |
Note bundler "fun" with pino@7 should we upgrade to pino@7 (or if a user passes in a pino@7 logger in config): pinojs/pino#1209 |
A related discuss topic: https://discuss.elastic.co/t/apm-agent-not-working-with-nodejs/295638 |
Perhaps related is support for (or at least setup and troubleshooting docs for) Next.js support. See #1611 and other enhancement requests. |
Answering my own question. Attempting to
This is because we are using a "Bare specifier" to the import statement that doesn't have an "export" in elastic-apm-node/package.json. So if we add this to our package.json:
then it "works". Where "it" here is: // foo2.mjs
import 'elastic-apm-node/start';
import http from 'http';
const server = http.createServer((req, res) => {
req.resume()
res.statusCode = 200;
res.end('pong');
});
server.listen(3000, () => {
http.get('http://localhost:3000', res => {
console.log('CLIENT: res.headers:', res.headers)
res.resume()
res.on('end', () => {
console.log('CLIENT: res "end"')
server.close()
})
})
}); And "works" is in quotes because this would only be a start to true ESM support, because we don't yet support auto-instrumenting This section of the docs has advice on whether to go "with extension" or "without extension": https://nodejs.org/api/packages.html#extensions-in-subpaths The first suggestion is to be consistently all one way. Later in that section it tends to imply that with the extension would be preferred. However, given that we already have tl;dr: The answer is to not have the ".js" in our docs for using Update 2022-07-26: My opinion on whether we should prefer "with extension" or "without extension" is wavering. |
This is experimental. I'm not sure if there are side-effects. See #1967 (comment)
Per some history and info from https://esbuild.github.io/content-types/#es-module-interop I think we should only bother worrying about support with |
There are a number of surprises/gotchas/not obvious hurdles to getting APM working with TypeScript, bundlers (like webpack), and ESM. The agent docs could be improved a lot for some of these cases. Comments below are collecting some Qs, gotchas, notes for this. (I realize that makes this issue a little fuzzy for "completion.")
initial description
See #1962 (comment) about it being hard to find the suggestion to use the
npm -r elastic-apm-node/start app.js
technique for those using bundlers (like webpack) or transpilers (like TypeScript) that might remove or re-order the "elastic-apm-node" import.#608 was a similar issue a while back, for which #638 added a note to https://www.elastic.co/guide/en/apm/agent/nodejs/current/agent-api.html#apm-start
The text was updated successfully, but these errors were encountered: