Replies: 1 comment
-
If number of attributes are limited, we can use something like this: ( as temporaries live until end of full expression)
Having said that, In general - I do see the pain to create temporary variables to avoid memory corruption. However, introducing Owned-attributes will bringing the ABI stability issue, which was the initial reason of API design using non-owning attributes. |
Beta Was this translation helpful? Give feedback.
0 replies
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Uh oh!
There was an error while loading. Please reload this page.
-
Our Tracing API surface assumes that the
common::AttributeValue
here does not own the originating event attribute memory.When I use the SDK to append some event on Span, e.g.
Then use some utility function that returns a temporary
std::string
, e.g.std::string getSomeValue()
I cannot code my events this way:
Because
nostd::string_view
would refer to temporary that does not have any lifecycle guarantees.Now to overcome this limitation, I could do the following:
Then emit my span attributes, which would be handled more coherently.
I wonder if we could create another class similar to
OwnedAttributeValue
in API, maybe naming itEventProperties
orProperties
orAttributes
, being owning collection in order to simplify the usage of OpenTelemetry SDK. Without this concept it is very easy to fall into trap of a memory corruption on a temporary assigned to non-owningnostd::string_view
.As alternative, I'd like to show what could have been done to address this:
https://github.com/maxgolov/opentelemetry-cpp/blob/master/api/include/opentelemetry/event/Properties.hpp
This code is inspired by the following original implementation:
https://github.com/microsoft/cpp_client_telemetry/blob/master/lib/include/public/EventProperties.hpp
Beta Was this translation helpful? Give feedback.
All reactions