-
Notifications
You must be signed in to change notification settings - Fork 809
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
Attributes helper function - convert a deep object to an attribute compliant single-depth kv object #1445
Comments
According to the specification, the attribute value must be:
An object (flat or nested) should not be accepted, so I suggest to apply what it says about arrays and serialize it using Nevertheless, who is responsible of serializing the value? The developer that sets it, the otel library that receives it or the exporter that propagates it? |
Not saying an object would be the attribute, but rather a helper function could convert an object into as many valid attributes as there are nested key values in the object for optimum queryability. So basically flat built into the api and provided to both node and browser. This would avoid users having to minutiously transform objects to ensure the KVs are compliant and would provide an experience similar to pino's mergingObject, where you just shove the object in there and profit. |
While I understand the frustration, I think adding such a helper is not in scope for the API package. 🤔 We'd be working around something that may be added to the spec in the future (see open-telemetry/opentelemetry-specification#2888), and if a future spec adds maps as attribute values, we'd also have to maintain our workaround for a long time. |
Thanks @pichlermarc let's see how open-telemetry/opentelemetry-specification#2888 and open-telemetry/oteps#219 play out. |
* chore(mysql): remove mysql from dependencies * fix: import type --------- Co-authored-by: Amir Blum <amirgiraffe@gmail.com>
tracer.getCurrentSpan()?.setAttributes({..anObject});
works well if the depth is 1, but if it is beyond that we will get[object Object]
as an attribute value.It would be nice to have a function to run on an object to get an atrribute friendly single-depth kv object.
tracer.getCurrentSpan()?.setAttributesFromObject({..anObject});
tl;dr
edit: as @sergioregueira mentioned, https://github.com/hughsk/flat exists
The text was updated successfully, but these errors were encountered: