Registry / observability / flask-datadog

flask-datadog

JSON →
library0.1.4pypypi✓ verified 86d ago

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.

pip install Flask-Datadog
INSTALL
IMPORT
SIG · FLASK-DATADOG
F
flask-datadog
observabilitypythonv0.1.4
Install
3.9s avg
Import
1070ms
Disk
27MB
Pass rate
10/ 10
Env Coverage10 / 10
glibc
3.93.13
musl
3.93.13
Install & Compatibility
Where this runs
tested against v0.1.4 · pip install
no network on importno background threads
Install × environment matrix
Each cell = how many times install + import succeeded across repeated harness runs. Partial = flaky.
glibc = Debian/Ubuntu slim · musl = Alpine Linux
musl
py 3.103.920 runs
installs and imports cleanly · install 0.0s · import 1.116s · 28.4MB
glibc
py 3.103.920 runs
installs and imports cleanly · install 3.9s · import 1.025s · 29MB
27MB installed
● package 27MB
Code
Verified usage

Verified import paths — ran on the pinned version, not inferred.

API
from flask_datadog import API
StatsD
from flask_datadog import StatsD
from flask.ext.datadog import StatsD
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.

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.

from flask import Flask from flask_datadog import API, StatsD import os app = Flask(__name__) # Configure Datadog API and StatsD settings app.config['STATSD_HOST'] = os.environ.get('DATADOG_STATSD_HOST', 'localhost') app.config['STATSD_PORT'] = int(os.environ.get('DATADOG_STATSD_PORT', '8125')) app.config['DATADOG_API_KEY'] = os.environ.get('DATADOG_API_KEY', '') app.config['DATADOG_APP_KEY'] = os.environ.get('DATADOG_APP_KEY', '') statsd = StatsD(app) dogapi = API(app) @app.route('/') def hello(): statsd.increment('my_flask_app.requests') return 'Hello, Datadog!' @app.route('/error') def error_route(): statsd.increment('my_flask_app.errors') # Example of API usage (requires valid API/App keys) # if dogapi.api_key and dogapi.app_key: # dogapi.Event.create('An error occurred in Flask app', # tags=['env:dev', 'service:my-app']) raise Exception('This is a test error!') if __name__ == '__main__': # Ensure the Datadog Agent is running and accessible at STATSD_HOST:STATSD_PORT # For API calls, ensure DATADOG_API_KEY and DATADOG_APP_KEY are set. app.run(debug=True)
Debug
Known issues
deprecatedThe `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`.
fix
Update imports from `from flask.ext.datadog import ...` to `from flask_datadog import ...`.
affects: < Flask 1.0
gotcha`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.
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.
affects: All versions
Errors
Common errors & fixes
ModuleNotFoundError: No module named 'flask.ext.datadog'
You are attempting to import `flask_datadog` using the deprecated `flask.ext` namespace, which was removed in Flask 1.0.
fix
Change your import statement from `from flask.ext.datadog import ...` to `from flask_datadog import ...`.
ConnectionRefusedError: [Errno 111] Connection refused
The Datadog Agent's DogStatsD server is not running or is not accessible at the configured `STATSD_HOST` and `STATSD_PORT`.
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.
Upgrade
Version history
0.1.4latest on PyPI · released Jan 16, 2017
Audit
Dependencies
FlaskrequiredCore web framework integration.
datadogrequiredProvides the underlying DogStatsD and Datadog API client functionality.
Agent activity
14 hits · last 30 days
node
12
OpenAI (training)
2
Resources
flask-datadog — pip install flask-datadog · libregistry