-
Notifications
You must be signed in to change notification settings - Fork 850
subscriber: add flatten span option to json formatter #2705
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
base: main
Are you sure you want to change the base?
Conversation
|
Is there any followup needed on this pr? Can we get this reviewed please. |
a52dde2 to
78929e7
Compare
Nothing from my side. We need to wait for the maintainers to take a look. |
|
I'd love to see this added as well. We're using spans to track ray_ids for our HTTP requests and want to be able to get rid of the span name and flatten the ray_id onto the top object. |
|
@hawkw @davidbarsky @hds any chance one of you could take a look? we would like to use this for crates.io too :) |
78929e7 to
5d3cc11
Compare
|
For anyone interested, I've created a json-subscriber and I'm trying to implement all these long standing feature requests there (or making it general enough that people can set most things themselves). I've added flattening of spans there too. |
|
Thank you @heat1q! This is exactly what I was hoping to find after enabling |
|
Glad to see this PR thanks @heat1q, would also find this functionality very useful |
5d3cc11 to
3afe022
Compare
5d3cc11 to
3afe022
Compare
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
Jsonfor making span fields accessible at root level:Json::flatten_current_spanflattens all span fields into the root object. Thenamefield is not carried over, since it might be ambiguous at root level.Json::flatten_span_listflattens all fields for each span in the list into the root object. Colliding fields will be overwritten from root to leaf span.Examples
Default
{ "timestamp": "2023-08-30T13:28:57.999070Z", "level": "INFO", "fields": { "message": "shaving yaks" }, "target": "fmt_json::yak_shave", "span": { "yaks": 3, "name": "shaving_yaks" }, "spans": [ { "yaks": 3, "name": "shaving_yaks" } ] }Flatten only current span
All fields (except
name) of the current span are present at the root level.{ "timestamp": "2023-08-30T13:30:22.753644Z", "level": "INFO", "fields": { "message": "shaving yaks" }, "target": "fmt_json::yak_shave", "yaks": 3, "spans": [ { "yaks": 3, "name": "shaving_yaks" } ] }Flatten current span and span list
{ "timestamp": "2023-08-30T13:31:17.733524Z", "level": "INFO", "fields": { "message": "shaving yaks" }, "target": "fmt_json::yak_shave", "yaks": 3 }Resolves: #2670