{"id":7236,"library":"flask-datadog","title":"Flask-Datadog","description":"Flask-Datadog is a micro-framework extension for Flask applications, providing access to DogStatsD for custom metrics. Last updated in 2017, it offers a simple wrapper around the `datadog` library's StatsD and API clients. For comprehensive application performance monitoring (APM), tracing, and logging with Flask, Datadog's officially supported `ddtrace` library is the current recommended solution.","status":"maintenance","version":"0.1.4","language":"en","source_language":"en","source_url":"https://github.com/50onRed/flask-datadog.git","tags":["flask","datadog","statsd","monitoring","metrics","extension"],"install":[{"cmd":"pip install Flask-Datadog","lang":"bash","label":"Install latest version"}],"dependencies":[{"reason":"Core web framework integration.","package":"Flask"},{"reason":"Provides the underlying DogStatsD and Datadog API client functionality.","package":"datadog"}],"imports":[{"symbol":"API","correct":"from flask_datadog import API"},{"note":"The 'flask.ext' import path was deprecated in Flask 0.11 and removed in Flask 1.0. Direct import from 'flask_datadog' is required for modern Flask versions.","wrong":"from flask.ext.datadog import StatsD","symbol":"StatsD","correct":"from flask_datadog import StatsD"}],"quickstart":{"code":"from flask import Flask\nfrom flask_datadog import API, StatsD\nimport os\n\napp = Flask(__name__)\n\n# Configure Datadog API and StatsD settings\napp.config['STATSD_HOST'] = os.environ.get('DATADOG_STATSD_HOST', 'localhost')\napp.config['STATSD_PORT'] = int(os.environ.get('DATADOG_STATSD_PORT', '8125'))\napp.config['DATADOG_API_KEY'] = os.environ.get('DATADOG_API_KEY', '')\napp.config['DATADOG_APP_KEY'] = os.environ.get('DATADOG_APP_KEY', '')\n\nstatsd = StatsD(app)\ndogapi = API(app)\n\n@app.route('/')\ndef hello():\n    statsd.increment('my_flask_app.requests')\n    return 'Hello, Datadog!'\n\n@app.route('/error')\ndef error_route():\n    statsd.increment('my_flask_app.errors')\n    # Example of API usage (requires valid API/App keys)\n    # if dogapi.api_key and dogapi.app_key:\n    #     dogapi.Event.create('An error occurred in Flask app', \n    #                        tags=['env:dev', 'service:my-app'])\n    raise Exception('This is a test error!')\n\nif __name__ == '__main__':\n    # Ensure the Datadog Agent is running and accessible at STATSD_HOST:STATSD_PORT\n    # For API calls, ensure DATADOG_API_KEY and DATADOG_APP_KEY are set.\n    app.run(debug=True)","lang":"python","description":"This quickstart initializes Flask-Datadog for both StatsD metric submission and Datadog API interactions. It demonstrates incrementing a custom metric on a successful route and another on an error route. Ensure `DATADOG_STATSD_HOST`, `DATADOG_STATSD_PORT`, `DATADOG_API_KEY`, and `DATADOG_APP_KEY` environment variables are set for full functionality, though StatsD will default to localhost:8125."},"warnings":[{"fix":"Update imports from `from flask.ext.datadog import ...` to `from flask_datadog import ...`.","message":"The `flask.ext` import mechanism, commonly shown in older `flask-datadog` examples, is deprecated since Flask 0.11 and removed in Flask 1.0. Attempting to use it with modern Flask will result in an `ImportError` or `ModuleNotFoundError`.","severity":"deprecated","affected_versions":"< Flask 1.0"},{"fix":"Consider migrating to `ddtrace` for new projects or enhanced monitoring. If sticking with `flask-datadog`, understand its limited scope to DogStatsD and basic API calls, and that it may not be compatible with newer Flask features or Python versions without manual intervention.","message":"`flask-datadog` is an older library (last updated 2017) primarily for StatsD metrics. For comprehensive Datadog integration, including APM, distributed tracing, and advanced logging, Datadog officially recommends using the `ddtrace` library with its automated instrumentation for Flask applications.","severity":"gotcha","affected_versions":"All versions"}],"env_vars":null,"last_verified":"2026-04-16T00:00:00.000Z","next_check":"2026-07-15T00:00:00.000Z","problems":[{"fix":"Change your import statement from `from flask.ext.datadog import ...` to `from flask_datadog import ...`.","cause":"You are attempting to import `flask_datadog` using the deprecated `flask.ext` namespace, which was removed in Flask 1.0.","error":"ModuleNotFoundError: No module named 'flask.ext.datadog'"},{"fix":"Ensure the Datadog Agent is installed and running, and that its DogStatsD port (default 8125) is open and reachable from your Flask application. Verify `app.config['STATSD_HOST']` and `app.config['STATSD_PORT']` are correctly set.","cause":"The Datadog Agent's DogStatsD server is not running or is not accessible at the configured `STATSD_HOST` and `STATSD_PORT`.","error":"ConnectionRefusedError: [Errno 111] Connection refused"}]}