Skip to content

Instantly share code, notes, and snippets.

@xen0l
Created May 12, 2022 13:47
Show Gist options
  • Save xen0l/0b8e42afb0f705803bbf5c668ef2dac2 to your computer and use it in GitHub Desktop.
Save xen0l/0b8e42afb0f705803bbf5c668ef2dac2 to your computer and use it in GitHub Desktop.
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