Logging to datadog

I’m currently looking how to configure home-assistant to log in a format that would be easy to send to datadog.
Documentation seems to point out that configuring HA to write log in a json format would help.

Is there any way to configure HA in such way?

Did you get anywhere with this? My logs in Datadog are a mess at the moment, and I’m not sure if this is best fixed at the application-level by logging JSON, or in Datadog itself with pipelines.

No progress so far!

I eventually built something to support this. I tried to propose ✨ Allow to log in json format by kamaradclimber · Pull Request #110487 · home-assistant/core · GitHub but it got rejected.

However, I’ve been using a simpler version of the patch for several months with great success:

diff --git a/homeassistant/bootstrap.py b/homeassistant/bootstrap.py
index 391c6ebfa45..4249c95ee9e 100644
--- a/homeassistant/bootstrap.py
+++ b/homeassistant/bootstrap.py
@@ -544,7 +544,18 @@ def async_enable_logging(
 
     # If the above initialization failed for any reason, setup the default
     # formatting.  If the above succeeds, this will result in a no-op.
-    logging.basicConfig(format=fmt, datefmt=FORMAT_DATETIME, level=logging.INFO)
+    # custom logging setup for datadog integration
+    import json_log_formatter
+    import threading
+    from .const import __version__ as VERSION_FOR_LOGS
+    class CustomJSONFormatter(json_log_formatter.VerboseJSONFormatter):
+        def json_record(self, message, extra, record):
+            extra['version'] = VERSION_FOR_LOGS
+            return super(CustomJSONFormatter, self).json_record(message, extra, record)
+    formatter = CustomJSONFormatter()
+    json_handler = logging.StreamHandler()
+    json_handler.setFormatter(formatter)
+    logging.root.addHandler(json_handler)
 
     # Capture warnings.warn(...) and friends messages in logs.
     # The standard destination for them is stderr, which may end up unnoticed.

For non-log integration, I’ve also built GitHub - kamaradclimber/datadog-integration-ha: A better datadog integration for Home Assistant to get metrics and events sent to datadog.