elastic / apm-agent-nodejs

https://www.elastic.co/guide/en/apm/agent/nodejs/current/index.html
BSD 2-Clause "Simplified" License
581 stars 224 forks source link

Add support for google cloud functions; or is already supported? #2362

Open eliaskardel opened 2 years ago

eliaskardel commented 2 years ago

is it possible to integrate elastic apm in a google cloud function environment (using the nodeJS type of cloud functions)?

Or do I have to use that one here:

https://www.elastic.co/guide/en/apm/agent/nodejs/current/custom-stack.html

trentm commented 2 years ago

@eliaskardel Thanks for the request. We do not currently have any specific support for Google Cloud Functions, nor are we currently working on it. We are currently working on AWS Lambda support. Some of the Node.js APM agent improvements for Lambda should help for eventual Google Cloud Functions work.

I'm not aware of an equivalent to Lambda Extensions (https://docs.aws.amazon.com/lambda/latest/dg/runtimes-extensions-api.html) for Google Cloud Functions to would allow for better integration of the APM agent. Also, I've no experience with https://cloud.google.com/functions/docs/concepts/nodejs-runtime#signal-termination to know how difficult it would be to guarantee APM data delivery to the upstream APM server before function instance execution is paused.

eliaskardel commented 2 years ago

Any timeline on when to except this? Anyway how to upvote this? Anyway how to support this? thanks

trentm commented 2 years ago

Any timeline on when to except this?

@eliaskardel Sorry, no we don't have a timeline for Google Cloud Functions. If you meant for Lambda support, we hope to have experimental (i.e. not final, deployment details might change) support out "soon".

Anyway how to upvote this?

Probably best would be to start an issue on https://github.com/elastic/apm to request the feature. This can help our product managers with prioritization. For example, here was the one for Lambda support: https://github.com/elastic/apm/issues/352

Anyway how to support this?

It is possible that using the current Node.js APM agent in a google cloud function will mostly just work. However I suspect it will take some playing around and configuring. If you intend to give it a try, some suggestions/ideas:

eliaskardel commented 2 years ago

Hi @trentm ,

yes I was talking about a timeline for Google Cloud Functions.

Probably best would be to start an issue on https://github.com/elastic/apm

I did it. here: https://github.com/elastic/apm/issues/526

current Node.js APM agent in a google cloud function will mostly just work

In general, it works out of the box.

With spans however, we observe the issues that sometimes (~10% of all invocations) it throws an error like the start of the span would not been have created. Hence myCustomSpan.end() throws an error

image

Any hints on that one?

Thanks

trentm commented 2 years ago

With spans however, we observe the issues that sometimes (~10% of all invocations) it throws an error like the start of the span would not been have created. Hence myCustomSpan.end() throws an error

Note that apm.startSpan(...) can return null. Usually the reason is that there is no current transaction. Turning on "trace"-level logging in the agent might help clarify.

It is hard to know if that might be the cause without knowing more about your code. It is possible that the two coming issues I mentioned above might help.