Python logging module allowing you to log directly to Datadog via https
Project description
Python logging module allowing you to log directly to Datadog via https. Currently support only for python 3.6+.
Installation
Install python 3.7.2+
Install pip
curl https://bootstrap.pypa.io/get-pip.py -o get-pip.py
python get-pip.py
Install datadog-http-handler
pip install git+https://github.com/nrccua/datadog-http-handler.git
Usage
The typical usage of this library to output to datadog
from datadog_http_handler import DatadogHttpHandler
logger = DatadogHttpHandler(
api_key=os.getenv('DATADOG_API_KEY', ''),
service='test',
host='your_hostname',
logger_name='example',
tags={'env': 'test', 'user': 'Tim the Enchanter'}
).logger
logger.info('Hello World')
Since sending logs to datadog via http can issue in a request failure for a myriad of reasons, it would be good to know if the failure accord. By setting raise_failure=True when creating the DatadogHttpHandler object, an exception will now be thrown if the status code of the response is not 200. See below:
import traceback
from datadog_http_handler import DatadogHttpHandler
logger = DatadogHttpHandler(
api_key='your_key',
raise_exception=True,
service='test',
host='your_hostname',
logger_name='example',
tags={'env': 'test', 'user': 'Tim the Enchanter'}
).logger
try:
logger.info('Hello World')
exceptException as e:
print(traceback.format_exc())
LICENSE
ACKNOWLEDGEMENTS
Bryan Cusatis - NRCCUA Architecture Team Lead
Grant Evans - NRCCUA DevOps Engineering Lead
Project details
Download files
Download the file for your platform. If you're not sure which to choose, learn more about installing packages.
Source Distribution
Hashes for datadog-http-handler-1.0.3.tar.gz
Algorithm | Hash digest | |
---|---|---|
SHA256 | abfd2694609e40ddfc9d7e8a343fbe534cdb2bb70ac662595ef04ddd4dc74e63 |
|
MD5 | 64c5a88cd082f9962f2e178c870e3d1c |
|
BLAKE2b-256 | 99e3ad01dd13fc7bacab7a8013dc1f8931d4dd3f4e4e8ea1be308baa4c10ab76 |