mirror of
https://github.com/katanemo/plano.git
synced 2026-06-23 15:38:07 +02:00
fix span
This commit is contained in:
parent
bb9503e873
commit
4d52acf60c
7 changed files with 198 additions and 149 deletions
|
|
@ -18,7 +18,7 @@ pub use shapes::{
|
|||
};
|
||||
|
||||
// Re-export new utilities
|
||||
pub use span_builder::{SpanBuilder, SpanKind};
|
||||
pub use span_builder::{SpanBuilder, SpanKind, generate_random_span_id};
|
||||
pub use resource_span_builder::ResourceSpanBuilder;
|
||||
pub use constants::*;
|
||||
|
||||
|
|
|
|||
|
|
@ -37,6 +37,7 @@ pub struct SpanBuilder {
|
|||
end_time: Option<SystemTime>,
|
||||
kind: SpanKind,
|
||||
attributes: HashMap<String, String>,
|
||||
span_id: Option<String>,
|
||||
}
|
||||
|
||||
impl SpanBuilder {
|
||||
|
|
@ -53,6 +54,7 @@ impl SpanBuilder {
|
|||
end_time: None,
|
||||
kind: SpanKind::Internal,
|
||||
attributes: HashMap::new(),
|
||||
span_id: None,
|
||||
}
|
||||
}
|
||||
|
||||
|
|
@ -62,6 +64,11 @@ impl SpanBuilder {
|
|||
self
|
||||
}
|
||||
|
||||
pub fn with_span_id(mut self, span_id: impl Into<String>) -> Self {
|
||||
self.span_id = Some(span_id.into());
|
||||
self
|
||||
}
|
||||
|
||||
/// Set the parent span ID to link this span to its parent
|
||||
pub fn with_parent_span_id(mut self, parent_span_id: impl Into<String>) -> Self {
|
||||
self.parent_span_id = Some(parent_span_id.into());
|
||||
|
|
@ -125,7 +132,7 @@ impl SpanBuilder {
|
|||
// Build span directly without going through Span::new()
|
||||
Span {
|
||||
trace_id,
|
||||
span_id: generate_random_span_id(),
|
||||
span_id: self.span_id.unwrap_or_else(|| generate_random_span_id()),
|
||||
parent_span_id: self.parent_span_id,
|
||||
name: self.name,
|
||||
start_time_unix_nano: format!("{}", start_nanos),
|
||||
|
|
@ -145,7 +152,7 @@ fn system_time_to_nanos(time: SystemTime) -> u128 {
|
|||
}
|
||||
|
||||
/// Generate a random span ID (16 hex characters = 8 bytes)
|
||||
fn generate_random_span_id() -> String {
|
||||
pub fn generate_random_span_id() -> String {
|
||||
use rand::RngCore;
|
||||
let mut rng = rand::thread_rng();
|
||||
let mut random_bytes = [0u8; 8];
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue