You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
kratos/pkg/net/trace/zipkin/zipkin_test.go

54 lines
1.2 KiB

6 years ago
package zipkin
import (
6 years ago
"io/ioutil"
6 years ago
"net/http"
6 years ago
"net/http/httptest"
6 years ago
"testing"
"time"
"github.com/bilibili/kratos/pkg/net/trace"
xtime "github.com/bilibili/kratos/pkg/time"
)
func TestZipkin(t *testing.T) {
6 years ago
ts := httptest.NewServer(http.HandlerFunc(func(w http.ResponseWriter, r *http.Request) {
if r.Method != "POST" {
t.Errorf("expected 'POST' request, got '%s'", r.Method)
}
aSpanPayload, err := ioutil.ReadAll(r.Body)
if err != nil {
t.Errorf("unexpected error: %s", err.Error())
}
t.Logf("%s\n", aSpanPayload)
}))
defer ts.Close()
6 years ago
c := &Config{
6 years ago
Endpoint: ts.URL,
6 years ago
Timeout: xtime.Duration(time.Second * 5),
BatchSize: 100,
}
6 years ago
//c.Endpoint = "http://127.0.0.1:9411/api/v2/spans"
6 years ago
report := newReport(c)
t1 := trace.NewTracer("service1", report, true)
t2 := trace.NewTracer("service2", report, true)
6 years ago
sp1 := t1.New("option_1")
sp2 := sp1.Fork("service3", "opt_client")
sp2.SetLog(trace.Log("log_k", "log_v"))
6 years ago
// inject
6 years ago
header := make(http.Header)
t1.Inject(sp2, trace.HTTPFormat, header)
6 years ago
t.Log(header)
6 years ago
sp3, err := t2.Extract(trace.HTTPFormat, header)
if err != nil {
t.Fatal(err)
}
sp3.Finish(nil)
sp2.Finish(nil)
sp1.Finish(nil)
report.Close()
}