Open trentm opened 1 year ago
The user on the discuss thread above mentioned that adding elastic-apm-node
to the External
config field (as mentioned at https://docs.aws.amazon.com/serverless-application-model/latest/developerguide/serverless-sam-cli-using-build-typescript.html) resolves the issue for them.
Hi @trentm! my team is also trying to use this, but a lot of our systems currently build with esbuild, and it would be a lot simpler to run this if esbuild was supported out of the box. Was there any priority set on this?
This AWS guide pitches using esbuild, sam, and typescript for Lambdas: https://docs.aws.amazon.com/serverless-application-model/latest/developerguide/serverless-sam-cli-using-build-typescript.html
This discuss issue pointed out that attempting to import and use the APM agent in the Lambda handler code does not work.
apm.isStarted()
returnsundefined
, indicating that the in-code import is not getting the wanted sharedAgent
singleton from the APM agent started viaNODE_OPTIONS
. A fix for this might be (or at least partially) usingglobalThis
for the singleton sharing. The current use ofrequire.cache
doesn't work with bundled modules.elastic-apm-node
module be in the esbuildexternals
-- as documented at https://www.elastic.co/guide/en/apm/agent/nodejs/current/starting-the-agent.html#start-esbuild. Can this config be passed through via the SAM configuration? If so, we should document this example.elastic-apm-node
listed in dependencies, but still import it via CommonJSrequire
. That might result in getting theelastic-apm-node
module provided by the Elastic Lambda layer. This may require configuring a linter and/or esbuild to ignore the attempt to import a module that is not listed in "dependencies".Format: cjs
in the SAM config.I don't know how prevalent this is, but it has come up at least once: https://discuss.elastic.co/t/how-to-send-error-message-to-elastic-apm-and-show-the-error-in-kibana-tab/329183/5 As well, the "esbuild-bundled APM agent not sharing the same singleton Agent instance" has also come up before.