Search code examples
google-cloud-platformgoogle-cloud-functionsstatsddatadog

How to report StatsD metrics from a Google Cloud Function written in Node.js?


Is there a simple way it to report custom defined stats to our statsd / Datadog infrastructure from a Google Cloud Function written in Node.js?

Since it's a high-traffic Javascript Cloud Function, I'd like to avoid heavy initialization of additional libraries every time the cloud function is invoked.

Also, by custom stats I mean stats of our own definition (not boilerplate summary statistics via StackDriver or DataDog GCP integration).


Solution

  • After a few more days of research, discovered that:

    • StatsD client libraries like hot-shots allow you to connect the cloud function to a StatsD daemon on the public internet, but not internally to a daemon on your GCP cloud; so this is not an ideal option.
    • Alternatively, libraries like node-dogapi can bypass StatsD daemons and report directly to DataDog. This works if you're ok with providing your DataDog API and App keys to the library so that it can generate the messages to DataDog for you.