Open cijothomas opened 2 months ago
Current update on the options tried :
This get's complicated to support. The generic solution would be adding &str variant type to StringValue
, however adding any such lifetime specifier propagates through function signatures, struct definitions, and trait implementations, increasing the complexity of the codebase. In this case, the lifetime specifier needs to be added to StringValue
-> OtelString
->AnyValue
-> LogRecord
, and then further to LogRecord::body()
, LogRecord::add_attributes()
, LogRecord::add_attribute()
, LogProcessor::emit
, and LogExporter::export
methods as tried here - https://github.com/open-telemetry/opentelemetry-rust/compare/main...lalitb:opentelemetry-rust:strref-support.
Another option could be additional support of the direct streaming to exporter, without intermediate storage, however this wouldn't support the updates through LogProcessor chaining.
Have opened a discussion with the tracing folks - https://github.com/tokio-rs/tracing/discussions/3073. Also with the trait definition for the tacing::field::Visit::record_str
method, it is not possible to extend the lifetime of str reference without unsafe
keyword.
Even though using unsafe
is a safe operation, as the lifetime of the string is valid for the scope of execution of the tracing macro.
trait tracing::field::Visit {
fn record_str(&mut self, field: &tracing_core::Field, value: &str);
}
Tracing appender's EventVisitor currently copies the
&str
to an owned string in the heap. This is the case even when the user provides 'static str to the tracing macros. Opening an issue to see if this can be improved. Most likely this requires some support fromtracing
itself. Alternatively, this could be optimized for the sync exporters (like etw/user_events) alone, by doing serialization in the exporter in "streaming fashion", without any intermediate storage.