Skip to content

Commit 7edfc86

Browse files
Add missing scope field in the log formatter
1 parent 30dc196 commit 7edfc86

File tree

2 files changed

+8
-2
lines changed

2 files changed

+8
-2
lines changed

src/snowflake/telemetry/logs/__init__.py

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -34,12 +34,15 @@
3434
"threadName",
3535
"taskName",
3636
# Params that Snowflake will populate and don't want users of this API to overwrite.
37+
"body",
3738
"code.lineno",
3839
"code.function",
3940
"code.filepath",
4041
"exception.type",
4142
"exception.message",
4243
"exception.stacktrace",
44+
"scope",
45+
"severity_text",
4346
)
4447
)
4548

@@ -75,6 +78,7 @@ def get_severity_text(py_level_name):
7578

7679
def format(self, record: logging.LogRecord) -> str:
7780
log_items = {
81+
"scope": record.name,
7882
"body": record.getMessage(),
7983
"severity_text": self.get_severity_text(record.levelname),
8084
"code.lineno": record.lineno,

tests/test_snowflake_log_formatter.py

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -20,6 +20,7 @@ def test_normal_log(self):
2020
""" Does the logger produce the correct output? """
2121
self.root_logger.warning('foo', extra={"test": 123, "code.lineno": 35})
2222
expected_log_message = {
23+
"scope": "test",
2324
"body": "foo",
2425
"severity_text": "WARN",
2526
"code.lineno": 21,
@@ -39,17 +40,18 @@ def test_exception_log(self):
3940
self.root_logger.exception("\"test exception\"")
4041

4142
expected_log_message = {
43+
"scope": "test",
4244
"body": "\"test exception\"",
4345
"severity_text": "ERROR",
44-
"code.lineno": 39,
46+
"code.lineno": 40,
4547
"code.function": "test_exception_log",
4648
"exception.type": "ZeroDivisionError",
4749
"exception.message": "division by zero",
4850
}
4951
actual_log_message = json.loads(self.stream.getvalue(), strict=False)
5052
actual_log_message.pop("code.filepath")
5153
actual_stacktrace = actual_log_message.pop("exception.stacktrace")
52-
self.assertIn("line 37, in test_exception_log\n", actual_stacktrace)
54+
self.assertIn("line 38, in test_exception_log\n", actual_stacktrace)
5355
self.assertIn("ZeroDivisionError: division by zero\n", actual_stacktrace)
5456
self.assertEqual(expected_log_message, actual_log_message)
5557

0 commit comments

Comments
 (0)