opentelemetry-python icon indicating copy to clipboard operation
opentelemetry-python copied to clipboard

Give a warning whenever span attribute was truncated

Open ola-gajkowska opened this issue 6 months ago • 1 comments

Is your feature request related to a problem?

I'd like my app's users to be informed whenever their span is truncated. Currently there's no warning being logged in Otel.

opentelemetry/attributes/__init__.py

Describe the solution you'd like

I'd like this method to log a warning whenever span attribute is truncated due to limitation:

def _clean_attribute_value(
    value: types.AttributeValue, limit: Optional[int]
) -> Optional[types.AttributeValue]:
    if value is None:
        return None

    if isinstance(value, bytes):
        try:
            value = value.decode()
        except UnicodeDecodeError:
            _logger.warning("Byte attribute could not be decoded.")
            return None

    if limit is not None and isinstance(value, str):
        value = value[:limit]
    return value

Describe alternatives you've considered

No response

Additional Context

No response

Would you like to implement a fix?

None

ola-gajkowska avatar May 29 '25 11:05 ola-gajkowska

I suppose one possible issue with this ask is that we can get a lot of warnings if we do it by attribute truncated, I can see there is some logging for dropped attributes, but is very generic and it doesn't even include the number of dropped attributes, also there is a filter to ensure the warning is only displayed once, so if we follow same existing pattern I'm not sure how useful will be to get a generic message saying some attribute was truncated without extra details.

hectorhdzg avatar Jun 12 '25 22:06 hectorhdzg