Skip to content

Instantly share code, notes, and snippets.

@danish1010
Last active April 18, 2019 15:54
Show Gist options
  • Save danish1010/feb1da638f60fa5f38285c9307270a7a to your computer and use it in GitHub Desktop.
Save danish1010/feb1da638f60fa5f38285c9307270a7a to your computer and use it in GitHub Desktop.
RUNNING Datadog in GAE
def get_request_from_user():
payload = {
metric_name: 'xyz',
value: 1
}
# Add payload to the queue
# which would we picked up by the worker to flush metric
add_job_to_metrics_flush_worker(payload)
# return something back to the user
# using https://github.com/DataDog/datadogpy
"""
This complete file runs on a backend-worker or
i am a job is added in the queue and the worker executes the
function worker_job
"""
stats = None
def initialize():
global stats
datadog.initialize(**options)
stats = datadog.ThreadStats()
# GAE do not allow creation of a new thread
# hence flush_in_thread = False
stats.start(flush_in_thread=False)
def worker_job(metric_name, value):
stats.increment(metric_name, value)
# Given we dont have any thread to flush
# we do it here
stats.flush()
initialize()
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment