Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Support Opentelemetry Proto definitions for span attributes #4380

Open
shivanshuraj1333 opened this issue Jan 6, 2025 · 3 comments
Open
Labels
bug Something isn't working

Comments

@shivanshuraj1333
Copy link
Member

shivanshuraj1333 commented Jan 6, 2025

Summary

Otel python api should support AnyValue instead of AnyAttributeValue, according to the proto definition for span attributes' value, (see KeyValue reference here)

What happened?

The trace proto definition defines span attributes to be of kind KeyValue.

KayValues supports Value of kind AnyValue

BUT,
Opentelemetry-python defines span attributes' values as types.AttributeValue, which is doesn't support AnyValue (this is the how it is defined)

The value of trace attributes should be of kind AnyValue, and not AttributeValue

This is causing the unit tests to fail in this PR open-telemetry/opentelemetry-python-contrib#3170

Steps to Reproduce

Run the unit tests in this PR open-telemetry/opentelemetry-python-contrib#3170

The PR adds map as attributes, which is supported by the proto definition of spans but not by python implementation of it https://github.com/open-telemetry/opentelemetry-python/blob/main/opentelemetry-api/src/opentelemetry/trace/span.py#L82

Expected Result

Opentelemetry python should adhere to trace proto definition as described here

So, that it can support map values as valid value in attribute values of a span, currently it doesn't support that.

Ideally https://github.com/open-telemetry/opentelemetry-python/blob/main/opentelemetry-api/src/opentelemetry/util/types.py#L21 should be used here instead of https://github.com/open-telemetry/opentelemetry-python/blob/main/opentelemetry-api/src/opentelemetry/util/types.py#L32

Actual Result

AnyValue is not sported in span attributes, and hence map values are not supported in span attributes.

Additional context

No response

Would you like to implement a fix?

None

@shivanshuraj1333 shivanshuraj1333 added the bug Something isn't working label Jan 6, 2025
@Oberon00
Copy link
Member

Oberon00 commented Jan 7, 2025

Hi, the OTLP protocol is not the primary definition of what should be allowed as attribute, the spec is. The spec does not allow map values for span attributes: https://github.com/open-telemetry/opentelemetry-specification/blob/main/specification/common/README.md#attribute

The standard attribute definition SHOULD be used to represent attributes in data modeling unless there is a strong justification to diverge.

It also calls out logs as one example where "Any" is actually the allowed attribute type, but span uses standard attributes, so IMHO opentelemetry-python behavior is correct, allowing map values would make it non-conforming.

(There were also many discussions about allowing map values, nested attributes, ... in the past in the spec if you want to research why this is the case)

@shivanshuraj1333
Copy link
Member Author

I see, thanks @Oberon00 do you know why logs are exception?
Whatever attributes are getting added to logs can also be part of span attributes.

And hence the same logic (query etc), that would work on logs attributes would not work in span attributes because the data type is now changed.

Any reasoning for this inconsistency that you are aware of?

@Oberon00
Copy link
Member

Oberon00 commented Jan 7, 2025

AFAIK because for logs the API is not defined by OTel (OTLP logs are mainly used to transport logs that were produced with some existing non-OTel logging framework) and some of these support such attribute types already. For tracing, maybe open-telemetry/opentelemetry-specification#3858 and open-telemetry/opentelemetry-specification#376 can provide explanations.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug Something isn't working
Projects
None yet
Development

No branches or pull requests

2 participants