Created
May 12, 2022 13:47
-
-
Save xen0l/0b8e42afb0f705803bbf5c668ef2dac2 to your computer and use it in GitHub Desktop.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
def send_log_to_datadog(data, dd_api_token, ingestion_endpoint=LOG_INGESTION_ENDPOINT): | |
try: | |
req = requests.request( | |
"POST", | |
"https://{url}/v1/input".format(url=ingestion_endpoint), | |
headers={"Content-Type": "application/json", "DD-API-KEY": dd_api_token}, | |
json=data, | |
) | |
req.raise_for_status() | |
except requests.exceptions.HTTPError as err: | |
print("HTTP Error:", err) | |
except requests.exceptions.ConnectionError as err: | |
print("Error while connecting:", err) | |
except requests.exceptions.Timeout as err: | |
print("Request timed out:", err) | |
except requests.exceptions.RequestException as err: | |
print("Error while sending logs:", err) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment