Skip to content

Commit 5fffd7f

Browse files
authored
Do not write a warning log when LogRecord.body is None (#427)
* Dont log when LogRecord.body is None * Fix snapshot
1 parent 2e50b5a commit 5fffd7f

File tree

3 files changed

+26
-6
lines changed

3 files changed

+26
-6
lines changed

opentelemetry-exporter-gcp-logging/src/opentelemetry/exporter/cloud_logging/__init__.py

Lines changed: 1 addition & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -112,9 +112,6 @@ def _convert_any_value_to_string(value: Any) -> str:
112112
return str(value)
113113
if isinstance(value, (list, tuple)):
114114
return json.dumps(value)
115-
logging.warning(
116-
"Unknown value %s found, cannot convert to string.", type(value)
117-
)
118115
return ""
119116

120117

@@ -158,7 +155,7 @@ def _set_payload_in_log_entry(log_entry: LogEntry, body: AnyValue):
158155
log_entry.json_payload = struct
159156
else:
160157
log_entry.text_payload = base64.b64encode(body).decode()
161-
else:
158+
elif body is not None:
162159
log_entry.text_payload = _convert_any_value_to_string(body)
163160

164161

Original file line numberDiff line numberDiff line change
@@ -0,0 +1,19 @@
1+
[
2+
{
3+
"entries": [
4+
{
5+
"logName": "projects/fakeproject/logs/test",
6+
"resource": {
7+
"labels": {
8+
"location": "global",
9+
"namespace": "",
10+
"node_id": ""
11+
},
12+
"type": "generic_node"
13+
},
14+
"timestamp": "2025-01-15T21:25:10.997977393Z"
15+
}
16+
],
17+
"partialSuccess": true
18+
}
19+
]

opentelemetry-exporter-gcp-logging/tests/test_cloud_logging.py

Lines changed: 6 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -155,12 +155,16 @@ def test_convert_non_json_dict_bytes(
155155

156156
@pytest.mark.parametrize(
157157
"body",
158-
[pytest.param("A text body", id="str"), pytest.param(True, id="bool")],
158+
[
159+
pytest.param("A text body", id="str"),
160+
pytest.param(True, id="bool"),
161+
pytest.param(None, id="None"),
162+
],
159163
)
160164
def test_convert_various_types_of_bodies(
161165
cloudloggingfake: CloudLoggingFake,
162166
snapshot_writelogentrycalls: List[WriteLogEntriesCall],
163-
body: Union[str, bool],
167+
body: Union[str, bool, None],
164168
) -> None:
165169
log_data = [
166170
LogData(

0 commit comments

Comments
 (0)