Skip to content

Commit 0c18474

Browse files
fix(exporter): convert body to str as fallback
1 parent db2dd1e commit 0c18474

File tree

3 files changed

+8
-2
lines changed

3 files changed

+8
-2
lines changed

Diff for: CHANGELOG.md

+2
Original file line numberDiff line numberDiff line change
@@ -17,6 +17,8 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0
1717
([#4494](https://github.com/open-telemetry/opentelemetry-python/pull/4494))
1818
- Improve CI by cancelling stale runs and setting timeouts
1919
([#4498](https://github.com/open-telemetry/opentelemetry-python/pull/4498))
20+
- Fix logging of objects which are convertible to strings
21+
([#4510](https://github.com/open-telemetry/opentelemetry-python/pull/4510))
2022

2123
## Version 1.31.0/0.52b0 (2025-03-12)
2224

Diff for: exporter/opentelemetry-exporter-otlp-proto-common/src/opentelemetry/exporter/otlp/proto/common/_internal/__init__.py

+5-1
Original file line numberDiff line numberDiff line change
@@ -70,7 +70,9 @@ def _encode_resource(resource: Resource) -> PB2Resource:
7070

7171

7272
def _encode_value(
73-
value: Any, allow_null: bool = False
73+
value: Any,
74+
allow_null: bool = False,
75+
fallback: Optional[Callable[[Any], Any]] = None,
7476
) -> Optional[PB2AnyValue]:
7577
if allow_null is True and value is None:
7678
return None
@@ -99,6 +101,8 @@ def _encode_value(
99101
]
100102
)
101103
)
104+
elif fallback is not None:
105+
return _encode_value(fallback(value), allow_null)
102106
raise Exception(f"Invalid type {type(value)} of value {value}")
103107

104108

Diff for: exporter/opentelemetry-exporter-otlp-proto-common/src/opentelemetry/exporter/otlp/proto/common/_internal/_log_encoder/__init__.py

+1-1
Original file line numberDiff line numberDiff line change
@@ -55,7 +55,7 @@ def _encode_log(log_data: LogData) -> PB2LogRecord:
5555
span_id=span_id,
5656
trace_id=trace_id,
5757
flags=int(log_data.log_record.trace_flags),
58-
body=_encode_value(body, allow_null=True),
58+
body=_encode_value(body, allow_null=True, fallback=str),
5959
severity_text=log_data.log_record.severity_text,
6060
attributes=_encode_attributes(log_data.log_record.attributes),
6161
dropped_attributes_count=log_data.log_record.dropped_attributes,

0 commit comments

Comments
 (0)