{"id":5174,"library":"datadog-logger","title":"DataDog Logger","description":"The datadog-logger library provides a Python logging handler designed to send log records as events to DataDog. It simplifies integrating Python application logs with DataDog's event stream for monitoring and alerting. The current version is 1.0.2, and releases are infrequent, primarily focused on maintenance and minor improvements.","status":"active","version":"1.0.2","language":"en","source_language":"en","source_url":"https://github.com/justiniso/datadog-logger","tags":["logging","datadog","observability","events"],"install":[{"cmd":"pip install datadog-logger","lang":"bash","label":"Install stable version"}],"dependencies":[{"reason":"Used for making HTTP requests to the DataDog API.","package":"requests","optional":false},{"reason":"Used for formatting log records into JSON format before sending.","package":"python-json-logger","optional":false}],"imports":[{"symbol":"DataDogHandler","correct":"from datadog_logger import DataDogHandler"}],"quickstart":{"code":"import logging\nimport os\nfrom datadog_logger import DataDogHandler\n\n# Configure your DataDog API and APP keys\nDD_API_KEY = os.environ.get('DATADOG_API_KEY', 'YOUR_DATADOG_API_KEY')\nDD_APP_KEY = os.environ.get('DATADOG_APP_KEY', 'YOUR_DATADOG_APP_KEY')\n\n# Set up a standard Python logger\nlogger = logging.getLogger(__name__)\nlogger.setLevel(logging.INFO)\n\n# Configure the DataDogHandler\n# For production, set a meaningful hostname and tags\ndatadog_handler = DataDogHandler(\n    api_key=DD_API_KEY,\n    app_key=DD_APP_KEY,\n    hostname='my_application_host',\n    tags=['env:dev', 'service:example-app']\n)\n\n# Add the handler to your logger\nlogger.addHandler(datadog_handler)\n\n# Log some messages\nlogger.info('Application started successfully.')\nlogger.warning('Potential issue detected in module X.',\n               extra={'user_id': 456, 'module': 'auth'})\nlogger.error('Critical error: Database connection failed!')\n","lang":"python","description":"This quickstart demonstrates how to set up a `DataDogHandler` and integrate it with a standard Python `logging` instance. It configures the handler with API/APP keys, a hostname, and custom tags. Remember to replace placeholder keys with actual DataDog credentials, ideally loaded from environment variables."},"warnings":[{"fix":"Understand the distinction: 'Events' are for notifications/alerts, 'Logs' are for detailed log aggregation. Use this library if you explicitly want DataDog Events for your logs.","message":"This library sends log records as DataDog *Events*, not DataDog *Logs*. If you intend to use DataDog's Log Management, you will need a different integration (e.g., DataDog Agent or `datadog-api-client` for Logs API).","severity":"gotcha","affected_versions":"All versions"},{"fix":"Ensure `api_key` and `app_key` parameters are correctly configured with your DataDog credentials. Load them from secure sources like environment variables or a configuration management system, not hardcoded.","message":"DataDog API Key and APP Key are mandatory for authentication. Without valid keys, the handler will fail to send events to DataDog.","severity":"gotcha","affected_versions":"All versions"},{"fix":"Initialize `DataDogHandler` with `buffer_size` greater than 1 (e.g., `buffer_size=50`) to buffer events and send them in batches. This introduces a slight delay but can significantly reduce network calls and improve performance.","message":"By default, `DataDogHandler` sends events synchronously (buffer_size=1). For high-volume logging, this can impact application performance. Events are flushed upon each log call.","severity":"gotcha","affected_versions":"All versions"},{"fix":"Always provide a meaningful `hostname` and a list of descriptive `tags` (e.g., `['env:prod', 'service:api']`) during handler initialization to ensure proper indexing and discoverability in DataDog.","message":"Omitting `hostname` or relevant `tags` can make it difficult to filter and analyze events effectively within DataDog.","severity":"gotcha","affected_versions":"All versions"},{"fix":"If upgrading from an older version, review the GitHub repository's commit history around 1.0.0 for specific changes and adapt your code accordingly. The current API (1.x.x) is stable.","message":"Version 1.0.0 introduced a significant rewrite, including the removal of the `python-logstash-logger` dependency and improvements to error handling and tag support. Users upgrading from pre-1.0.0 versions will likely encounter breaking changes.","severity":"breaking","affected_versions":"<1.0.0 to >=1.0.0"}],"env_vars":null,"last_verified":"2026-04-13T00:00:00.000Z","next_check":"2026-07-12T00:00:00.000Z"}