-
Notifications
You must be signed in to change notification settings - Fork 721
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 changing Event struct to have non-'static metadata (Cow?) #1047
Comments
I've run into this limitation several times and been stumped because it's not possible to dynamically construct a For a real world example, I've got a WebAssembly module which uses the Leaking+caching the strings to get a |
I kind of have the same issue, where I need a dynamic I ended up with the same kind of tricks as This is quite ugly and cumbersome though, as this a lot of copying around and requires a custom subscriber to properly handle. I would definitely love to be able to build dynamic objects to solve those issues. |
I think this limitation makes it quite hard to follow the open telemetry convention for rpc span names https://github.com/open-telemetry/opentelemetry-specification/blob/main/specification/trace/semantic_conventions/rpc.md Might be able to do something similar where the subscribers rewrite the events before formatting and/or sending to open telemetry. |
I ran into this issue again a couple weeks back and created a thread on the Rust User Forums. It didn't get any responses, but I think the post itself provides some good concrete examples of what people mean when they want to dynamically generate I'm working on an application which uses the Here is a snippet showing the rough public API I want to expose: use tracing::field::ValueSet;
pub enum LogLevel {
Trace,
Debug,
Info,
Warn,
Error,
}
pub struct LogMetadata<'a> {
pub name: &'a str,
pub target: &'a str,
pub level: LogLevel,
pub file: Option<&'a str>,
pub line: Option<u32>,
pub module: Option<&'a str>,
}
pub enum LogValue<'a> {
Null,
Boolean(bool),
Integer(i64),
Float(f64),
String(&'a str),
}
pub type LogValueMap<'a> = Vec<(&'a str, LogValue<'a>)>;
fn is_enabled(meta: LogMetadata<'_>) -> bool {
tracing::dispatcher::get_default(|dispatch| {
let meta = tracing::Metadata::from(meta);
dispatch.enabled(&meta)
})
}
fn log(meta: LogMetadata<'_>, message: &str, data: LogValueMap<'_>) {
let meta = tracing::Metadata::from(meta);
let values = value_set(message, &data);
tracing::Event::dispatch(&meta, &values)
}
impl<'a> From<LogMetadata<'a>> for tracing::Metadata<'a> {
fn from(_: LogMetadata<'a>) -> Self {
todo!();
}
}
fn value_set<'a>(message: &'a str, values: &'a [(&'a str, LogValue<'a>)]) -> ValueSet<'a> {
todo!();
} The compile error shows that
Does anyone have any solutions or workarounds for my problem? The main thing I care about is having the log level and target in my final log event so that the dynamically generated log messages look just like any other message (styled differently based on levels, filtering by target/level works, etc.). I could use Footnotes
|
Non However I have a use case, in which I'm happy to leak the string (one per program), but I don't know how to use it as a name for a |
The One potential option could be to use the dynamic string as the span's Sorry. |
I appreciate the workaround suggestion. It might work. |
ref. #922
Currently the
Event
type intracing-core
requires a&'static Metadata<'static>
.The text was updated successfully, but these errors were encountered: