You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
When creating a new span, the tracer calls the SpanProcessor::on_start on method and passes a &mut Span.
In the otel spec, this span parameter is read/write opentelemetry-specification.
Currently in the rust SDK, the only way to read data on the span is to call span.exported_data() -> Option<crate::trace::SpanData>, which clones all fields in the span, including things that require allocation such as the span links attributes, events and span links.
Other opentelemetry SDK implementation usually expose a ReadableSpan interface gojava providing a view over the span without mutations, and I believe something similar could be implemented over the rust Span.
This is the API I am proposing:
implSpan{/// Returns a read-only view of the span data/// This is None if the span is not recording.pubfnread<'a>(&'aself) -> Option<ReadableSpan<'a>>{Some(ReadableSpan(self.data.as_ref()?))}}#[derive(Clone,Debug)]pubstructReadableSpan<'a>(&'aSpanData);impl<'a>ReadableSpan<'a>{pubfnparent_span_id(&self) -> SpanId{..}pubfnspan_kind(&self) -> SpanKind{..}pubfnname(&self) -> &str{..}pubfnstart_time(&self) -> SystemTime{..}pubfnend_time(&self) -> SystemTime{..}pubfnattributes(&self) -> &'a[KeyValue]{..}pubfndropped_attributes_count(&self) -> u32{..}pubfnevents(&self) -> &'a[Event]{..}pubfndropped_events_count(&self) -> u32{..}pubfnlinks(&self) -> &'a[Link]{..}pubfndropped_links_count(&self) -> u32{..}pubfnstatus(&self) -> &Status{..}}
An alternative would be to implement all of the getters directly on the opentelemetry_sdk::trace::Span struct.
This is functionally the same, and we don't have to add a separate struct to the public API of ths crate.
This make the API a bit harder to call though because every field that references a field in SpanData would need to either return an Option, or the default value (empty attribute slice, 0 for dropped entries, SpanId::Invalid for the parent id)
Make ReadableSpan<'a> a trait, and return an opaque object implementating the trait from Span
implSpan{/// Returns a read-only view of the span data/// This is None if the span is not recording.pubfnread<'a>(&'aself) -> Option<implReadableSpan<'a>>{Some(ReadableSpan(self.data.as_ref()?))}}traitReadableSpan<'a>{...}
This is more complex, as the value become un-nameable and thus cannot be stored easily in collections.
I don't really know what this buys us, and who else would implement the trait....
Additional Context
No response
The text was updated successfully, but these errors were encountered:
Related Problems?
No response
Describe the solution you'd like:
When creating a new span, the tracer calls the
SpanProcessor::on_start
on method and passes a&mut Span
.In the otel spec, this span parameter is read/write opentelemetry-specification.
Currently in the rust SDK, the only way to read data on the span is to call
span.exported_data() -> Option<crate::trace::SpanData>
, which clones all fields in the span, including things that require allocation such as the span links attributes, events and span links.Other opentelemetry SDK implementation usually expose a
ReadableSpan
interfacego java providing a view over the span without mutations, and I believe something similar could be implemented over the rust Span.
This is the API I am proposing:
POC here
Considered Alternatives
I see two alternatives:
An alternative would be to implement all of the getters directly on the
opentelemetry_sdk::trace::Span
struct.This is functionally the same, and we don't have to add a separate struct to the public API of ths crate.
This make the API a bit harder to call though because every field that references a field in
SpanData
would need to either return anOption
, or the default value (empty attribute slice,0
for dropped entries,SpanId::Invalid
for the parent id)Make
ReadableSpan<'a>
a trait, and return an opaque object implementating the trait fromSpan
This is more complex, as the value become un-nameable and thus cannot be stored easily in collections.
I don't really know what this buys us, and who else would implement the trait....
Additional Context
No response
The text was updated successfully, but these errors were encountered: