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

53 lines
1.1 KiB

5 years ago
package zipkin
import (
5 years ago
"io/ioutil"
5 years ago
"net/http"
5 years ago
"net/http/httptest"
5 years ago
"testing"
"time"
"github.com/bilibili/kratos/pkg/net/trace"
xtime "github.com/bilibili/kratos/pkg/time"
)
func TestZipkin(t *testing.T) {
5 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()
5 years ago
c := &Config{
5 years ago
Endpoint: ts.URL,
5 years ago
Timeout: xtime.Duration(time.Second * 5),
BatchSize: 100,
}
5 years ago
//c.Endpoint = "http://127.0.0.1:9411/api/v2/spans"
5 years ago
report := newReport(c)
t1 := trace.NewTracer("service1", report, true)
t2 := trace.NewTracer("service2", report, true)
5 years ago
sp1 := t1.New("option_1")
sp2 := sp1.Fork("service3", "opt_client")
// inject
5 years ago
header := make(http.Header)
t1.Inject(sp2, trace.HTTPFormat, header)
5 years ago
t.Log(header)
5 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()
}