-
Notifications
You must be signed in to change notification settings - Fork 1.1k
Expand file tree
/
Copy pathtelemetry_test.go
More file actions
86 lines (72 loc) · 2.58 KB
/
telemetry_test.go
File metadata and controls
86 lines (72 loc) · 2.58 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
package copilot
import (
"context"
"testing"
"go.opentelemetry.io/otel"
"go.opentelemetry.io/otel/propagation"
"go.opentelemetry.io/otel/trace"
)
func TestGetTraceContextEmpty(t *testing.T) {
// Without any propagator configured, should return empty strings
tp, ts := getTraceContext(context.Background())
if tp != "" || ts != "" {
t.Errorf("expected empty trace context, got traceparent=%q tracestate=%q", tp, ts)
}
}
func TestGetTraceContextWithPropagator(t *testing.T) {
// Set up W3C propagator
otel.SetTextMapPropagator(propagation.TraceContext{})
defer otel.SetTextMapPropagator(propagation.NewCompositeTextMapPropagator())
// Inject known trace context
carrier := propagation.MapCarrier{
"traceparent": "00-4bf92f3577b34da6a3ce929d0e0e4736-00f067aa0ba902b7-01",
}
ctx := otel.GetTextMapPropagator().Extract(context.Background(), carrier)
tp, ts := getTraceContext(ctx)
if tp == "" {
t.Error("expected non-empty traceparent")
}
_ = ts // tracestate may be empty
}
func TestContextWithTraceParentEmpty(t *testing.T) {
ctx := contextWithTraceParent(context.Background(), "", "")
if ctx == nil {
t.Error("expected non-nil context")
}
}
func TestContextWithTraceParentValid(t *testing.T) {
otel.SetTextMapPropagator(propagation.TraceContext{})
defer otel.SetTextMapPropagator(propagation.NewCompositeTextMapPropagator())
ctx := contextWithTraceParent(context.Background(),
"00-4bf92f3577b34da6a3ce929d0e0e4736-00f067aa0ba902b7-01", "")
// Verify the context has trace info by extracting it back
carrier := propagation.MapCarrier{}
otel.GetTextMapPropagator().Inject(ctx, carrier)
if carrier.Get("traceparent") == "" {
t.Error("expected traceparent to be set in context")
}
}
func TestToolInvocationTraceContext(t *testing.T) {
otel.SetTextMapPropagator(propagation.TraceContext{})
defer otel.SetTextMapPropagator(propagation.NewCompositeTextMapPropagator())
traceparent := "00-4bf92f3577b34da6a3ce929d0e0e4736-00f067aa0ba902b7-01"
ctx := contextWithTraceParent(context.Background(), traceparent, "")
inv := ToolInvocation{
SessionID: "sess-1",
ToolCallID: "call-1",
ToolName: "my_tool",
Arguments: nil,
TraceContext: ctx,
}
// The TraceContext should carry the remote span context
sc := trace.SpanContextFromContext(inv.TraceContext)
if !sc.IsValid() {
t.Fatal("expected valid span context on ToolInvocation.TraceContext")
}
if sc.TraceID().String() != "4bf92f3577b34da6a3ce929d0e0e4736" {
t.Errorf("unexpected trace ID: %s", sc.TraceID())
}
if sc.SpanID().String() != "00f067aa0ba902b7" {
t.Errorf("unexpected span ID: %s", sc.SpanID())
}
}