-
Notifications
You must be signed in to change notification settings - Fork 0
/
zipkin_test.go
53 lines (47 loc) · 1.18 KB
/
zipkin_test.go
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
package zipkin
import (
"io/ioutil"
"net/http"
"net/http/httptest"
"testing"
"time"
"github.com/aluka-7/trace"
"github.com/aluka-7/utils"
)
func TestZipkin(t *testing.T) {
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()
c := &Config{
Endpoint: ts.URL,
Timeout: utils.Duration(time.Second * 5),
BatchSize: 100,
}
// c.Endpoint = "http://127.0.0.1:9411/api/v2/spans"
report := newReport(c)
t1 := trace.NewTracer("service1", []trace.Tag{}, report, true)
t2 := trace.NewTracer("service2", []trace.Tag{}, report, true)
sp1 := t1.New("option_1")
sp2 := sp1.Fork("service3", "opt_client")
sp2.SetLog(trace.Log("log_k", "log_v"))
// inject
header := make(http.Header)
t1.Inject(sp2, trace.HTTPFormat, header)
t.Log(header)
sp3, err := t2.Extract(trace.HTTPFormat, header)
if err != nil {
t.Fatal(err)
}
sp3.Finish(nil)
sp2.Finish(nil)
sp1.Finish(nil)
report.Close()
}