|
|
@ -27,9 +27,9 @@ func TestOtelHandler(t *testing.T) {
|
|
|
|
t.Run(test, func(t *testing.T) {
|
|
|
|
t.Run(test, func(t *testing.T) {
|
|
|
|
h := chain.New(TracingHandler("foo", test)).Then(
|
|
|
|
h := chain.New(TracingHandler("foo", test)).Then(
|
|
|
|
http.HandlerFunc(func(w http.ResponseWriter, r *http.Request) {
|
|
|
|
http.HandlerFunc(func(w http.ResponseWriter, r *http.Request) {
|
|
|
|
ctx := otel.GetTextMapPropagator().Extract(r.Context(), propagation.HeaderCarrier(r.Header))
|
|
|
|
span := trace.SpanFromContext(r.Context())
|
|
|
|
spanCtx := trace.SpanContextFromContext(ctx)
|
|
|
|
assert.True(t, span.SpanContext().IsValid())
|
|
|
|
assert.True(t, spanCtx.IsValid())
|
|
|
|
assert.True(t, span.IsRecording())
|
|
|
|
}))
|
|
|
|
}))
|
|
|
|
ts := httptest.NewServer(h)
|
|
|
|
ts := httptest.NewServer(h)
|
|
|
|
defer ts.Close()
|
|
|
|
defer ts.Close()
|
|
|
@ -52,7 +52,7 @@ func TestOtelHandler(t *testing.T) {
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
func TestDontTracingSpanName(t *testing.T) {
|
|
|
|
func TestDontTracingSpan(t *testing.T) {
|
|
|
|
ztrace.StartAgent(ztrace.Config{
|
|
|
|
ztrace.StartAgent(ztrace.Config{
|
|
|
|
Name: "go-zero-test",
|
|
|
|
Name: "go-zero-test",
|
|
|
|
Endpoint: "http://localhost:14268/api/traces",
|
|
|
|
Endpoint: "http://localhost:14268/api/traces",
|
|
|
@ -66,12 +66,15 @@ func TestDontTracingSpanName(t *testing.T) {
|
|
|
|
t.Run(test, func(t *testing.T) {
|
|
|
|
t.Run(test, func(t *testing.T) {
|
|
|
|
h := chain.New(TracingHandler("foo", test)).Then(
|
|
|
|
h := chain.New(TracingHandler("foo", test)).Then(
|
|
|
|
http.HandlerFunc(func(w http.ResponseWriter, r *http.Request) {
|
|
|
|
http.HandlerFunc(func(w http.ResponseWriter, r *http.Request) {
|
|
|
|
spanCtx := trace.SpanContextFromContext(r.Context())
|
|
|
|
span := trace.SpanFromContext(r.Context())
|
|
|
|
|
|
|
|
spanCtx := span.SpanContext()
|
|
|
|
if test == "bar" {
|
|
|
|
if test == "bar" {
|
|
|
|
assert.False(t, spanCtx.IsValid())
|
|
|
|
assert.False(t, spanCtx.IsValid())
|
|
|
|
|
|
|
|
assert.False(t, span.IsRecording())
|
|
|
|
return
|
|
|
|
return
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
assert.True(t, span.IsRecording())
|
|
|
|
assert.True(t, spanCtx.IsValid())
|
|
|
|
assert.True(t, spanCtx.IsValid())
|
|
|
|
}))
|
|
|
|
}))
|
|
|
|
ts := httptest.NewServer(h)
|
|
|
|
ts := httptest.NewServer(h)
|
|
|
|