Open vikramsubramanian opened 3 months ago
The warning Invalid type dict for attribute 'extra' value. Expected one of ['bool', 'str', 'bytes', 'int', 'float'] or a sequence of those types
suggests that the extra
attribute of a log record, which is being passed to OpenTelemetry, is expected to be a simple type or a sequence of simple types, but a dictionary is being provided instead.
To resolve this issue, you should ensure that the extra
attribute of the log records being sent to OpenTelemetry contains only the expected types. If you need to include a dictionary, you should serialize it into a string or flatten it into multiple key-value pairs that conform to the expected types.
Here is a high-level overview of how you might modify the extra
attribute before sending it to OpenTelemetry:
Here is a pseudo-code example of how you might serialize the extra
dictionary:
import json
# Assuming log_record is the record being processed
if isinstance(log_record['extra'], dict):
log_record['extra'] = json.dumps(log_record['extra'])
And here is an example of how you might flatten the dictionary:
# Assuming log_record is the record being processed
if isinstance(log_record['extra'], dict):
for key, value in log_record['extra'].items():
if isinstance(value, (bool, str, bytes, int, float)):
log_record[f'extra_{key}'] = value
del log_record['extra'] # Remove the original 'extra' key
You would need to integrate this logic into the appropriate place in your logging pipeline, ensuring that the log records are modified before they are sent to OpenTelemetry.
When using
opentelemetry-collter
to collect logs,loguru
will throw a warning like this:Invalid type dict for attribute 'extra' value. Expected one of ['bool', 'str', 'bytes', 'int' , 'float'] or a sequence of those types
hashtaghashtag my code:
hashtaghashtag console output: ![截屏2024-01-05 17 33 40](
hashtaghashtag env:
system: macOS 14.2.1 (23C71)
)