Skip to content

Instantly share code, notes, and snippets.

@LeoCavaille
Forked from alq666/gae.md
Last active February 26, 2019 23:13
Show Gist options
  • Star 1 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save LeoCavaille/bb4379d628db2fa6e102 to your computer and use it in GitHub Desktop.
Save LeoCavaille/bb4379d628db2fa6e102 to your computer and use it in GitHub Desktop.
Custom Datadog metrics on Google App Engine

How to use custom Datadog metrics on Google App Engine

Installation

We will use the dogapi module to instrument your code. There are a lot of ways to ship libraries to Google App Engine using virtualenvs, symlinks, etc. If you already have that, just add to your stack the latest version of dogapi from PyPi.

If not, here is an easy way to use dogapi:

cd $MY_GAE_PROJECT
echo "dogapi" >> requirements.txt
pip install -r requirements.txt -t lib/

Then in your application initalization (appengine_config.py) make sure to the libraries to your Python path:

import sys
import os.path
sys.path.insert(0, os.path.join(os.path.dirname(__file__), 'lib'))

Also the dogapi module sends metrics and events through a secure TLS connection, so you need to enable the ssl module in your app.yaml

libraries:
  - name: ssl
    version: "latest"

Instrumentation

  1. set your API key from datadog when initializing dogapi. The flush_in_thread is needed right now due to threading constraints on GAE
from dogapi import dog_stats_api as dog
dog.start(
    api_key=PUT_YOUR_API_KEY_HERE,
    flush_in_thread=False
)
  1. start sending your own metrics
@app.route('/datadog')
def datadog():
    dog.increment('myapp.requests', tags=['controller:datadog'])
    return 'Datadog'
@danish1010
Copy link

If you do flush_in_thread=False, how will the metrics be send. I did follow the above steps but the dashboard never recieve metrics. if i do flush_in_thread=True, than get metrics in the dashboard. Can u clarify

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment