Skip to content

Commit a2179ba

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

File tree

2 files changed

+6
-2
lines changed
  • exporter/opentelemetry-exporter-otlp-proto-common/src/opentelemetry/exporter/otlp/proto/common/_internal

2 files changed

+6
-2
lines changed

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)