How to use Datadog 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 AppEngin 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.
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'