more fixes based on PR comments

This commit is contained in:
Salman Paracha 2025-12-11 14:49:38 -08:00
parent 28b674454b
commit 54db942f3c
3 changed files with 27 additions and 11 deletions

View file

@ -42,12 +42,9 @@ pub async fn llm_chat(
.and_then(|h| h.to_str().ok())
.map(|s| s.to_string())
.unwrap_or_else(|| {
// No traceparent - this is a root span, generate a new trace ID
use uuid::Uuid;
let trace_id = Uuid::new_v4().to_string().replace("-", "");
let span_id = Uuid::new_v4().to_string().replace("-", "")[..16].to_string();
// Format: version-trace_id-parent_span_id-trace_flags
format!("00-{}-{}-01", trace_id, span_id)
format!("00-{}-0000000000000000-01", trace_id)
});
let mut request_headers = request_headers;
@ -273,7 +270,6 @@ async fn build_llm_span(
let mut span_builder = SpanBuilder::new(&operation_name)
.with_trace_id(&trace_id)
.with_parent_span_id(&parent_span_id)
.with_kind(SpanKind::Client)
.with_start_time(start_time)
.with_attribute(http::METHOD, "POST")
@ -283,6 +279,11 @@ async fn build_llm_span(
.with_attribute(llm::MODEL_NAME, resolved_model.to_string())
.with_attribute(llm::IS_STREAMING, is_streaming.to_string());
// Only set parent span ID if it exists (not a root span)
if let Some(parent) = parent_span_id {
span_builder = span_builder.with_parent_span_id(&parent);
}
// Add optional attributes
if let Some(temp) = temperature {
span_builder = span_builder.with_attribute(llm::TEMPERATURE, temp.to_string());

View file

@ -219,7 +219,6 @@ async fn record_routing_span(
// Build the routing span directly using constants
let mut span_builder = SpanBuilder::new(&routing_operation_name)
.with_trace_id(&trace_id)
.with_parent_span_id(&parent_span_id)
.with_kind(SpanKind::Client)
.with_start_time(start_system_time)
.with_end_time(std::time::SystemTime::now())
@ -227,6 +226,11 @@ async fn record_routing_span(
.with_attribute(http::TARGET, routing_api_path.to_string())
.with_attribute(routing::ROUTE_DETERMINATION_MS, start_time.elapsed().as_millis().to_string());
// Only set parent span ID if it exists (not a root span)
if let Some(parent) = parent_span_id {
span_builder = span_builder.with_parent_span_id(&parent);
}
// Add all custom attributes
for (key, value) in attrs {
span_builder = span_builder.with_attribute(key, value);