Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Appearance settings

Commit e05d132

Browse filesBrowse files
fix: instrumentation entries should not contain user labels (#703)
1 parent 5361a70 commit e05d132
Copy full SHA for e05d132

File tree

Expand file treeCollapse file tree

2 files changed

+20
-2
lines changed
Filter options
Expand file treeCollapse file tree

2 files changed

+20
-2
lines changed

‎google/cloud/logging_v2/_instrumentation.py

Copy file name to clipboardExpand all lines: google/cloud/logging_v2/_instrumentation.py
+4-2Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -67,8 +67,10 @@ def _create_diagnostic_entry(name=_PYTHON_LIBRARY_NAME, version=_LIBRARY_VERSION
6767
_INSTRUMENTATION_SOURCE_KEY: [_get_instrumentation_source(name, version)]
6868
}
6969
}
70-
kw["severity"] = "INFO"
71-
entry = StructEntry(payload=payload, **kw)
70+
# only keep the log_name and resource from the parent log
71+
allow_list = ("log_name", "resource")
72+
active_kws = {k: v for k, v in kw.items() if k in allow_list}
73+
entry = StructEntry(payload=payload, **active_kws)
7274
return entry
7375

7476

‎tests/unit/test__instrumentation.py

Copy file name to clipboardExpand all lines: tests/unit/test__instrumentation.py
+16Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -63,3 +63,19 @@ def test_truncate_long_values(self):
6363

6464
self.assertEqual(expected_name, self._get_diagonstic_value(entry, "name"))
6565
self.assertEqual(expected_version, self._get_diagonstic_value(entry, "version"))
66+
67+
def test_drop_labels(self):
68+
"""Labels should not be copied in instrumentation log"""
69+
test_logname = "test-name"
70+
test_labels = {"hello": "world"}
71+
entry = i._create_diagnostic_entry(
72+
name=self.LONG_NAME,
73+
version=self.LONG_VERSION,
74+
log_name=test_logname,
75+
labels=test_labels,
76+
)
77+
self.assertEqual(entry.log_name, test_logname)
78+
self.assertIsNone(entry.labels)
79+
# ensure only expected fields exist in entry
80+
expected_keys = set(["logName", "resource", "jsonPayload"])
81+
self.assertEqual(set(entry.to_api_repr().keys()), expected_keys)

0 commit comments

Comments
0 (0)
Morty Proxy This is a proxified and sanitized view of the page, visit original site.