...
1 package ext_test
2
3 import (
4 "fmt"
5 "reflect"
6 "testing"
7
8 "github.com/stretchr/testify/assert"
9
10 "github.com/opentracing/opentracing-go/ext"
11 "github.com/opentracing/opentracing-go/log"
12 "github.com/opentracing/opentracing-go/mocktracer"
13 )
14
15 func TestLogError(t *testing.T) {
16 tracer := mocktracer.New()
17 span := tracer.StartSpan("my-trace")
18 ext.Component.Set(span, "my-awesome-library")
19 ext.SamplingPriority.Set(span, 1)
20 err := fmt.Errorf("my error")
21 ext.LogError(span, err, log.Message("my optional msg text"))
22
23 span.Finish()
24
25 rawSpan := tracer.FinishedSpans()[0]
26 assert.Equal(t, map[string]interface{}{
27 "component": "my-awesome-library",
28 "error": true,
29 }, rawSpan.Tags())
30
31 assert.Equal(t, len(rawSpan.Logs()), 1)
32 fields := rawSpan.Logs()[0].Fields
33 assert.Equal(t, []mocktracer.MockKeyValue{
34 {
35 Key: "event",
36 ValueKind: reflect.String,
37 ValueString: "error",
38 },
39 {
40 Key: "error.object",
41 ValueKind: reflect.String,
42 ValueString: err.Error(),
43 },
44 {
45 Key: "message",
46 ValueKind: reflect.String,
47 ValueString: "my optional msg text",
48 },
49 }, fields)
50 }
51
View as plain text