Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

ERROR:__main__:'entity_id' #27

Open
maruina opened this issue Jan 12, 2025 · 5 comments
Open

ERROR:__main__:'entity_id' #27

maruina opened this issue Jan 12, 2025 · 5 comments

Comments

@maruina
Copy link

maruina commented Jan 12, 2025

Looking at the integration logs, they show this error

[...]
2025-01-12 16:48:12,900:ERROR:__main__:'entity_id'
2025-01-12 16:48:22,918:ERROR:__main__:'entity_id'
2025-01-12 16:48:32,939:ERROR:__main__:'entity_id'
2025-01-12 16:48:42,955:ERROR:__main__:'entity_id'
2025-01-12 16:48:52,973:ERROR:__main__:'entity_id'
2025-01-12 16:49:02,988:ERROR:__main__:'entity_id'
2025-01-12 16:49:13,009:ERROR:__main__:'entity_id'
2025-01-12 16:49:23,025:ERROR:__main__:'entity_id'
[...]

but as far as I can tell I'm sending metrics to Datadog.

I'm using the latest version v0.5.2

@kamaradclimber
Copy link
Owner

Thanks for the report.
It's a bit hard to know where this comes from. I assumed it started in 0.5.0+ so I'll take a wild guess. Let's see if https://github.com/kamaradclimber/datadog-integration-ha/releases/tag/0.5.3 provides more context (the exception context).

By the way, if you build your own HA image, you might be interested in adding the following patch to use json logs (to send them more easily to dd):

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.

@maruina
Copy link
Author

maruina commented Jan 12, 2025

Thanks, I updated it but I still see the same error. Scrolling back to the log lines I see a couple of entries like

2025-01-12 17:22:36,900:ERROR:__main__:Extra data: line 1 column 4 (char 3)

@kamaradclimber
Copy link
Owner

Previous attempt was simply improving a bit of logging to try to understand what happens.

My hypothesis is that the callbacks I wrote raise an error, which would explain why the error is reported in the __main__ function.
I've wrapped the callbacks to capture errors myself, let's see if https://github.com/kamaradclimber/datadog-integration-ha/releases/tag/0.5.6 gives us more details.

@maruina
Copy link
Author

maruina commented Jan 12, 2025

Thanks for the update, unfortunately I see the same log with 0.5.6

@maruina
Copy link
Author

maruina commented Jan 18, 2025

Thanks for the report. It's a bit hard to know where this comes from. I assumed it started in 0.5.0+ so I'll take a wild guess. Let's see if https://github.com/kamaradclimber/datadog-integration-ha/releases/tag/0.5.3 provides more context (the exception context).

By the way, if you build your own HA image, you might be interested in adding the following patch to use json logs (to send them more easily to dd):

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.

I'm having an hard time to find that file, I'll ping you back when I find how to change the logs :)
Still having the issue on 0.5.7

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants