Open davidbarsky opened 4 years ago
I think my biggest motivation for this proposal was supporting recording nested structures, as fmt::Debug
recordings of, for instance, http::HeaderMap
are non-ideal. This also has interesting implications for the 32 field limit—how would nested keys be treated by the key/value system? Given that:
log
, https://github.com/rust-lang/log/pull/396...there's a rich design space available for us to explore.
I'm a bigger fan of Value::from_serde
than this approach for that use case. Another one I have is that I'd like to pass a value directly through to the subscriber and it seems like this could be useful there.
the current practice of extensions traits on Spans that allow users to directly write to a Subscriber's extensions
I'm not familiar with this but it seems like it might not work super well for the case of wanting to print JS values to console.log
as those should often be events, although I may be misunderstanding this brief description. If it's a useful alternative to this proposal it might be worth writing something about it to contrast.
The ideal, IMO would be to support something like this in tracing-wasm:
let foo: JsValue = ...;
info!(foo, "button clicked");
which would end up calling something like console.log("button clicked foo=", foo)
under the hood. It would be fine if we were limited to an extension trait that returned a concrete type the backend can probe for:
let foo: JsValue = ...;
info!(foo = foo.pretty(), "button clicked"); // returns something like ConsoleValue(foo)
Supporting downcasting for Value
s is definitely not as powerful as arbitrary serde
serialization — and it's not really intended as a replacement for that. But downcasting is something we should probably implement anyway, and it may also cover some of those use cases in the short term.
Feature Request
Crates
tracing-core
Motivation
tracing_core::Value
without needing to take a public dependency on serde 1.0.Proposal
David:
Eliza, continuing in #819:
To address the "I can only record types that I know how to downcast" problem, Layers and Subscribers would be encouraged to provide a registry of formatters + downcasters for
std::any::Any
that the end-user (e.g., the person creating a binary executable) would register when creating their subscriber or layer.Alternatives
Don't do this. Based off Eliza's response, I worry that supporting
dyn Any + 'static
is strictly worse than something likeValue::from_serde
or the current practice of extensions traits on Spans that allow users to directly write to a Subscriber's extensions.Value::from_serde
, or something equivalent toValue::from_serde
, seems like a more general purpose and correct solution thandyn Any + 'static
because it doesn't require Layer or Subscriber-specific knowledge of types.tracing_core
.dyn Any + 'static
could prevent the usage of non-'static
references, requiring a clone to record a value. This is something thattracing
has avoided when recording other values and wouldn't hit iftracing_core::Value
supported something serde-style serializers.On the other hand, a registry of formatting/downcasting functions for
std::any::Any
could serve nice compliment for specialized, associative collections likehttp::Request
and friends, in that it provides a handy escape hatch for types/crates that either can't or won't take a public dependency ontracing_core::Value
. That said, I'm not sure this benefit is worth the downsides because Serde's support for implementing Serialize/Deserialize on foreign types would handle this usecase nicely.