/
opentelemetry_test.go
95 lines (77 loc) · 2.81 KB
/
opentelemetry_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
package client
import (
"context"
"testing"
"github.com/stretchr/testify/assert"
"github.com/stretchr/testify/require"
"go.opentelemetry.io/otel"
tracesdk "go.opentelemetry.io/otel/sdk/trace"
"go.opentelemetry.io/otel/sdk/trace/tracetest"
"go.opentelemetry.io/otel/trace"
"github.com/go-openapi/runtime"
)
func Test_OpenTelemetryRuntime_submit(t *testing.T) {
t.Parallel()
exporter := tracetest.NewInMemoryExporter()
tp := tracesdk.NewTracerProvider(
tracesdk.WithSampler(tracesdk.AlwaysSample()),
tracesdk.WithSyncer(exporter),
)
otel.SetTracerProvider(tp)
tracer := tp.Tracer("go-runtime")
ctx, _ := tracer.Start(context.Background(), "op")
testOpenTelemetrySubmit(t, testOperation(ctx), exporter, 1)
}
// func Test_OpenTelemetryRuntime_submit_nilAuthInfo(t *testing.T) {
// t.Parallel()
// tracer := mocktracer.New()
// _, ctx := opentracing.StartSpanFromContextWithTracer(context.Background(), tracer, "op")
// operation := testOperation(ctx)
// operation.AuthInfo = nil
// testOpenTelemetrySubmit(t, operation, tracer, 1)
// }
// func Test_OpenTelemetryRuntime_submit_nilContext(t *testing.T) {
// t.Parallel()
// tracer := mocktracer.New()
// _, ctx := opentracing.StartSpanFromContextWithTracer(context.Background(), tracer, "op")
// operation := testOperation(ctx)
// operation.Context = nil
// testOpenTelemetrySubmit(t, operation, tracer, 0) // just don't panic
// }
// func Test_injectOpenTelemetrySpanContext(t *testing.T) {
// t.Parallel()
// tracer := mocktracer.New()
// _, ctx := opentracing.StartSpanFromContextWithTracer(context.Background(), tracer, "op")
// header := map[string][]string{}
// createOpenTelemetryClientSpan(testOperation(ctx), header, "", nil)
// // values are random - just check that something was injected
// assert.Len(t, header, 3)
// }
func testOpenTelemetrySubmit(t *testing.T, operation *runtime.ClientOperation, exporter *tracetest.InMemoryExporter, expectedSpans int) {
header := map[string][]string{}
r := newOpenTelemetryTransport(&mockRuntime{runtime.TestClientRequest{Headers: header}},
"remote_host",
[]trace.SpanStartOption{})
// // opentracing.Tag{
// Key: string(ext.PeerService),
// Value: "service",
// }
_, err := r.Submit(operation)
require.NoError(t, err)
l := exporter.GetSpans()
assert.Len(t, l, expectedSpans)
// if expectedSpans == 1 {
// span := tracer.FinishedSpans()[0]
// assert.Equal(t, "getCluster", span.OperationName)
// assert.Equal(t, map[string]interface{}{
// "component": "go-openapi",
// "http.method": "GET",
// "http.path": "/kubernetes-clusters/{cluster_id}",
// "http.status_code": uint16(490),
// "peer.hostname": "remote_host",
// "peer.service": "service",
// "span.kind": ext.SpanKindRPCClientEnum,
// "error": true,
// }, span.Tags())
// }
}