Skip to content

Commit b83f931

Browse files
matej-gMrAlias
andauthored
Use tracer and meter test helpers from the OTEL repository instead of the internal ones (#414)
* Internal test helpers -> OTEL test helpers in instrumentation modules * Internal test helpers -> OTEL test helpers in propagators modules * Remove internal test helper packages * Update go.mod and go.sum in all affected modules * Unify test tracer provider / span recorder creation across modules * Update CHANGELOG.md * Fix merge of 'master' into trace-and-meter-helpers-from-otel * Remove leftover Co-authored-by: Tyler Yahn <[email protected]> Co-authored-by: Tyler Yahn <[email protected]>
1 parent 1d3290d commit b83f931

File tree

56 files changed

+451
-1381
lines changed

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

56 files changed

+451
-1381
lines changed

CHANGELOG.md

+1
Original file line numberDiff line numberDiff line change
@@ -16,6 +16,7 @@ This project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0.htm
1616

1717
- Add semantic version to `Tracer` / `Meter` created by instrumentation packages `otelsaram`, `otelrestful`, `otelmongo`, `otelhttp` and `otelhttptrace`. (#412)
1818
- Update instrumentation guidelines about tracer / meter semantic version. (#412)
19+
- Replace internal tracer and meter helpers by helpers from `go.opentelemetry.io/otel`. (#414)
1920
- gRPC instrumentation sets span attribute `rpc.grpc.status_code`. (#453)
2021

2122
## Fixed

go.mod

-7
Original file line numberDiff line numberDiff line change
@@ -1,10 +1,3 @@
11
module go.opentelemetry.io/contrib
22

33
go 1.14
4-
5-
require (
6-
github.com/davecgh/go-spew v1.1.1 // indirect
7-
github.com/kr/pretty v0.1.0 // indirect
8-
go.opentelemetry.io/otel v0.13.0
9-
gopkg.in/check.v1 v1.0.0-20190902080502-41f04d3bba15 // indirect
10-
)

go.sum

-25
Original file line numberDiff line numberDiff line change
@@ -1,25 +0,0 @@
1-
github.com/davecgh/go-spew v1.1.0/go.mod h1:J7Y8YcW2NihsgmVo/mv3lAwl/skON4iLHjSsI+c5H38=
2-
github.com/davecgh/go-spew v1.1.1 h1:vj9j/u1bqnvCEfJOwUhtlOARqs3+rkHYY13jYWTU97c=
3-
github.com/davecgh/go-spew v1.1.1/go.mod h1:J7Y8YcW2NihsgmVo/mv3lAwl/skON4iLHjSsI+c5H38=
4-
github.com/google/go-cmp v0.5.2 h1:X2ev0eStA3AbceY54o37/0PQ/UWqKEiiO2dKL5OPaFM=
5-
github.com/google/go-cmp v0.5.2/go.mod h1:v8dTdLbMG2kIc/vJvl+f65V22dbkXbowE6jgT/gNBxE=
6-
github.com/kr/pretty v0.1.0 h1:L/CwN0zerZDmRFUapSPitk6f+Q3+0za1rQkzVuMiMFI=
7-
github.com/kr/pretty v0.1.0/go.mod h1:dAy3ld7l9f0ibDNOQOHHMYYIIbhfbHSm3C4ZsoJORNo=
8-
github.com/kr/pty v1.1.1/go.mod h1:pFQYn66WHrOpPYNljwOMqo10TkYh1fy3cYio2l3bCsQ=
9-
github.com/kr/text v0.1.0 h1:45sCR5RtlFHMR4UwH9sdQ5TC8v0qDQCHnXt+kaKSTVE=
10-
github.com/kr/text v0.1.0/go.mod h1:4Jbv+DJW3UT/LiOwJeYQe1efqtUx/iVham/4vfdArNI=
11-
github.com/pmezard/go-difflib v1.0.0 h1:4DBwDE0NGyQoBHbLQYPwSUPoCMWR5BEzIk/f1lZbAQM=
12-
github.com/pmezard/go-difflib v1.0.0/go.mod h1:iKH77koFhYxTK1pcRnkKkqfTogsbg7gZNVY4sRDYZ/4=
13-
github.com/stretchr/objx v0.1.0 h1:4G4v2dO3VZwixGIRoQ5Lfboy6nUhCyYzaqnIAPPhYs4=
14-
github.com/stretchr/objx v0.1.0/go.mod h1:HFkY916IF+rwdDfMAkV7OtwuqBVzrE8GR6GFx+wExME=
15-
github.com/stretchr/testify v1.6.1 h1:hDPOHmpOpP40lSULcqw7IrRb/u7w6RpDC9399XyoNd0=
16-
github.com/stretchr/testify v1.6.1/go.mod h1:6Fq8oRcR53rry900zMqJjRRixrwX3KX962/h/Wwjteg=
17-
go.opentelemetry.io/otel v0.13.0 h1:2isEnyzjjJZq6r2EKMsFj4TxiQiexsM04AVhwbR/oBA=
18-
go.opentelemetry.io/otel v0.13.0/go.mod h1:dlSNewoRYikTkotEnxdmuBHgzT+k/idJSfDv/FxEnOY=
19-
golang.org/x/xerrors v0.0.0-20191204190536-9bdfabe68543 h1:E7g+9GITq07hpfrRu66IVDexMakfv52eLZ2CXBWiKr4=
20-
golang.org/x/xerrors v0.0.0-20191204190536-9bdfabe68543/go.mod h1:I/5z698sn9Ka8TeJc9MKroUUfqBBauWjQqLJ2OPfmY0=
21-
gopkg.in/check.v1 v0.0.0-20161208181325-20d25e280405/go.mod h1:Co6ibVJAznAaIkqp8huTwlJQCZ016jof/cbN4VW5Yz0=
22-
gopkg.in/check.v1 v1.0.0-20190902080502-41f04d3bba15 h1:YR8cESwS4TdDjEe65xsg0ogRM/Nc3DYOhEAlW+xobZo=
23-
gopkg.in/check.v1 v1.0.0-20190902080502-41f04d3bba15/go.mod h1:Co6ibVJAznAaIkqp8huTwlJQCZ016jof/cbN4VW5Yz0=
24-
gopkg.in/yaml.v3 v3.0.0-20200313102051-9f266ea9e77c h1:dUUwHk2QECo/6vqA44rthZ8ie2QXMNeKRTHCNY2nXvo=
25-
gopkg.in/yaml.v3 v3.0.0-20200313102051-9f266ea9e77c/go.mod h1:K4uyk7z7BCEPqu6E+C64Yfv1cQ7kz7rIZviUmN+EgEM=

instrumentation/github.com/Shopify/sarama/otelsarama/consumer_test.go

+14-12
Original file line numberDiff line numberDiff line change
@@ -29,7 +29,7 @@ import (
2929
otelpropagators "go.opentelemetry.io/otel/propagators"
3030
"go.opentelemetry.io/otel/semconv"
3131

32-
mocktracer "go.opentelemetry.io/contrib/internal/trace"
32+
"go.opentelemetry.io/otel/api/trace/tracetest"
3333
)
3434

3535
const (
@@ -39,7 +39,8 @@ const (
3939
func TestWrapPartitionConsumer(t *testing.T) {
4040
propagators := otelpropagators.TraceContext{}
4141
// Mock provider
42-
provider, mt := NewTracerProviderAndTracer()
42+
sr := new(tracetest.StandardSpanRecorder)
43+
provider := tracetest.NewTracerProvider(tracetest.WithSpanRecorder(sr))
4344

4445
// Mock partition consumer controller
4546
consumer := mocks.NewConsumer(t, sarama.NewConfig())
@@ -51,13 +52,14 @@ func TestWrapPartitionConsumer(t *testing.T) {
5152

5253
partitionConsumer = WrapPartitionConsumer(partitionConsumer, WithTracerProvider(provider), WithPropagators(propagators))
5354

54-
consumeAndCheck(t, mt, mockPartitionConsumer, partitionConsumer)
55+
consumeAndCheck(t, provider.Tracer(defaultTracerName), sr.Completed, mockPartitionConsumer, partitionConsumer)
5556
}
5657

5758
func TestWrapConsumer(t *testing.T) {
5859
propagators := otelpropagators.TraceContext{}
5960
// Mock provider
60-
provider, mt := NewTracerProviderAndTracer()
61+
sr := new(tracetest.StandardSpanRecorder)
62+
provider := tracetest.NewTracerProvider(tracetest.WithSpanRecorder(sr))
6163

6264
// Mock partition consumer controller
6365
mockConsumer := mocks.NewConsumer(t, sarama.NewConfig())
@@ -70,10 +72,10 @@ func TestWrapConsumer(t *testing.T) {
7072
partitionConsumer, err := consumer.ConsumePartition(topic, 0, 0)
7173
require.NoError(t, err)
7274

73-
consumeAndCheck(t, mt, mockPartitionConsumer, partitionConsumer)
75+
consumeAndCheck(t, provider.Tracer(defaultTracerName), sr.Completed, mockPartitionConsumer, partitionConsumer)
7476
}
7577

76-
func consumeAndCheck(t *testing.T, mt *mocktracer.Tracer, mockPartitionConsumer *mocks.PartitionConsumer, partitionConsumer sarama.PartitionConsumer) {
78+
func consumeAndCheck(t *testing.T, mt trace.Tracer, complFn func() []*tracetest.Span, mockPartitionConsumer *mocks.PartitionConsumer, partitionConsumer sarama.PartitionConsumer) {
7779
// Create message with span context
7880
ctx, _ := mt.Start(context.Background(), "")
7981
message := sarama.ConsumerMessage{Key: []byte("foo")}
@@ -93,7 +95,7 @@ func consumeAndCheck(t *testing.T, mt *mocktracer.Tracer, mockPartitionConsumer
9395
<-partitionConsumer.Messages()
9496

9597
// Check spans length
96-
spans := mt.EndedSpans()
98+
spans := complFn()
9799
assert.Len(t, spans, 2)
98100

99101
expectedList := []struct {
@@ -133,17 +135,17 @@ func consumeAndCheck(t *testing.T, mt *mocktracer.Tracer, mockPartitionConsumer
133135
t.Run(fmt.Sprint("index", i), func(t *testing.T) {
134136
span := spans[i]
135137

136-
assert.Equal(t, expected.parentSpanID, span.ParentSpanID)
138+
assert.Equal(t, expected.parentSpanID, span.ParentSpanID())
137139

138140
remoteSpanFromMessage := trace.RemoteSpanContextFromContext(propagators.Extract(context.Background(), NewConsumerMessageCarrier(msgList[i])))
139141
assert.Equal(t, span.SpanContext(), remoteSpanFromMessage,
140142
"span context should be injected into the consumer message headers")
141143

142-
assert.Equal(t, "kafka.consume", span.Name)
143-
assert.Equal(t, expected.kind, span.Kind)
144+
assert.Equal(t, "kafka.consume", span.Name())
145+
assert.Equal(t, expected.kind, span.SpanKind())
144146
assert.Equal(t, expected.msgKey, msgList[i].Key)
145147
for _, k := range expected.labelList {
146-
assert.Equal(t, k.Value, span.Attributes[k.Key], k.Key)
148+
assert.Equal(t, k.Value, span.Attributes()[k.Key], k.Key)
147149
}
148150
})
149151
}
@@ -164,7 +166,7 @@ func TestConsumerConsumePartitionWithError(t *testing.T) {
164166

165167
func BenchmarkWrapPartitionConsumer(b *testing.B) {
166168
// Mock provider
167-
provider, _ := NewTracerProviderAndTracer()
169+
provider := tracetest.NewTracerProvider()
168170

169171
mockPartitionConsumer, partitionConsumer := createMockPartitionConsumer(b)
170172

instrumentation/github.com/Shopify/sarama/otelsarama/example/go.sum

-2
Original file line numberDiff line numberDiff line change
@@ -37,7 +37,6 @@ github.com/jcmturner/gofork v1.0.0/go.mod h1:MK8+TM0La+2rjBD4jE12Kj1pCCxK7d2LK/U
3737
github.com/klauspost/compress v1.10.10/go.mod h1:aoV0uJVorq1K+umq18yTdKaF57EivdYsUV+/s2qKfXs=
3838
github.com/klauspost/compress v1.11.0 h1:wJbzvpYMVGG9iTI9VxpnNZfd4DzMPoCWze3GgSqz8yg=
3939
github.com/klauspost/compress v1.11.0/go.mod h1:aoV0uJVorq1K+umq18yTdKaF57EivdYsUV+/s2qKfXs=
40-
github.com/kr/pretty v0.1.0/go.mod h1:dAy3ld7l9f0ibDNOQOHHMYYIIbhfbHSm3C4ZsoJORNo=
4140
github.com/kr/pretty v0.2.0/go.mod h1:ipq/a2n7PKx3OHsz4KJII5eveXtPO4qwEXGdVfWzfnI=
4241
github.com/kr/pretty v0.2.1 h1:Fmg33tUaq4/8ym9TJN1x7sLJnHVwhP33CNkpYV/7rwI=
4342
github.com/kr/pretty v0.2.1/go.mod h1:ipq/a2n7PKx3OHsz4KJII5eveXtPO4qwEXGdVfWzfnI=
@@ -87,7 +86,6 @@ golang.org/x/xerrors v0.0.0-20191204190536-9bdfabe68543/go.mod h1:I/5z698sn9Ka8T
8786
golang.org/x/xerrors v0.0.0-20200804184101-5ec99f83aff1 h1:go1bK/D/BFZV2I8cIQd1NKEZ+0owSTG1fDTci4IqFcE=
8887
golang.org/x/xerrors v0.0.0-20200804184101-5ec99f83aff1/go.mod h1:I/5z698sn9Ka8TeJc9MKroUUfqBBauWjQqLJ2OPfmY0=
8988
gopkg.in/check.v1 v0.0.0-20161208181325-20d25e280405/go.mod h1:Co6ibVJAznAaIkqp8huTwlJQCZ016jof/cbN4VW5Yz0=
90-
gopkg.in/check.v1 v1.0.0-20190902080502-41f04d3bba15/go.mod h1:Co6ibVJAznAaIkqp8huTwlJQCZ016jof/cbN4VW5Yz0=
9189
gopkg.in/check.v1 v1.0.0-20200227125254-8fa46927fb4f/go.mod h1:Co6ibVJAznAaIkqp8huTwlJQCZ016jof/cbN4VW5Yz0=
9290
gopkg.in/check.v1 v1.0.0-20200902074654-038fdea0a05b h1:QRR6H1YWRnHb4Y/HeNFCTJLFVxaq6wH4YuVdsUOr75U=
9391
gopkg.in/check.v1 v1.0.0-20200902074654-038fdea0a05b/go.mod h1:Co6ibVJAznAaIkqp8huTwlJQCZ016jof/cbN4VW5Yz0=

instrumentation/github.com/Shopify/sarama/otelsarama/go.sum

-3
Original file line numberDiff line numberDiff line change
@@ -29,7 +29,6 @@ github.com/jcmturner/gofork v1.0.0 h1:J7uCkflzTEhUZ64xqKnkDxq3kzc96ajM1Gli5ktUem
2929
github.com/jcmturner/gofork v1.0.0/go.mod h1:MK8+TM0La+2rjBD4jE12Kj1pCCxK7d2LK/UM3ncEo0o=
3030
github.com/klauspost/compress v1.10.10 h1:a/y8CglcM7gLGYmlbP/stPE5sR3hbhFRUjCBfd/0B3I=
3131
github.com/klauspost/compress v1.10.10/go.mod h1:aoV0uJVorq1K+umq18yTdKaF57EivdYsUV+/s2qKfXs=
32-
github.com/kr/pretty v0.1.0/go.mod h1:dAy3ld7l9f0ibDNOQOHHMYYIIbhfbHSm3C4ZsoJORNo=
3332
github.com/kr/pretty v0.2.0 h1:s5hAObm+yFO5uHYt5dYjxi2rXrsnmRpJx4OYvIWUaQs=
3433
github.com/kr/pretty v0.2.0/go.mod h1:ipq/a2n7PKx3OHsz4KJII5eveXtPO4qwEXGdVfWzfnI=
3534
github.com/kr/pty v1.1.1/go.mod h1:pFQYn66WHrOpPYNljwOMqo10TkYh1fy3cYio2l3bCsQ=
@@ -69,8 +68,6 @@ golang.org/x/tools v0.0.0-20180917221912-90fa682c2a6e/go.mod h1:n7NCudcB/nEzxVGm
6968
golang.org/x/xerrors v0.0.0-20191204190536-9bdfabe68543 h1:E7g+9GITq07hpfrRu66IVDexMakfv52eLZ2CXBWiKr4=
7069
golang.org/x/xerrors v0.0.0-20191204190536-9bdfabe68543/go.mod h1:I/5z698sn9Ka8TeJc9MKroUUfqBBauWjQqLJ2OPfmY0=
7170
gopkg.in/check.v1 v0.0.0-20161208181325-20d25e280405/go.mod h1:Co6ibVJAznAaIkqp8huTwlJQCZ016jof/cbN4VW5Yz0=
72-
gopkg.in/check.v1 v1.0.0-20190902080502-41f04d3bba15 h1:YR8cESwS4TdDjEe65xsg0ogRM/Nc3DYOhEAlW+xobZo=
73-
gopkg.in/check.v1 v1.0.0-20190902080502-41f04d3bba15/go.mod h1:Co6ibVJAznAaIkqp8huTwlJQCZ016jof/cbN4VW5Yz0=
7471
gopkg.in/check.v1 v1.0.0-20200227125254-8fa46927fb4f h1:BLraFXnmrev5lT+xlilqcH8XK9/i0At2xKjWk4p6zsU=
7572
gopkg.in/check.v1 v1.0.0-20200227125254-8fa46927fb4f/go.mod h1:Co6ibVJAznAaIkqp8huTwlJQCZ016jof/cbN4VW5Yz0=
7673
gopkg.in/jcmturner/aescts.v1 v1.0.1 h1:cVVZBK2b1zY26haWB4vbBiZrfFQnfbTVrE3xZq6hrEw=

0 commit comments

Comments
 (0)