open-telemetry / opentelemetry-specification

Specifications for OpenTelemetry
https://opentelemetry.io
Apache License 2.0
3.65k stars 873 forks source link

Is there a get equivalent for attributes? #755

Closed aronchick closed 3 years ago

aronchick commented 3 years ago

Hi all! I'm looking to populate all events inside the span with the attributes from the parent span - so, for example, i start a span with the set_attribute("project_id", "foo") and then I'd like to set that as an attribute in the add_event call. I get that I could do this on the backend when I pull everything apart, but it'd be much more convenient to just duplicate now. But, though there's plenty of documentation on how to "set_attribute", there's none I can find on how to "get_attribute". Any suggestions?

arminru commented 3 years ago

Hi @aronchick, no, there's no way to get span attributes from the API.

669 clarified the requirement for spans that can be read from but those are only part of the SDK on purpose and not exposed in the API.

Can you share which use case you're trying to solve by duplicating the parent's span attributes as events on the child? Maybe we're able to solve that by other means.

andrewhsu commented 3 years ago

from the spec sig mtg today, discussed this and the answer is "no", if there is a need, please send a PR to the spec to propose a change.

Oberon00 commented 3 years ago

To point out two important reason for why get cannot be provided:

aronchick commented 3 years ago

Gotcha – can you recommend a solution for later getting an attribute (if it exists) on a span?

I guess what I’m really looking for is a way to pass state, in a variable, to a child span or event being written.

bogdandrutu commented 3 years ago

@aronchick try to use CorrelationContext