feat: harden community production foundation through story 1.5
This commit is contained in:
@@ -10,7 +10,10 @@ version.workspace = true
|
||||
path = "src/lib.rs"
|
||||
|
||||
[dependencies]
|
||||
crank-core = { path = "../crank-core" }
|
||||
opentelemetry.workspace = true
|
||||
tracing.workspace = true
|
||||
tracing-opentelemetry.workspace = true
|
||||
|
||||
[dev-dependencies]
|
||||
tracing-subscriber.workspace = true
|
||||
|
||||
@@ -6,7 +6,50 @@
|
||||
|
||||
use std::future::Future;
|
||||
|
||||
use opentelemetry::{
|
||||
Context,
|
||||
trace::{SpanContext, SpanId, TraceContextExt, TraceFlags, TraceId, TraceState},
|
||||
};
|
||||
use tracing::{Instrument, Span, field::Empty, info_span};
|
||||
use tracing_opentelemetry::OpenTelemetrySpanExt;
|
||||
|
||||
pub fn set_parent_from_trace_context(span: &Span, context: &crank_core::TraceContext) -> bool {
|
||||
let mut parts = context.traceparent().split('-');
|
||||
let (Some("00"), Some(trace_id), Some(parent_id), Some(flags), None) = (
|
||||
parts.next(),
|
||||
parts.next(),
|
||||
parts.next(),
|
||||
parts.next(),
|
||||
parts.next(),
|
||||
) else {
|
||||
return false;
|
||||
};
|
||||
let (Ok(trace_id), Ok(parent_id)) = (TraceId::from_hex(trace_id), SpanId::from_hex(parent_id))
|
||||
else {
|
||||
return false;
|
||||
};
|
||||
let flags = match flags {
|
||||
"00" => TraceFlags::default(),
|
||||
"01" => TraceFlags::SAMPLED,
|
||||
_ => return false,
|
||||
};
|
||||
let parent = SpanContext::new(trace_id, parent_id, flags, true, TraceState::default());
|
||||
span.set_parent(Context::new().with_remote_span_context(parent))
|
||||
.is_ok()
|
||||
}
|
||||
|
||||
pub fn trace_context_for_span(span: &Span) -> Option<crank_core::TraceContext> {
|
||||
let context = span.context();
|
||||
let span_context = context.span().span_context().clone();
|
||||
span_context.is_valid().then(|| {
|
||||
crank_core::TraceContext::from_span_parts(
|
||||
&span_context.trace_id().to_string(),
|
||||
&span_context.span_id().to_string(),
|
||||
span_context.is_sampled(),
|
||||
)
|
||||
.ok()
|
||||
})?
|
||||
}
|
||||
|
||||
macro_rules! stage_span {
|
||||
($name:literal) => {
|
||||
|
||||
Reference in New Issue
Block a user