forked from openzipkin/zipkin-go
-
Notifications
You must be signed in to change notification settings - Fork 0
/
tracer_test.go
810 lines (618 loc) · 19 KB
/
tracer_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
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
700
701
702
703
704
705
706
707
708
709
710
711
712
713
714
715
716
717
718
719
720
721
722
723
724
725
726
727
728
729
730
731
732
733
734
735
736
737
738
739
740
741
742
743
744
745
746
747
748
749
750
751
752
753
754
755
756
757
758
759
760
761
762
763
764
765
766
767
768
769
770
771
772
773
774
775
776
777
778
779
780
781
782
783
784
785
786
787
788
789
790
791
792
793
794
795
796
797
798
799
800
801
802
803
804
805
806
807
808
809
810
// Copyright 2019 The OpenZipkin Authors
//
// Licensed under the Apache License, Version 2.0 (the "License");
// you may not use this file except in compliance with the License.
// You may obtain a copy of the License at
//
// http://www.apache.org/licenses/LICENSE-2.0
//
// Unless required by applicable law or agreed to in writing, software
// distributed under the License is distributed on an "AS IS" BASIS,
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
// See the License for the specific language governing permissions and
// limitations under the License.
package zipkin
import (
"context"
"errors"
"reflect"
"testing"
"time"
"github.com/openzipkin/zipkin-go/idgenerator"
"github.com/openzipkin/zipkin-go/model"
"github.com/openzipkin/zipkin-go/reporter"
)
func TestTracerOptionLocalEndpoint(t *testing.T) {
var (
err error
wantEP *model.Endpoint
)
tr, err := NewTracer(nil, WithLocalEndpoint(nil))
if err != nil {
t.Fatalf("unexpected tracer creation failure: %+v", err.Error())
}
if tr == nil {
t.Error("expected valid tracer, got: nil")
}
if want, have := wantEP, tr.LocalEndpoint(); !reflect.DeepEqual(want, have) {
t.Errorf("local Endpoint want %+v, have %+v", want, have)
}
wantEP, err = NewEndpoint("testService", "localhost:80")
if err != nil {
t.Fatalf("expected valid endpoint, got error: %+v", err)
}
rep := reporter.NewNoopReporter()
defer rep.Close()
tr, err = NewTracer(rep, WithLocalEndpoint(wantEP))
if err != nil {
t.Fatalf("expected valid tracer, got error: %+v", err)
}
if tr == nil {
t.Error("expected valid tracer, got nil")
}
haveEP := tr.LocalEndpoint()
if want, have := wantEP.ServiceName, haveEP.ServiceName; want != have {
t.Errorf("ServiceName want %s, have %s", want, have)
}
if !wantEP.IPv4.Equal(haveEP.IPv4) {
t.Errorf(" IPv4 want %+v, have %+v", wantEP.IPv4, haveEP.IPv4)
}
if !wantEP.IPv6.Equal(haveEP.IPv6) {
t.Errorf("IPv6 want %+v, have %+v", wantEP.IPv6, haveEP.IPv6)
}
}
func TestTracerOptionExtractFailurePolicy(t *testing.T) {
rep := reporter.NewNoopReporter()
defer rep.Close()
policies := []struct {
policy ExtractFailurePolicy
err error
}{
{-1, ErrInvalidExtractFailurePolicy},
{ExtractFailurePolicyRestart, nil},
{ExtractFailurePolicyError, nil},
{ExtractFailurePolicyTagAndRestart, nil},
{3, ErrInvalidExtractFailurePolicy},
}
for idx, item := range policies {
tr, err := NewTracer(rep, WithExtractFailurePolicy(item.policy))
if want, have := item.err, err; want != have {
t.Fatalf("[%d] expected tracer creation failure: want %+v, have %+v", idx, item.err, err)
}
if err != nil && tr != nil {
t.Fatalf("[%d] expected tracer to be nil, have: %+v", idx, tr)
}
if err != nil {
tr, _ = NewTracer(rep)
tr.extractFailurePolicy = item.policy
}
errStr := failSpan(t, tr, idx, item.err)
if item.policy == ExtractFailurePolicyTagAndRestart {
if want, have := "dummy", errStr; want != have {
t.Errorf("[%d] tag[error.extract tag] want %s, have %s", idx, want, have)
}
}
}
}
func failSpan(t *testing.T, tr *Tracer, idx int, want error) string {
sc := model.SpanContext{
Err: errors.New("dummy"),
}
defer func() {
if err := recover(); err != nil {
if err != want {
t.Errorf("[%d] Context Error want %+v, have %+v", idx, want, err)
}
}
}()
sp := tr.StartSpan("test", Parent(sc))
sp.Finish()
return sp.(*spanImpl).Tags["error.extract"]
}
func TestTracerIDGeneratorOption(t *testing.T) {
rep := reporter.NewNoopReporter()
defer rep.Close()
gen := idgenerator.NewRandomTimestamped()
tr, err := NewTracer(rep, WithIDGenerator(gen))
if err != nil {
t.Fatalf("expected valid tracer, got error: %+v", err)
}
if want, have := gen, tr.generate; want != have {
t.Errorf("id generator want %+v, have %+v", want, have)
}
}
func TestTracerWithTraceID128BitOption(t *testing.T) {
rep := reporter.NewNoopReporter()
defer rep.Close()
tr, err := NewTracer(rep, WithTraceID128Bit(false))
if err != nil {
t.Fatalf("expected valid tracer, got error: %+v", err)
}
if want, have := reflect.TypeOf(idgenerator.NewRandom64()), reflect.TypeOf(tr.generate); want != have {
t.Errorf("id generator want %+v, have %+v", want, have)
}
tr, err = NewTracer(rep, WithTraceID128Bit(true))
if err != nil {
t.Fatalf("expected valid tracer, got error: %+v", err)
}
if want, have := reflect.TypeOf(idgenerator.NewRandom128()), reflect.TypeOf(tr.generate); want != have {
t.Errorf("id generator want %+v, have %+v", want, have)
}
}
func TestTracerExtractor(t *testing.T) {
rep := reporter.NewNoopReporter()
defer rep.Close()
tr, err := NewTracer(rep)
if err != nil {
t.Fatalf("unable to create tracer instance: %+v", err)
}
testErr1 := errors.New("extractor error")
extractorErr := func() (*model.SpanContext, error) {
return nil, testErr1
}
sc := tr.Extract(extractorErr)
if want, have := testErr1, sc.Err; want != have {
t.Errorf("Err want %+v, have %+v", want, have)
}
spanContext := model.SpanContext{}
extractor := func() (*model.SpanContext, error) {
return &spanContext, nil
}
sc = tr.Extract(extractor)
if want, have := spanContext, sc; want != have {
t.Errorf("SpanContext want %+v, have %+v", want, have)
}
if want, have := &spanContext, ≻ want == have {
t.Error("expected different span context objects")
}
}
func TestNoopTracer(t *testing.T) {
rep := reporter.NewNoopReporter()
defer rep.Close()
tr, err := NewTracer(rep)
if err != nil {
t.Fatalf("unable to create tracer instance: %+v", err)
}
pSC := model.SpanContext{
TraceID: model.TraceID{
High: 0,
Low: 1,
},
ID: model.ID(1),
}
span := tr.StartSpan("test", Parent(pSC))
if want, have := reflect.TypeOf(&spanImpl{}), reflect.TypeOf(span); want != have {
t.Errorf("span implementation type want %+v, have %+v", want, have)
}
span.Finish()
tr.SetNoop(true)
testErr1 := errors.New("extractor error")
extractor := func() (*model.SpanContext, error) {
return nil, testErr1
}
sc := tr.Extract(extractor)
if sc.Err != nil {
t.Errorf("Err want nil, have %+v", sc.Err)
}
span = tr.StartSpan("test", Parent(pSC))
if want, have := reflect.TypeOf(&noopSpan{}), reflect.TypeOf(span); want != have {
t.Errorf("span implementation type want %+v, have %+v", want, have)
}
span.Finish()
tr.SetNoop(false)
span = tr.StartSpan("test", Parent(pSC))
if want, have := reflect.TypeOf(&spanImpl{}), reflect.TypeOf(span); want != have {
t.Errorf("span implementation type want %+v, have %+v", want, have)
}
span.Finish()
tr, err = NewTracer(rep, WithNoopTracer(true))
if err != nil {
t.Fatalf("unable to create tracer instance: %+v", err)
}
testErr1 = errors.New("extractor error")
extractor = func() (*model.SpanContext, error) {
return nil, testErr1
}
sc = tr.Extract(extractor)
if sc.Err != nil {
t.Errorf("Err want nil, have %+v", sc.Err)
}
span = tr.StartSpan("test", Parent(pSC))
if want, have := reflect.TypeOf(&noopSpan{}), reflect.TypeOf(span); want != have {
t.Errorf("span implementation type want %+v, have %+v", want, have)
}
tr, err = NewTracer(rep, WithNoopTracer(false))
if err != nil {
t.Fatalf("unable to create tracer instance: %+v", err)
}
span = tr.StartSpan("test", Parent(pSC))
if want, have := reflect.TypeOf(&spanImpl{}), reflect.TypeOf(span); want != have {
t.Errorf("span implementation type want %+v, have %+v", want, have)
}
}
func TestNoopSpan(t *testing.T) {
rep := reporter.NewNoopReporter()
defer rep.Close()
tr, err := NewTracer(rep, WithNoopSpan(true))
if err != nil {
t.Fatalf("unable to create tracer instance: %+v", err)
}
sampled := false
pSC := model.SpanContext{
TraceID: model.TraceID{
High: 0,
Low: 1,
},
ID: model.ID(1),
Sampled: &sampled,
}
span := tr.StartSpan("test", Parent(pSC))
if want, have := reflect.TypeOf(&noopSpan{}), reflect.TypeOf(span); want != have {
t.Errorf("span implementation type want %+v, have %+v", want, have)
}
span.Finish()
}
func TestUnsampledSpan(t *testing.T) {
rep := reporter.NewNoopReporter()
defer rep.Close()
tr, err := NewTracer(rep, WithTraceID128Bit(false))
if err != nil {
t.Fatalf("unable to create tracer instance: %+v", err)
}
sampled := false
pSC := model.SpanContext{
TraceID: model.TraceID{
High: 0,
Low: 1,
},
ID: model.ID(1),
Sampled: &sampled,
}
span := tr.StartSpan("test", Parent(pSC))
if want, have := reflect.TypeOf(&spanImpl{}), reflect.TypeOf(span); want != have {
t.Errorf("span implementation type want %+v, have %+v", want, have)
}
cSC := span.Context()
if cSC.Err != nil {
t.Errorf("Err want nil, have %+v", cSC.Err)
}
if want, have := pSC.Debug, cSC.Debug; want != have {
t.Errorf("Debug want %t, have %t", want, have)
}
if want, have := pSC.TraceID, cSC.TraceID; want != have {
t.Errorf("TraceID want %+v, have %+v", want, have)
}
if cSC.ID == 0 {
t.Error("ID want valid value, have 0")
}
if cSC.ParentID == nil {
t.Errorf("ParentID want %+v, have nil", pSC.ID)
} else if want, have := pSC.ID, *cSC.ParentID; want != have {
t.Errorf("ParentID want %+v, have %+v", want, have)
}
if cSC.Sampled == nil {
t.Error("Sampled want false, have nil")
} else if *cSC.Sampled {
t.Errorf("Sampled want false, have %+v", *cSC.Sampled)
}
if want, have := int32(0), span.(*spanImpl).mustCollect; want != have {
t.Errorf("expected mustCollect %d, got %d", want, have)
}
span.Finish()
}
func TestDefaultTags(t *testing.T) {
var (
scTagKey = "spanScopedTag"
scTagValue = "spanPayload"
tags = make(map[string]string)
)
tags["platform"] = "zipkin_test"
tags["version"] = "1.0"
rep := reporter.NewNoopReporter()
defer rep.Close()
tr, err := NewTracer(rep, WithTags(tags), WithTraceID128Bit(true))
if err != nil {
t.Fatalf("unable to create tracer instance: %+v", err)
}
pSC := model.SpanContext{
TraceID: model.TraceID{
High: 0,
Low: 1,
},
ID: model.ID(1),
}
span := tr.StartSpan("test", Kind(model.Server), Parent(pSC))
span.Tag(scTagKey, scTagValue)
foundTags := span.(*spanImpl).Tags
for key, value := range tags {
foundValue, foundKey := foundTags[key]
if !foundKey {
t.Errorf("Tag want %s=%s, have key not found", key, value)
} else if value != foundValue {
t.Errorf("Tag want %s=%s, have %s=%s", key, value, key, foundValue)
}
}
foundValue, foundKey := foundTags[scTagKey]
if !foundKey {
t.Errorf("Tag want %s=%s, have key not found", scTagKey, scTagValue)
} else if want, have := scTagValue, foundValue; want != have {
t.Errorf("Tag want %s=%s, have %s=%s", scTagKey, scTagValue, scTagKey, foundValue)
}
}
func TestTagOverwriteRules(t *testing.T) {
var (
k1 = "key1"
v1First = "value to overwrite"
v1Last = "value to keep"
k2 = string(TagError)
)
rep := reporter.NewNoopReporter()
defer rep.Close()
tr, err := NewTracer(rep, WithIDGenerator(idgenerator.NewRandomTimestamped()))
if err != nil {
t.Fatalf("unable to create tracer instance: %+v", err)
}
s := tr.StartSpan("test_tags")
defer s.Finish()
s.Tag(k1, v1First)
if want, have := v1First, s.(*spanImpl).Tags[k1]; want != have {
t.Errorf("Tag want %s=%s, have %s=%s", k1, want, k1, have)
}
s.Tag(k1, v1Last)
if want, have := v1Last, s.(*spanImpl).Tags[k1]; want != have {
t.Errorf("Tag want %s=%s, have %s=%s", k1, want, k1, have)
}
s.Tag(k2, v1First)
if want, have := v1First, s.(*spanImpl).Tags[k2]; want != have {
t.Errorf("Tag want %s=%s, have %s=%s", k1, want, k1, have)
}
s.Tag(k2, v1Last)
if want, have := v1First, s.(*spanImpl).Tags[k2]; want != have {
t.Errorf("Tag want %s=%s, have %s=%s", k1, want, k1, have)
}
TagError.Set(s, v1Last)
if want, have := v1First, s.(*spanImpl).Tags[k2]; want != have {
t.Errorf("Tag want %s=%s, have %s=%s", k1, want, k1, have)
}
}
func TestAnnotations(t *testing.T) {
rep := reporter.NewNoopReporter()
defer rep.Close()
tr, err := NewTracer(rep)
if err != nil {
t.Fatalf("unable to create tracer instance: %+v", err)
}
s := tr.StartSpan("test_tags")
defer s.Finish()
annotations := []model.Annotation{
{
Timestamp: time.Now().Add(10 * time.Millisecond),
Value: "annotation 1",
},
{
Timestamp: time.Now().Add(20 * time.Millisecond),
Value: "annotation 2",
},
{
Timestamp: time.Now().Add(30 * time.Millisecond),
Value: "annotation 3",
},
}
for _, annotation := range annotations {
s.Annotate(annotation.Timestamp, annotation.Value)
}
time.Sleep(40 * time.Millisecond)
if want, have := len(annotations), len(s.(*spanImpl).Annotations); want != have {
t.Fatalf("Annotation count want %d, have %d", want, have)
}
for idx, annotation := range annotations {
if want, have := annotation, s.(*spanImpl).Annotations[idx]; want != have {
t.Errorf("Annotation #%d want %+v, have %+v", idx, want, have)
}
}
}
func TestExplicitStartTime(t *testing.T) {
rep := reporter.NewNoopReporter()
defer rep.Close()
tr, err := NewTracer(rep, WithSampler(NewModuloSampler(2)))
if err != nil {
t.Fatalf("unable to create tracer instance: %+v", err)
}
st := time.Now()
time.Sleep(10 * time.Millisecond)
s := tr.StartSpan("test_tags", StartTime(st))
defer s.Finish()
if want, have := st, s.(*spanImpl).Timestamp; want != have {
t.Errorf("Timestamp want %+v, have %+v", want, have)
}
}
func TestDebugFlagWithoutParentTrace(t *testing.T) {
/*
Test handling of a single Debug flag without an existing trace
*/
rep := reporter.NewNoopReporter()
defer rep.Close()
tr, err := NewTracer(rep, WithSharedSpans(true))
if err != nil {
t.Fatalf("unable to create tracer instance: %+v", err)
}
pSC := model.SpanContext{
Debug: true,
}
span := tr.StartSpan("test", Parent(pSC))
cSC := span.Context()
if cSC.Err != nil {
t.Errorf("Err want nil, have %+v", cSC.Err)
}
if want, have := pSC.Debug, cSC.Debug; want != have {
t.Errorf("Debug want %t, have %t", want, have)
}
if want, have := false, cSC.TraceID.Empty(); want != have {
t.Error("expected valid TraceID")
}
if cSC.ID == 0 {
t.Error("expected valid ID")
}
if cSC.ParentID != nil {
t.Errorf("ParentID want nil, have %+v", cSC.ParentID)
}
if cSC.Sampled != nil {
t.Errorf("Sampled want nil, have %+v", cSC.Sampled)
}
if want, have := int32(1), span.(*spanImpl).mustCollect; want != have {
t.Errorf("mustCollect want %d, have %d", want, have)
}
}
func TestParentSpanInSharedMode(t *testing.T) {
rep := reporter.NewNoopReporter()
defer rep.Close()
tr, err := NewTracer(rep, WithSharedSpans(true))
if err != nil {
t.Fatalf("unable to create tracer instance: %+v", err)
}
parentID := model.ID(1)
pSC := model.SpanContext{
TraceID: model.TraceID{
High: 0,
Low: 1,
},
ID: model.ID(2),
ParentID: &parentID,
}
span := tr.StartSpan("test", Kind(model.Server), Parent(pSC))
cSC := span.Context()
if cSC.Err != nil {
t.Errorf("Err want nil, have %+v", cSC.Err)
}
if want, have := pSC.Debug, cSC.Debug; want != have {
t.Errorf("Debug want %t, have %t", want, have)
}
if want, have := pSC.TraceID, cSC.TraceID; want != have {
t.Errorf("TraceID want %+v, have %+v", want, have)
}
if want, have := pSC.ID, cSC.ID; want != have {
t.Errorf("ID want %+v, have %+v", want, have)
}
if cSC.ParentID == nil {
t.Error("ParentID want valid value, have nil")
} else if want, have := parentID, *cSC.ParentID; want != have {
t.Errorf("ParentID want %+v, have %+v", want, have)
}
if cSC.Sampled == nil {
t.Error("Sampled want explicit value, have nil")
} else if !*cSC.Sampled {
t.Errorf("Sampled want true, have %+v", *cSC.Sampled)
}
if want, have := int32(1), span.(*spanImpl).mustCollect; want != have {
t.Errorf("mustCollect want %d, have %d", want, have)
}
}
func TestParentSpanInSpanPerNodeMode(t *testing.T) {
rep := reporter.NewNoopReporter()
defer rep.Close()
tr, err := NewTracer(rep, WithSharedSpans(false))
if err != nil {
t.Fatalf("unable to create tracer instance: %+v", err)
}
pSC := model.SpanContext{
TraceID: model.TraceID{
High: 0,
Low: 1,
},
ID: model.ID(1),
}
span := tr.StartSpan("test", Kind(model.Server), Parent(pSC))
cSC := span.Context()
if cSC.Err != nil {
t.Errorf("Err want nil, have %+v", cSC.Err)
}
if want, have := pSC.Debug, cSC.Debug; want != have {
t.Errorf("Debug want %t, have %t", want, have)
}
if want, have := pSC.TraceID, cSC.TraceID; want != have {
t.Errorf("TraceID want %+v, have: %+v", want, have)
}
if cSC.ID == 0 {
t.Error("expected valid ID")
}
if cSC.ParentID == nil {
t.Error("ParentID want valid value, have nil")
} else if want, have := pSC.ID, *cSC.ParentID; want != have {
t.Errorf("ParentID want %+v, have %+v", want, have)
}
if cSC.Sampled == nil {
t.Error("Sampled want explicit value, have nil")
} else if !*cSC.Sampled {
t.Errorf("Sampled want true, have %+v", *cSC.Sampled)
}
if want, have := int32(1), span.(*spanImpl).mustCollect; want != have {
t.Errorf("mustCollect want %d, have %d", want, have)
}
}
func TestStartSpanFromContext(t *testing.T) {
ctx := context.Background()
rep := reporter.NewNoopReporter()
defer rep.Close()
tr, err := NewTracer(rep, WithSharedSpans(true))
if err != nil {
t.Fatalf("unable to create tracer instance: %+v", err)
}
if ctxSpan := SpanFromContext(ctx); ctxSpan != nil {
t.Errorf("SpanFromContext want nil, have %+v", ctxSpan)
}
cSpan := tr.StartSpan("test", Kind(model.Client))
ctx = NewContext(ctx, cSpan)
sSpan, _ := tr.StartSpanFromContext(ctx, "testChild", Kind(model.Server))
cS, sS := cSpan.(*spanImpl), sSpan.(*spanImpl)
if want, have := model.Client, cS.Kind; want != have {
t.Errorf("Kind want %+v, have %+v", want, have)
}
if want, have := model.Server, sS.Kind; want != have {
t.Errorf("Kind want %+v, have: %+v", want, have)
}
if want, have := cS.TraceID, sS.TraceID; want != have {
t.Errorf("TraceID want %+v, have: %+v", want, have)
}
if want, have := cS.ID, sS.ID; want != have {
t.Errorf("ID want %+v, have %+v", want, have)
}
if want, have := cS.ParentID, sS.ParentID; want != have {
t.Errorf("ParentID want %+v, have %+v", want, have)
}
}
func TestStartSpanFromContextForEmptyContext(t *testing.T) {
ctx := context.Background()
rep := reporter.NewNoopReporter()
defer rep.Close()
tr, err := NewTracer(rep, WithSampler(NeverSample))
if err != nil {
t.Fatalf("unable to create tracer instance: %+v", err)
}
span, _ := tr.StartSpanFromContext(ctx, "my span")
span.Finish()
}
func TestLocalEndpoint(t *testing.T) {
rep := reporter.NewNoopReporter()
defer rep.Close()
ep, err := NewEndpoint("my service", "localhost:80")
if err != nil {
t.Fatalf("expected valid endpoint, got error: %+v", err)
}
tracer, err := NewTracer(rep, WithLocalEndpoint(ep))
if err != nil {
t.Fatalf("expected valid tracer, got error: %+v", err)
}
want, have := ep, tracer.LocalEndpoint()
if have == nil {
t.Fatalf("endpoint want %+v, have nil", want)
}
if want.ServiceName != have.ServiceName {
t.Errorf("serviceName want %s, have %s", want.ServiceName, have.ServiceName)
}
if !want.IPv4.Equal(have.IPv4) {
t.Errorf("IPv4 endpoint want %+v, have %+v", want.IPv4, have.IPv4)
}
if !want.IPv6.Equal(have.IPv6) {
t.Errorf("IPv6 endpoint want %+v, have %+v", want.IPv6, have.IPv6)
}
}