Skip to content

Commit 312d6c7

Browse files
committed
Add test for sarama producer
1 parent 3adea50 commit 312d6c7

File tree

8 files changed

+341
-10
lines changed

8 files changed

+341
-10
lines changed

instrumentation/github.com/Shopify/sarama/consumer.go

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -18,6 +18,7 @@ import (
1818
"context"
1919

2020
"github.com/Shopify/sarama"
21+
2122
"go.opentelemetry.io/otel/api/kv"
2223
"go.opentelemetry.io/otel/api/propagation"
2324
"go.opentelemetry.io/otel/api/standard"

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

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -22,6 +22,7 @@ import (
2222
"github.com/Shopify/sarama"
2323
"github.com/Shopify/sarama/mocks"
2424
"github.com/stretchr/testify/assert"
25+
2526
"go.opentelemetry.io/otel/api/global"
2627
"go.opentelemetry.io/otel/api/kv"
2728
"go.opentelemetry.io/otel/api/propagation"
@@ -161,8 +162,9 @@ func TestConsumer_ConsumePartitionWithError(t *testing.T) {
161162
mockConsumer.ExpectConsumePartition(topic, 0, 0)
162163

163164
consumer := WrapConsumer(serviceName, mockConsumer)
164-
consumer.ConsumePartition(topic, 0, 0)
165-
// Consume twice
166165
_, err := consumer.ConsumePartition(topic, 0, 0)
166+
assert.NoError(t, err)
167+
// Consume twice
168+
_, err = consumer.ConsumePartition(topic, 0, 0)
167169
assert.Error(t, err)
168170
}

instrumentation/github.com/Shopify/sarama/go.mod

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -9,6 +9,6 @@ require (
99
github.com/google/uuid v1.1.1
1010
github.com/stretchr/testify v1.6.1
1111
go.opentelemetry.io/contrib v0.7.0
12-
go.opentelemetry.io/otel v0.7.0
12+
go.opentelemetry.io/otel v0.8.0
1313
google.golang.org/grpc v1.30.0
1414
)

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

Lines changed: 6 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -64,7 +64,7 @@ github.com/kr/pretty v0.2.0/go.mod h1:ipq/a2n7PKx3OHsz4KJII5eveXtPO4qwEXGdVfWzfn
6464
github.com/kr/pty v1.1.1/go.mod h1:pFQYn66WHrOpPYNljwOMqo10TkYh1fy3cYio2l3bCsQ=
6565
github.com/kr/text v0.1.0 h1:45sCR5RtlFHMR4UwH9sdQ5TC8v0qDQCHnXt+kaKSTVE=
6666
github.com/kr/text v0.1.0/go.mod h1:4Jbv+DJW3UT/LiOwJeYQe1efqtUx/iVham/4vfdArNI=
67-
github.com/opentracing/opentracing-go v1.1.1-0.20190913142402-a7454ce5950e/go.mod h1:UkNAQd3GIcIGf0SeVgPpRdFStlNbqXla1AfSYxPUl2o=
67+
github.com/opentracing/opentracing-go v1.2.0/go.mod h1:GxEUsuufX4nBwe+T+Wl9TAgYrxe9dPLANfrWvHYVTgc=
6868
github.com/pierrec/lz4 v2.4.1+incompatible h1:mFe7ttWaflA46Mhqh+jUfjp2qTbPYxLB2/OyBppH9dg=
6969
github.com/pierrec/lz4 v2.4.1+incompatible/go.mod h1:pdkljMzZIN41W+lC3N2tnIh5sFi+IEE17M5jbnwPHcY=
7070
github.com/pmezard/go-difflib v1.0.0 h1:4DBwDE0NGyQoBHbLQYPwSUPoCMWR5BEzIk/f1lZbAQM=
@@ -73,13 +73,14 @@ github.com/prometheus/client_model v0.0.0-20190812154241-14fe0d1b01d4/go.mod h1:
7373
github.com/rcrowley/go-metrics v0.0.0-20190826022208-cac0b30c2563 h1:dY6ETXrvDG7Sa4vE8ZQG4yqWg6UnOcbqTAahkV813vQ=
7474
github.com/rcrowley/go-metrics v0.0.0-20190826022208-cac0b30c2563/go.mod h1:bCqnVzQkZxMG4s8nGwiZ5l3QUCyqpo9Y+/ZMZ9VjZe4=
7575
github.com/stretchr/objx v0.1.0/go.mod h1:HFkY916IF+rwdDfMAkV7OtwuqBVzrE8GR6GFx+wExME=
76+
github.com/stretchr/testify v1.3.0/go.mod h1:M5WIy9Dh21IEIfnGCwXGc5bZfKNJtfHm1UVUgZn+9EI=
7677
github.com/stretchr/testify v1.4.0/go.mod h1:j7eGeouHqKxXV5pUuKE4zz7dFj8WfuZ+81PSLYec5m4=
7778
github.com/stretchr/testify v1.6.1 h1:hDPOHmpOpP40lSULcqw7IrRb/u7w6RpDC9399XyoNd0=
7879
github.com/stretchr/testify v1.6.1/go.mod h1:6Fq8oRcR53rry900zMqJjRRixrwX3KX962/h/Wwjteg=
7980
github.com/xdg/scram v0.0.0-20180814205039-7eeb5667e42c/go.mod h1:lB8K/P019DLNhemzwFU4jHLhdvlE6uDZjXFejJXr49I=
8081
github.com/xdg/stringprep v1.0.0/go.mod h1:Jhud4/sHMO4oL310DaZAKk9ZaJ08SJfe+sJh0HrGL1Y=
81-
go.opentelemetry.io/otel v0.7.0 h1:u43jukpwqR8EsyeJOMgrsUgZwVI1e1eVw7yuzRkD1l0=
82-
go.opentelemetry.io/otel v0.7.0/go.mod h1:aZMyHG5TqDOXEgH2tyLiXSUKly1jT3yqE9PmrzIeCdo=
82+
go.opentelemetry.io/otel v0.8.0 h1:he/8j/EBlKjENVtDvFalawIUcQ+1E3uHRsvJZWLIa7M=
83+
go.opentelemetry.io/otel v0.8.0/go.mod h1:ckxzUEfk7tAkTwEMVdkllBM+YOfE/K9iwg6zYntFYSg=
8384
golang.org/x/crypto v0.0.0-20190308221718-c2843e01d9a2/go.mod h1:djNgcEr1/C05ACkg1iLfiJU5Ep61QUkGW8qpdssI0+w=
8485
golang.org/x/crypto v0.0.0-20200204104054-c9f3fb736b72 h1:+ELyKg6m8UBf0nPFSqD0mi7zUfwPyXo23HNjMnXPz7w=
8586
golang.org/x/crypto v0.0.0-20200204104054-c9f3fb736b72/go.mod h1:LzIPMQfyMNhhGPhUkYOs5KpL4U8rLKemX1yGLhDgUto=
@@ -92,6 +93,7 @@ golang.org/x/net v0.0.0-20180826012351-8a410e7b638d/go.mod h1:mL1N/T3taQHkDXs73r
9293
golang.org/x/net v0.0.0-20190213061140-3a22650c66bd/go.mod h1:mL1N/T3taQHkDXs73rZJwtUhF3w3ftmwwsq0BUmARs4=
9394
golang.org/x/net v0.0.0-20190311183353-d8887717615a/go.mod h1:t9HGtf8HONx5eT2rtn7q6eTqICYqUVnKs3thJo3Qplg=
9495
golang.org/x/net v0.0.0-20190404232315-eb5bcb51f2a3/go.mod h1:t9HGtf8HONx5eT2rtn7q6eTqICYqUVnKs3thJo3Qplg=
96+
golang.org/x/net v0.0.0-20190613194153-d28f0bde5980/go.mod h1:z5CRVTTTmAJ677TzLLGU+0bjPO0LkuOLi4/5GtJWs/s=
9597
golang.org/x/net v0.0.0-20200202094626-16171245cfb2 h1:CCH4IOTTfewWjGOlSp+zGcjutRKlBEZQ6wTn8ozI/nI=
9698
golang.org/x/net v0.0.0-20200202094626-16171245cfb2/go.mod h1:z5CRVTTTmAJ677TzLLGU+0bjPO0LkuOLi4/5GtJWs/s=
9799
golang.org/x/oauth2 v0.0.0-20180821212333-d2e6202438be/go.mod h1:N/0e6XlmueqKjAGxoOufVs8QHGRruUQn6yWY3a++T0U=
@@ -101,6 +103,7 @@ golang.org/x/sync v0.0.0-20190423024810-112230192c58/go.mod h1:RxMgew5VJxzue5/jJ
101103
golang.org/x/sys v0.0.0-20180830151530-49385e6e1522/go.mod h1:STP8DvDyc/dI5b8T5hshtkjS+E42TnysNCUPdjciGhY=
102104
golang.org/x/sys v0.0.0-20190215142949-d0b11bdaac8a/go.mod h1:STP8DvDyc/dI5b8T5hshtkjS+E42TnysNCUPdjciGhY=
103105
golang.org/x/sys v0.0.0-20190412213103-97732733099d/go.mod h1:h1NjWce9XRLGQEsW7wpKNCjG9DtNlClVuFLEZdDNbEs=
106+
golang.org/x/sys v0.0.0-20200615200032-f1bc736245b1/go.mod h1:h1NjWce9XRLGQEsW7wpKNCjG9DtNlClVuFLEZdDNbEs=
104107
golang.org/x/text v0.3.0/go.mod h1:NqM8EUOU14njkJ3fqMW+pc6Ldnwhi/IjpwHt7yyuwOQ=
105108
golang.org/x/text v0.3.2/go.mod h1:bEr9sfX3Q8Zfm5fL9x+3itogRgK3+ptLWKqgva+5dAk=
106109
golang.org/x/tools v0.0.0-20180917221912-90fa682c2a6e/go.mod h1:n7NCudcB/nEzxVGmLbDWY5pfWTLqBcC2KZ6jyYvM4mQ=

instrumentation/github.com/Shopify/sarama/message.go

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -16,6 +16,7 @@ package sarama
1616

1717
import (
1818
"github.com/Shopify/sarama"
19+
1920
"go.opentelemetry.io/otel/api/propagation"
2021
)
2122

@@ -35,7 +36,7 @@ func NewProducerMessageCarrier(msg *sarama.ProducerMessage) ProducerMessageCarri
3536
// Get retrieves a single value for a given key.
3637
func (c ProducerMessageCarrier) Get(key string) string {
3738
for _, h := range c.msg.Headers {
38-
if string(h.Key) == key{
39+
if string(h.Key) == key {
3940
return string(h.Value)
4041
}
4142
}
@@ -70,7 +71,7 @@ func NewConsumerMessageCarrier(msg *sarama.ConsumerMessage) ConsumerMessageCarri
7071
// Get retrieves a single value for a given key.
7172
func (c ConsumerMessageCarrier) Get(key string) string {
7273
for _, h := range c.msg.Headers {
73-
if h != nil && string(h.Key) == key{
74+
if h != nil && string(h.Key) == key {
7475
return string(h.Value)
7576
}
7677
}

instrumentation/github.com/Shopify/sarama/option_test.go

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -18,6 +18,7 @@ import (
1818
"testing"
1919

2020
"github.com/stretchr/testify/assert"
21+
2122
"go.opentelemetry.io/otel/api/global"
2223
)
2324

instrumentation/github.com/Shopify/sarama/producer.go

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -19,11 +19,12 @@ import (
1919

2020
"github.com/Shopify/sarama"
2121
"github.com/google/uuid"
22+
"google.golang.org/grpc/codes"
23+
2224
"go.opentelemetry.io/otel/api/kv"
2325
"go.opentelemetry.io/otel/api/propagation"
2426
"go.opentelemetry.io/otel/api/standard"
2527
"go.opentelemetry.io/otel/api/trace"
26-
"google.golang.org/grpc/codes"
2728
)
2829

2930
type syncProducer struct {
@@ -109,7 +110,7 @@ func (p *asyncProducer) Close() error {
109110

110111
// WrapAsyncProducer wraps a sarama.AsyncProducer so that all produced messages
111112
// are traced. It requires the underlying sarama Config so we can know whether
112-
// or not sucesses will be returned.
113+
// or not successes will be returned.
113114
//
114115
// If `Return.Successes` is false, there is no way to know partition and offset of
115116
// the message.

0 commit comments

Comments
 (0)