from flask import Flask
from datadog import statsd
import logging

import os

# This is a small example application
# It uses tracing and dogstatsd on a sample flask application

log = logging.getLogger("app")

app = Flask(__name__)

# The app has two routes, a basic endpoint and an exception endpoint
@app.route("/")
def hello():
    statsd.increment('request.number', 1, tags=["test", "foo:bar", "my:app"])
    log.info("Got a request at hello")
    return "Hello World!"

@app.route("/error")
def error():
    statsd.increment('request.error.number', 1, tags=["test", "foo:bar", "my:app"])
    log.info("Got a request at error")
    raise Exception()

# This is meant to be run directly, instead of executed through flask run
if __name__ == '__main__':
    # It grabs the host and port from the environment
    port = 5001
    host = '0.0.0.0'
    if os.environ.get('HOST'):
        host = os.environ.get('HOST')
    if os.environ.get('PORT'):
        port = os.environ.get('PORT')
    app.run(debug=True, host=host, port=port)

[((185, 209), 'logging.getLogger', 'logging.getLogger', (['"""app"""'], {}), "('app')\n", (202, 209), False, 'import logging\n'), ((217, 232), 'flask.Flask', 'Flask', (['__name__'], {}), '(__name__)\n', (222, 232), False, 'from flask import Flask\n'), ((336, 409), 'datadog.statsd.increment', 'statsd.increment', (['"""request.number"""', '(1)'], {'tags': "['test', 'foo:bar', 'my:app']"}), "('request.number', 1, tags=['test', 'foo:bar', 'my:app'])\n", (352, 409), False, 'from datadog import statsd\n'), ((514, 593), 'datadog.statsd.increment', 'statsd.increment', (['"""request.error.number"""', '(1)'], {'tags': "['test', 'foo:bar', 'my:app']"}), "('request.error.number', 1, tags=['test', 'foo:bar', 'my:app'])\n", (530, 593), False, 'from datadog import statsd\n'), ((855, 877), 'os.environ.get', 'os.environ.get', (['"""HOST"""'], {}), "('HOST')\n", (869, 877), False, 'import os\n'), ((924, 946), 'os.environ.get', 'os.environ.get', (['"""PORT"""'], {}), "('PORT')\n", (938, 946), False, 'import os\n'), ((894, 916), 'os.environ.get', 'os.environ.get', (['"""HOST"""'], {}), "('HOST')\n", (908, 916), False, 'import os\n'), ((963, 985), 'os.environ.get', 'os.environ.get', (['"""PORT"""'], {}), "('PORT')\n", (977, 985), False, 'import os\n')]