subscriber: add flatten span option to json formatter #2705
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Motivation
Span fields are currently not accessible at root level but only inside a nested object or the span list. This makes indexing log data more complex if a unique span identifier is required at root level, for example in the case of distributed trace Id (See also #1531).
Solution
This change adds two new options to
Json
for making span fields accessible at root level:Json::flatten_current_span
flattens all span fields into the root object. Thename
field is not carried over, since it might be ambiguous at root level.Json::flatten_span_list
flattens all fields for each span in the list into the root object. Colliding fields will be overwritten from root to leaf span.Examples
Default
Flatten only current span
All fields (except
name
) of the current span are present at the root level.Flatten current span and span list
Resolves: #2670