Skip to content

Commit cd79aec

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

File tree

2 files changed

+14
-2
lines changed

2 files changed

+14
-2
lines changed

src/snowflake/telemetry/logs/__init__.py

Lines changed: 6 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,9 @@ def get_severity_text(py_level_name):
7578

7679
def format(self, record: logging.LogRecord) -> str:
7780
log_items = {
81+
"scope": {
82+
"name": record.name,
83+
},
7884
"body": record.getMessage(),
7985
"severity_text": self.get_severity_text(record.levelname),
8086
"code.lineno": record.lineno,

tests/test_snowflake_log_formatter.py

Lines changed: 8 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -20,6 +20,9 @@ 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": {
24+
"name": "test",
25+
},
2326
"body": "foo",
2427
"severity_text": "WARN",
2528
"code.lineno": 21,
@@ -39,17 +42,20 @@ def test_exception_log(self):
3942
self.root_logger.exception("\"test exception\"")
4043

4144
expected_log_message = {
45+
"scope": {
46+
"name": "test",
47+
},
4248
"body": "\"test exception\"",
4349
"severity_text": "ERROR",
44-
"code.lineno": 39,
50+
"code.lineno": 42,
4551
"code.function": "test_exception_log",
4652
"exception.type": "ZeroDivisionError",
4753
"exception.message": "division by zero",
4854
}
4955
actual_log_message = json.loads(self.stream.getvalue(), strict=False)
5056
actual_log_message.pop("code.filepath")
5157
actual_stacktrace = actual_log_message.pop("exception.stacktrace")
52-
self.assertIn("line 37, in test_exception_log\n", actual_stacktrace)
58+
self.assertIn("line 40, in test_exception_log\n", actual_stacktrace)
5359
self.assertIn("ZeroDivisionError: division by zero\n", actual_stacktrace)
5460
self.assertEqual(expected_log_message, actual_log_message)
5561

0 commit comments

Comments
 (0)