How to use custom Datadog metrics on Google App Engine
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"
- 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
)
- start sending your own metrics
@app.route('/datadog')
def datadog():
dog.increment('myapp.requests', tags=['controller:datadog'])
return 'Datadog'
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 doflush_in_thread=True
, than get metrics in the dashboard. Can u clarify