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

Consider flattening object-valued tags #5718

Open
djluck opened this issue Jun 25, 2024 · 0 comments
Open

Consider flattening object-valued tags #5718

djluck opened this issue Jun 25, 2024 · 0 comments
Labels
enhancement New feature or request

Comments

@djluck
Copy link

djluck commented Jun 25, 2024

Package

None

Is your feature request related to a problem?

When attaching object-valued tag values to Activity, when they are exported via TagWriter they are converted to their string representation via Convert.ToString.

This leads to issues with the exported attribute values, where one of two things happens:

  1. The object structure and values are not exported. This is the situation with the default object.ToString implementation.
  2. The object structure is not exported. This is the situation when ToString has been overridden and while the object property names + values are visible, it is not efficient to query.

What is the expected behavior?

If we could flatten objects automatically into key/ value pairs, e.g. given an object structure like this:

public record MyRecord(string Foo, string Bar);

When including this as a tag:

using var activity = ActivitySource.StartActivity("my_activity").AddTag("myrecord", new MyRecord("hello", "sir"))

The "myreord" tag would be converted into multiple OTel attributes that followed OTel attribute naming conventions (i.e snake_case + lowercased):

myrecord.foo = hello
myrecord.bar = sir

As per the discussion in the specification repo around supporting maps, we wouldn't be able to serialize any non-primitive arrays.

Which alternative solutions or features have you considered?

Currently no alternative exists in the standard library. The presence of Activity.AddTag(string key, object value) means it's very likely that users will incorrectly add

Additional context

No response

@djluck djluck added the enhancement New feature or request label Jun 25, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
enhancement New feature or request
1 participant