@@ -379,10 +379,15 @@ func (h *hubBase) traceContextForScan(table string, columns []string, limit int6
379
379
380
380
// Check if we have trace context from session variables
381
381
if traceContextStr , exists := opts ["trace_context" ]; exists && traceContextStr != "" {
382
+ log .Printf ("[DEBUG] traceContextForScan received trace context: %s" , traceContextStr )
382
383
if parentCtx := h .parseTraceContext (traceContextStr ); parentCtx != nil {
383
384
baseCtx = parentCtx
384
385
log .Printf ("[TRACE] Using parent trace context for scan of table: %s" , table )
386
+ } else {
387
+ log .Printf ("[WARN] Failed to parse trace context for table: %s" , table )
385
388
}
389
+ } else {
390
+ log .Printf ("[DEBUG] No trace context found in options for table: %s" , table )
386
391
}
387
392
388
393
// Create span with potentially propagated context
@@ -396,28 +401,45 @@ func (h *hubBase) traceContextForScan(table string, columns []string, limit int6
396
401
if limit != - 1 {
397
402
span .SetAttributes (attribute .Int64 ("limit" , limit ))
398
403
}
404
+
405
+ spanCtx := span .SpanContext ()
406
+ if spanCtx .IsValid () {
407
+ log .Printf ("[DEBUG] Created span for table %s - TraceID: %s, SpanID: %s" ,
408
+ table , spanCtx .TraceID ().String (), spanCtx .SpanID ().String ())
409
+ }
410
+
399
411
return & telemetry.TraceCtx {Ctx : ctx , Span : span }
400
412
}
401
413
402
414
// parseTraceContext parses trace context string from session variables
403
415
// Format: "traceparent=00-4bf92f3577b34da6a3ce929d0e0e4736-00f067aa0ba902b7-01;tracestate=rojo=00f067aa0ba902b7"
404
416
func (h * hubBase ) parseTraceContext (traceContextString string ) context.Context {
417
+ log .Printf ("[DEBUG] parseTraceContext called with: %s" , traceContextString )
418
+
405
419
if traceContextString == "" {
420
+ log .Printf ("[DEBUG] Empty trace context string" )
406
421
return nil
407
422
}
408
423
409
424
carrier := propagation.MapCarrier {}
410
425
411
426
// Parse the trace context string format: "traceparent=..;tracestate=.."
412
427
parts := strings .Split (traceContextString , ";" )
428
+ log .Printf ("[DEBUG] Split trace context into %d parts: %v" , len (parts ), parts )
429
+
413
430
for _ , part := range parts {
414
431
if kv := strings .SplitN (part , "=" , 2 ); len (kv ) == 2 {
415
432
key := strings .TrimSpace (kv [0 ])
416
433
value := strings .TrimSpace (kv [1 ])
417
434
carrier [key ] = value
435
+ log .Printf ("[DEBUG] Added to carrier: %s = %s" , key , value )
436
+ } else {
437
+ log .Printf ("[DEBUG] Skipping invalid part: %s" , part )
418
438
}
419
439
}
420
440
441
+ log .Printf ("[DEBUG] Final carrier contents: %v" , carrier )
442
+
421
443
if len (carrier ) == 0 {
422
444
log .Printf ("[WARN] No valid trace context found in: %s" , traceContextString )
423
445
return nil
@@ -438,7 +460,7 @@ func (h *hubBase) parseTraceContext(traceContextString string) context.Context {
438
460
return extractedCtx
439
461
}
440
462
441
- log .Printf ("[WARN] Extracted trace context is not valid" )
463
+ log .Printf ("[WARN] Extracted trace context is not valid - carrier was: %v" , carrier )
442
464
return nil
443
465
}
444
466
0 commit comments