# Datadog Async Handler
[](https://badge.fury.io/py/datadog-async-handler)
[](https://pypi.org/project/datadog-async-handler/)
[](https://opensource.org/licenses/MIT)
[](https://github.com/astral-sh/ruff)
A modern, high-performance Python logging handler that sends logs directly to Datadog via HTTP API with asynchronous batching, retry logic, and comprehensive error handling.
## ✨ Features
- **🚀 High Performance**: Asynchronous batching and background processing
- **🔄 Reliable Delivery**: Automatic retry with exponential backoff
- **📊 Batching**: Configurable batch size and flush intervals
- **🏷️ Rich Metadata**: Automatic service, environment, and custom tag support
- **🔧 Easy Integration**: Drop-in replacement for standard logging handlers
- **🌐 Multi-Site Support**: Works with all Datadog sites (US, EU, etc.)
- **📝 Type Safe**: Full type hints and mypy compatibility
- **⚡ Modern**: Built with Python 3.9+ and latest best practices
## 🚀 Quick Start
### Installation
```bash
pip install datadog-async-handler
```
### Basic Usage
```python
import logging
from datadog_http_handler import DatadogHTTPHandler
# Configure the handler
handler = DatadogHTTPHandler(
api_key="your-datadog-api-key", # or set DD_API_KEY env var
service="my-application",
source="python",
tags="env:production,team:backend"
)
# Set up logging
logger = logging.getLogger(__name__)
logger.addHandler(handler)
logger.setLevel(logging.INFO)
# Start logging!
logger.info("Application started successfully", extra={
"user_id": "12345",
"action": "startup"
})
```
### Environment Variables
The handler automatically picks up standard Datadog environment variables:
```bash
export DD_API_KEY="your-api-key"
export DD_SERVICE="my-application"
export DD_ENV="production"
export DD_VERSION="1.2.3"
export DD_TAGS="team:backend,component:api"
export DD_SITE="datadoghq.com" # or datadoghq.eu, ddog-gov.com, etc.
```
## 📖 Documentation
### Configuration Options
| Parameter | Type | Default | Description |
|-----------|------|---------|-------------|
| `api_key` | `str` | `None` | Datadog API key (required) |
| `site` | `str` | `"datadoghq.com"` | Datadog site |
| `service` | `str` | `None` | Service name |
| `source` | `str` | `"python"` | Log source |
| `hostname` | `str` | `None` | Hostname |
| `tags` | `str` | `None` | Comma-separated tags |
| `batch_size` | `int` | `10` | Number of logs per batch |
| `flush_interval_seconds` | `float` | `5.0` | Batch flush interval |
| `timeout_seconds` | `float` | `10.0` | Request timeout |
| `max_retries` | `int` | `3` | Maximum retry attempts |
### Framework Integration Examples
#### Django
```python
# settings.py
LOGGING = {
'version': 1,
'disable_existing_loggers': False,
'handlers': {
'datadog': {
'class': 'datadog_http_handler.DatadogHTTPHandler',
'api_key': 'your-api-key',
'service': 'django-app',
'source': 'django',
},
},
'root': {
'handlers': ['datadog'],
'level': 'INFO',
},
}
```
#### FastAPI
```python
import logging
from fastapi import FastAPI
from datadog_http_handler import DatadogHTTPHandler
app = FastAPI()
# Configure logging
handler = DatadogHTTPHandler(service="fastapi-app", source="fastapi")
logging.getLogger().addHandler(handler)
logging.getLogger().setLevel(logging.INFO)
@app.get("/")
async def root():
logging.info("API endpoint called", extra={"endpoint": "/"})
return {"message": "Hello World"}
```
#### Flask
```python
import logging
from flask import Flask
from datadog_http_handler import DatadogHTTPHandler
app = Flask(__name__)
# Configure logging
handler = DatadogHTTPHandler(service="flask-app", source="flask")
app.logger.addHandler(handler)
app.logger.setLevel(logging.INFO)
@app.route("/")
def hello():
app.logger.info("Flask endpoint called", extra={"endpoint": "/"})
return "Hello World!"
```
## 🔧 Development
### Setup
```bash
# Clone the repository
git clone https://github.com/enlyft/datadog-http-handler.git
cd datadog-http-handler
# Install UV (modern Python package manager)
curl -LsSf https://astral.sh/uv/install.sh | sh
# Install dependencies
uv pip install -e ".[dev]"
# Install pre-commit hooks
pre-commit install
```
### Running Tests
```bash
# Run all tests
hatch run test
# Run with coverage
hatch run test-cov
# Run specific tests
hatch run test tests/test_handler.py::test_basic_logging
```
### Code Quality
```bash
# Format code
hatch run format
# Lint code
hatch run lint
# Type checking
hatch run type-check
# Run all checks
hatch run all
```
## 🤝 Contributing
We welcome contributions! Please see our [Contributing Guide](CONTRIBUTING.md) for details.
1. Fork the repository
2. Create a feature branch
3. Make your changes
4. Add tests
5. Run the test suite
6. Submit a pull request
## 📋 Requirements
- Python 3.9+
- `datadog-api-client>=2.0.0`
## 📄 License
This project is licensed under the MIT License - see the [LICENSE](LICENSE) file for details.
## 🔗 Links
- [Documentation](https://enlyft.github.io/datadog-http-handler)
- [PyPI Package](https://pypi.org/project/datadog-async-handler/)
- [GitHub Repository](https://github.com/enlyft/datadog-http-handler)
- [Issue Tracker](https://github.com/enlyft/datadog-http-handler/issues)
- [Datadog Logs API Documentation](https://docs.datadoghq.com/api/latest/logs/)
## 🆚 Comparison with Other Solutions
| Feature | datadog-async-handler | datadog-http-handler | python-datadog | datadog-logger |
|---------|----------------------|---------------------|----------------|----------------|
| Async Batching | ✅ | ❌ | ❌ | ❌ |
| Retry Logic | ✅ | ❌ | ❌ | ❌ |
| Type Hints | ✅ | ❌ | ❌ | ❌ |
| Modern Python | ✅ (3.9+) | ❌ (3.6+) | ❌ (2.7+) | ❌ (3.6+) |
| Official API Client | ✅ | ❌ | ❌ | ❌ |
| Background Processing | ✅ | ❌ | ❌ | ❌ |
| Memory Efficient | ✅ | ❌ | ❌ | ❌ |
| Active Maintenance | ✅ | ❌ (2019) | ✅ | ❌ |
| Comprehensive Tests | ✅ | ❌ | ✅ | ❌ |
---
Made with ❤️ for the Python and Datadog communities.
Raw data
{
"_id": null,
"home_page": null,
"name": "datadog-async-handler",
"maintainer": null,
"docs_url": null,
"requires_python": ">=3.9",
"maintainer_email": "Parth <parth@enlyft.com>",
"keywords": "async, batching, datadog, handler, logging, observability",
"author": null,
"author_email": "Parth <parth@enlyft.com>",
"download_url": "https://files.pythonhosted.org/packages/e7/67/6357799576c28f8374f7178edc84efc746e574321276a5e0a3de3d4f7cee/datadog_async_handler-0.1.2.tar.gz",
"platform": null,
"description": "# Datadog Async Handler\n\n[](https://badge.fury.io/py/datadog-async-handler)\n[](https://pypi.org/project/datadog-async-handler/)\n[](https://opensource.org/licenses/MIT)\n[](https://github.com/astral-sh/ruff)\n\nA modern, high-performance Python logging handler that sends logs directly to Datadog via HTTP API with asynchronous batching, retry logic, and comprehensive error handling.\n\n## \u2728 Features\n\n- **\ud83d\ude80 High Performance**: Asynchronous batching and background processing\n- **\ud83d\udd04 Reliable Delivery**: Automatic retry with exponential backoff\n- **\ud83d\udcca Batching**: Configurable batch size and flush intervals\n- **\ud83c\udff7\ufe0f Rich Metadata**: Automatic service, environment, and custom tag support\n- **\ud83d\udd27 Easy Integration**: Drop-in replacement for standard logging handlers\n- **\ud83c\udf10 Multi-Site Support**: Works with all Datadog sites (US, EU, etc.)\n- **\ud83d\udcdd Type Safe**: Full type hints and mypy compatibility\n- **\u26a1 Modern**: Built with Python 3.9+ and latest best practices\n\n## \ud83d\ude80 Quick Start\n\n### Installation\n\n```bash\npip install datadog-async-handler\n```\n\n### Basic Usage\n\n```python\nimport logging\nfrom datadog_http_handler import DatadogHTTPHandler\n\n# Configure the handler\nhandler = DatadogHTTPHandler(\n api_key=\"your-datadog-api-key\", # or set DD_API_KEY env var\n service=\"my-application\",\n source=\"python\",\n tags=\"env:production,team:backend\"\n)\n\n# Set up logging\nlogger = logging.getLogger(__name__)\nlogger.addHandler(handler)\nlogger.setLevel(logging.INFO)\n\n# Start logging!\nlogger.info(\"Application started successfully\", extra={\n \"user_id\": \"12345\",\n \"action\": \"startup\"\n})\n```\n\n### Environment Variables\n\nThe handler automatically picks up standard Datadog environment variables:\n\n```bash\nexport DD_API_KEY=\"your-api-key\"\nexport DD_SERVICE=\"my-application\"\nexport DD_ENV=\"production\"\nexport DD_VERSION=\"1.2.3\"\nexport DD_TAGS=\"team:backend,component:api\"\nexport DD_SITE=\"datadoghq.com\" # or datadoghq.eu, ddog-gov.com, etc.\n```\n\n## \ud83d\udcd6 Documentation\n\n### Configuration Options\n\n| Parameter | Type | Default | Description |\n|-----------|------|---------|-------------|\n| `api_key` | `str` | `None` | Datadog API key (required) |\n| `site` | `str` | `\"datadoghq.com\"` | Datadog site |\n| `service` | `str` | `None` | Service name |\n| `source` | `str` | `\"python\"` | Log source |\n| `hostname` | `str` | `None` | Hostname |\n| `tags` | `str` | `None` | Comma-separated tags |\n| `batch_size` | `int` | `10` | Number of logs per batch |\n| `flush_interval_seconds` | `float` | `5.0` | Batch flush interval |\n| `timeout_seconds` | `float` | `10.0` | Request timeout |\n| `max_retries` | `int` | `3` | Maximum retry attempts |\n\n### Framework Integration Examples\n\n#### Django\n\n```python\n# settings.py\nLOGGING = {\n 'version': 1,\n 'disable_existing_loggers': False,\n 'handlers': {\n 'datadog': {\n 'class': 'datadog_http_handler.DatadogHTTPHandler',\n 'api_key': 'your-api-key',\n 'service': 'django-app',\n 'source': 'django',\n },\n },\n 'root': {\n 'handlers': ['datadog'],\n 'level': 'INFO',\n },\n}\n```\n\n#### FastAPI\n\n```python\nimport logging\nfrom fastapi import FastAPI\nfrom datadog_http_handler import DatadogHTTPHandler\n\napp = FastAPI()\n\n# Configure logging\nhandler = DatadogHTTPHandler(service=\"fastapi-app\", source=\"fastapi\")\nlogging.getLogger().addHandler(handler)\nlogging.getLogger().setLevel(logging.INFO)\n\n@app.get(\"/\")\nasync def root():\n logging.info(\"API endpoint called\", extra={\"endpoint\": \"/\"})\n return {\"message\": \"Hello World\"}\n```\n\n#### Flask\n\n```python\nimport logging\nfrom flask import Flask\nfrom datadog_http_handler import DatadogHTTPHandler\n\napp = Flask(__name__)\n\n# Configure logging\nhandler = DatadogHTTPHandler(service=\"flask-app\", source=\"flask\")\napp.logger.addHandler(handler)\napp.logger.setLevel(logging.INFO)\n\n@app.route(\"/\")\ndef hello():\n app.logger.info(\"Flask endpoint called\", extra={\"endpoint\": \"/\"})\n return \"Hello World!\"\n```\n\n## \ud83d\udd27 Development\n\n### Setup\n\n```bash\n# Clone the repository\ngit clone https://github.com/enlyft/datadog-http-handler.git\ncd datadog-http-handler\n\n# Install UV (modern Python package manager)\ncurl -LsSf https://astral.sh/uv/install.sh | sh\n\n# Install dependencies\nuv pip install -e \".[dev]\"\n\n# Install pre-commit hooks\npre-commit install\n```\n\n### Running Tests\n\n```bash\n# Run all tests\nhatch run test\n\n# Run with coverage\nhatch run test-cov\n\n# Run specific tests\nhatch run test tests/test_handler.py::test_basic_logging\n```\n\n### Code Quality\n\n```bash\n# Format code\nhatch run format\n\n# Lint code\nhatch run lint\n\n# Type checking\nhatch run type-check\n\n# Run all checks\nhatch run all\n```\n\n## \ud83e\udd1d Contributing\n\nWe welcome contributions! Please see our [Contributing Guide](CONTRIBUTING.md) for details.\n\n1. Fork the repository\n2. Create a feature branch\n3. Make your changes\n4. Add tests\n5. Run the test suite\n6. Submit a pull request\n\n## \ud83d\udccb Requirements\n\n- Python 3.9+\n- `datadog-api-client>=2.0.0`\n\n## \ud83d\udcc4 License\n\nThis project is licensed under the MIT License - see the [LICENSE](LICENSE) file for details.\n\n## \ud83d\udd17 Links\n\n- [Documentation](https://enlyft.github.io/datadog-http-handler)\n- [PyPI Package](https://pypi.org/project/datadog-async-handler/)\n- [GitHub Repository](https://github.com/enlyft/datadog-http-handler)\n- [Issue Tracker](https://github.com/enlyft/datadog-http-handler/issues)\n- [Datadog Logs API Documentation](https://docs.datadoghq.com/api/latest/logs/)\n\n## \ud83c\udd9a Comparison with Other Solutions\n\n| Feature | datadog-async-handler | datadog-http-handler | python-datadog | datadog-logger |\n|---------|----------------------|---------------------|----------------|----------------|\n| Async Batching | \u2705 | \u274c | \u274c | \u274c |\n| Retry Logic | \u2705 | \u274c | \u274c | \u274c |\n| Type Hints | \u2705 | \u274c | \u274c | \u274c |\n| Modern Python | \u2705 (3.9+) | \u274c (3.6+) | \u274c (2.7+) | \u274c (3.6+) |\n| Official API Client | \u2705 | \u274c | \u274c | \u274c |\n| Background Processing | \u2705 | \u274c | \u274c | \u274c |\n| Memory Efficient | \u2705 | \u274c | \u274c | \u274c |\n| Active Maintenance | \u2705 | \u274c (2019) | \u2705 | \u274c |\n| Comprehensive Tests | \u2705 | \u274c | \u2705 | \u274c |\n\n---\n\nMade with \u2764\ufe0f for the Python and Datadog communities.",
"bugtrack_url": null,
"license": null,
"summary": "High-performance async HTTP logging handler for Datadog with batching and retry logic",
"version": "0.1.2",
"project_urls": {
"Bug Tracker": "https://github.com/enlyft/datadog-http-handler/issues",
"Changelog": "https://github.com/enlyft/datadog-http-handler/blob/main/CHANGELOG.md",
"Documentation": "https://enlyft.github.io/datadog-http-handler",
"Homepage": "https://github.com/enlyft/datadog-http-handler",
"Repository": "https://github.com/enlyft/datadog-http-handler.git"
},
"split_keywords": [
"async",
" batching",
" datadog",
" handler",
" logging",
" observability"
],
"urls": [
{
"comment_text": null,
"digests": {
"blake2b_256": "c36eebc0b74ff944e80333a081af1db910af1672edf13605bb68335d1befbb6a",
"md5": "164d91cd6bf7f1188a9e62653fdcc39e",
"sha256": "c851536085018c78a75a614cd012968138bbcc8a57409add2cd2cfff8d35954d"
},
"downloads": -1,
"filename": "datadog_async_handler-0.1.2-py3-none-any.whl",
"has_sig": false,
"md5_digest": "164d91cd6bf7f1188a9e62653fdcc39e",
"packagetype": "bdist_wheel",
"python_version": "py3",
"requires_python": ">=3.9",
"size": 9049,
"upload_time": "2025-08-25T21:29:28",
"upload_time_iso_8601": "2025-08-25T21:29:28.621512Z",
"url": "https://files.pythonhosted.org/packages/c3/6e/ebc0b74ff944e80333a081af1db910af1672edf13605bb68335d1befbb6a/datadog_async_handler-0.1.2-py3-none-any.whl",
"yanked": false,
"yanked_reason": null
},
{
"comment_text": null,
"digests": {
"blake2b_256": "e7676357799576c28f8374f7178edc84efc746e574321276a5e0a3de3d4f7cee",
"md5": "cefffd0d87a56ba41a1346963ae1dfef",
"sha256": "4d00e72317356733c6107b5f05e4be50b59f66441fb1622025fc42f92a584ec3"
},
"downloads": -1,
"filename": "datadog_async_handler-0.1.2.tar.gz",
"has_sig": false,
"md5_digest": "cefffd0d87a56ba41a1346963ae1dfef",
"packagetype": "sdist",
"python_version": "source",
"requires_python": ">=3.9",
"size": 117893,
"upload_time": "2025-08-25T21:29:30",
"upload_time_iso_8601": "2025-08-25T21:29:30.012982Z",
"url": "https://files.pythonhosted.org/packages/e7/67/6357799576c28f8374f7178edc84efc746e574321276a5e0a3de3d4f7cee/datadog_async_handler-0.1.2.tar.gz",
"yanked": false,
"yanked_reason": null
}
],
"upload_time": "2025-08-25 21:29:30",
"github": true,
"gitlab": false,
"bitbucket": false,
"codeberg": false,
"github_user": "enlyft",
"github_project": "datadog-http-handler",
"travis_ci": false,
"coveralls": false,
"github_actions": true,
"lcname": "datadog-async-handler"
}