forked from mtusi2026/mtusi2026lab6
27 lines
879 B
Go
27 lines
879 B
Go
package telemetry
|
|
|
|
import (
|
|
"context"
|
|
"testing"
|
|
|
|
"go.opentelemetry.io/otel/trace"
|
|
)
|
|
|
|
func TestOutboxTraceHeaders(t *testing.T) {
|
|
input := map[string]string{
|
|
"traceparent": "00-4bf92f3577b34da6a3ce929d0e0e4736-00f067aa0ba902b7-01",
|
|
"tracestate": "lab=node1",
|
|
"baggage": "private=example",
|
|
}
|
|
ctx := ExtractTrace(context.Background(), input)
|
|
got := TraceHeaders(ctx)
|
|
if len(got) != 2 || got["traceparent"] != input["traceparent"] || got["tracestate"] != input["tracestate"] {
|
|
t.Fatalf("неожиданные заголовки outbox: %v", got)
|
|
}
|
|
for _, headers := range []map[string]string{nil, {"traceparent": "broken"}} {
|
|
if trace.SpanContextFromContext(ExtractTrace(context.Background(), headers)).IsValid() {
|
|
t.Fatal("отсутствующий или повреждённый контекст дал валидного родителя")
|
|
}
|
|
}
|
|
}
|