Skip to content

Commit a59885b

Browse files
authored
Update google.golang.org/grpc/otelgrpc instrumentation to not accept Tracer (#373)
* Update google.golang.org/grpc/otelgrpc * Add changes to changelog * Update example * Clean unused const in benchmark_test.go
1 parent 8244cc7 commit a59885b

File tree

12 files changed

+132
-85
lines changed

12 files changed

+132
-85
lines changed

CHANGELOG.md

+2
Original file line numberDiff line numberDiff line change
@@ -10,6 +10,8 @@ This project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0.htm
1010

1111
## Changed
1212

13+
- The `go.opentelemetry.io/contrib/instrumentation/google.golang.org/grpc` package instrumentation no longer accepts a `Tracer` as an argument to the interceptor function.
14+
Instead, a new `WithTracerProvider` option is added to configure the `TracerProvider` used when creating the `Tracer` for the instrumentation. (#373)
1315
- Remove `go.opentelemetry.io/otel/sdk` dependency from instrumentation. (#381)
1416

1517
### Fixed

instrumentation/google.golang.org/grpc/otelgrpc/benchmark_test.go

+14-9
Original file line numberDiff line numberDiff line change
@@ -28,12 +28,9 @@ import (
2828
"go.opentelemetry.io/otel/api/trace/tracetest"
2929
)
3030

31-
const (
32-
bufSize = 2048
33-
instName = "go.opentelemetry.io/contrib/instrumentation/google.golang.org/grpc/otelgrpc"
34-
)
31+
const bufSize = 2048
3532

36-
var tracer = tracetest.NewTracerProvider().Tracer(instName)
33+
var tracerProvider = tracetest.NewTracerProvider()
3734

3835
func benchmark(b *testing.B, cOpt []grpc.DialOption, sOpt []grpc.ServerOption) {
3936
l := bufconn.Listen(bufSize)
@@ -85,24 +82,32 @@ func BenchmarkNoInstrumentation(b *testing.B) {
8582

8683
func BenchmarkUnaryServerInterceptor(b *testing.B) {
8784
benchmark(b, nil, []grpc.ServerOption{
88-
grpc.UnaryInterceptor(otelgrpc.UnaryServerInterceptor(tracer)),
85+
grpc.UnaryInterceptor(otelgrpc.UnaryServerInterceptor(
86+
otelgrpc.WithTracerProvider(tracerProvider),
87+
)),
8988
})
9089
}
9190

9291
func BenchmarkStreamServerInterceptor(b *testing.B) {
9392
benchmark(b, nil, []grpc.ServerOption{
94-
grpc.StreamInterceptor(otelgrpc.StreamServerInterceptor(tracer)),
93+
grpc.StreamInterceptor(otelgrpc.StreamServerInterceptor(
94+
otelgrpc.WithTracerProvider(tracerProvider),
95+
)),
9596
})
9697
}
9798

9899
func BenchmarkUnaryClientInterceptor(b *testing.B) {
99100
benchmark(b, []grpc.DialOption{
100-
grpc.WithUnaryInterceptor(otelgrpc.UnaryClientInterceptor(tracer)),
101+
grpc.WithUnaryInterceptor(otelgrpc.UnaryClientInterceptor(
102+
otelgrpc.WithTracerProvider(tracerProvider),
103+
)),
101104
}, nil)
102105
}
103106

104107
func BenchmarkStreamClientInterceptor(b *testing.B) {
105108
benchmark(b, []grpc.DialOption{
106-
grpc.WithStreamInterceptor(otelgrpc.StreamClientInterceptor(tracer)),
109+
grpc.WithStreamInterceptor(otelgrpc.StreamClientInterceptor(
110+
otelgrpc.WithTracerProvider(tracerProvider),
111+
)),
107112
}, nil)
108113
}

instrumentation/google.golang.org/grpc/otelgrpc/example/client/main.go

+2-3
Original file line numberDiff line numberDiff line change
@@ -22,7 +22,6 @@ import (
2222

2323
"go.opentelemetry.io/contrib/instrumentation/google.golang.org/grpc/otelgrpc/example/api"
2424
"go.opentelemetry.io/contrib/instrumentation/google.golang.org/grpc/otelgrpc/example/config"
25-
"go.opentelemetry.io/otel/api/global"
2625

2726
"go.opentelemetry.io/contrib/instrumentation/google.golang.org/grpc/otelgrpc"
2827

@@ -35,8 +34,8 @@ func main() {
3534

3635
var conn *grpc.ClientConn
3736
conn, err := grpc.Dial(":7777", grpc.WithInsecure(),
38-
grpc.WithUnaryInterceptor(otelgrpc.UnaryClientInterceptor(global.Tracer(""))),
39-
grpc.WithStreamInterceptor(otelgrpc.StreamClientInterceptor(global.Tracer(""))),
37+
grpc.WithUnaryInterceptor(otelgrpc.UnaryClientInterceptor()),
38+
grpc.WithStreamInterceptor(otelgrpc.StreamClientInterceptor()),
4039
)
4140

4241
if err != nil {

instrumentation/google.golang.org/grpc/otelgrpc/example/go.sum

+11
Original file line numberDiff line numberDiff line change
@@ -10,6 +10,8 @@ github.com/client9/misspell v0.3.4/go.mod h1:qj6jICC3Q7zFZvVWo7KLAzC3yx5G7kyvSDk
1010
github.com/cncf/udpa/go v0.0.0-20191209042840-269d4d468f6f/go.mod h1:M8M6+tZqaGXZJjfX53e64911xZQV5JYwmTeXPW+k8Sc=
1111
github.com/davecgh/go-spew v1.1.0 h1:ZDRjVQ15GmhC3fiQ8ni8+OwkZQO4DARzQgrnXU1Liz8=
1212
github.com/davecgh/go-spew v1.1.0/go.mod h1:J7Y8YcW2NihsgmVo/mv3lAwl/skON4iLHjSsI+c5H38=
13+
github.com/davecgh/go-spew v1.1.1 h1:vj9j/u1bqnvCEfJOwUhtlOARqs3+rkHYY13jYWTU97c=
14+
github.com/davecgh/go-spew v1.1.1/go.mod h1:J7Y8YcW2NihsgmVo/mv3lAwl/skON4iLHjSsI+c5H38=
1315
github.com/envoyproxy/go-control-plane v0.9.0/go.mod h1:YTl/9mNaCwkRvm6d1a2C3ymFceY/DCBVvsKhRF0iEA4=
1416
github.com/envoyproxy/go-control-plane v0.9.4/go.mod h1:6rpuAdCZL397s3pYoYcLgu1mIlRU8Am5FuJP05cCM98=
1517
github.com/envoyproxy/protoc-gen-validate v0.1.0/go.mod h1:iSmxcyjqTsJpI2R4NaDN7+kN2VEUnK/pcBlmesArF7c=
@@ -33,12 +35,19 @@ github.com/google/go-cmp v0.5.2 h1:X2ev0eStA3AbceY54o37/0PQ/UWqKEiiO2dKL5OPaFM=
3335
github.com/google/go-cmp v0.5.2/go.mod h1:v8dTdLbMG2kIc/vJvl+f65V22dbkXbowE6jgT/gNBxE=
3436
github.com/google/gofuzz v1.1.0 h1:Hsa8mG0dQ46ij8Sl2AYJDUv1oA9/d6Vk+3LG99Oe02g=
3537
github.com/google/gofuzz v1.1.0/go.mod h1:dBl0BpW6vV/+mYPU4Po3pmUjxk6FQPldtuIdl/M65Eg=
38+
github.com/kr/pretty v0.1.0 h1:L/CwN0zerZDmRFUapSPitk6f+Q3+0za1rQkzVuMiMFI=
39+
github.com/kr/pretty v0.1.0/go.mod h1:dAy3ld7l9f0ibDNOQOHHMYYIIbhfbHSm3C4ZsoJORNo=
40+
github.com/kr/pty v1.1.1/go.mod h1:pFQYn66WHrOpPYNljwOMqo10TkYh1fy3cYio2l3bCsQ=
41+
github.com/kr/text v0.1.0 h1:45sCR5RtlFHMR4UwH9sdQ5TC8v0qDQCHnXt+kaKSTVE=
42+
github.com/kr/text v0.1.0/go.mod h1:4Jbv+DJW3UT/LiOwJeYQe1efqtUx/iVham/4vfdArNI=
3643
github.com/pmezard/go-difflib v1.0.0 h1:4DBwDE0NGyQoBHbLQYPwSUPoCMWR5BEzIk/f1lZbAQM=
3744
github.com/pmezard/go-difflib v1.0.0/go.mod h1:iKH77koFhYxTK1pcRnkKkqfTogsbg7gZNVY4sRDYZ/4=
3845
github.com/prometheus/client_model v0.0.0-20190812154241-14fe0d1b01d4/go.mod h1:xMI15A0UPsDsEKsMN9yxemIoYk6Tm2C1GtYGdfGttqA=
3946
github.com/stretchr/objx v0.1.0/go.mod h1:HFkY916IF+rwdDfMAkV7OtwuqBVzrE8GR6GFx+wExME=
4047
github.com/stretchr/testify v1.6.1 h1:hDPOHmpOpP40lSULcqw7IrRb/u7w6RpDC9399XyoNd0=
4148
github.com/stretchr/testify v1.6.1/go.mod h1:6Fq8oRcR53rry900zMqJjRRixrwX3KX962/h/Wwjteg=
49+
go.opentelemetry.io/contrib v0.12.0 h1:vLtYifaYQD8i9ncT07vLqUmo2RivECfpNJ2kv3YKnK0=
50+
go.opentelemetry.io/contrib v0.12.0/go.mod h1:onlxH6TKFRkW2Xgc5IO37kPYz3v7wMzh/FrBxsQxCt4=
4251
go.opentelemetry.io/otel v0.12.0 h1:bwWaPd/h2q+U6KdKaAiOS5GLwOMd1LDt9iNaeyIoAI8=
4352
go.opentelemetry.io/otel v0.12.0/go.mod h1:dlSNewoRYikTkotEnxdmuBHgzT+k/idJSfDv/FxEnOY=
4453
go.opentelemetry.io/otel/exporters/stdout v0.12.0 h1:ji9VVPmKg+oONcqwULcO0AHZseGU6CFOIdvwKCxNZ9Y=
@@ -96,6 +105,8 @@ google.golang.org/protobuf v1.23.0 h1:4MY060fB1DLGMB/7MBTLnwQUY6+F09GEiz6SsrNqyz
96105
google.golang.org/protobuf v1.23.0/go.mod h1:EGpADcykh3NcUnDUJcl1+ZksZNG86OlYog2l/sGQquU=
97106
gopkg.in/check.v1 v0.0.0-20161208181325-20d25e280405 h1:yhCVgyC4o1eVCa2tZl7eS0r+SDo693bJlVdllGtEeKM=
98107
gopkg.in/check.v1 v0.0.0-20161208181325-20d25e280405/go.mod h1:Co6ibVJAznAaIkqp8huTwlJQCZ016jof/cbN4VW5Yz0=
108+
gopkg.in/check.v1 v1.0.0-20190902080502-41f04d3bba15 h1:YR8cESwS4TdDjEe65xsg0ogRM/Nc3DYOhEAlW+xobZo=
109+
gopkg.in/check.v1 v1.0.0-20190902080502-41f04d3bba15/go.mod h1:Co6ibVJAznAaIkqp8huTwlJQCZ016jof/cbN4VW5Yz0=
99110
gopkg.in/yaml.v3 v3.0.0-20200313102051-9f266ea9e77c h1:dUUwHk2QECo/6vqA44rthZ8ie2QXMNeKRTHCNY2nXvo=
100111
gopkg.in/yaml.v3 v3.0.0-20200313102051-9f266ea9e77c/go.mod h1:K4uyk7z7BCEPqu6E+C64Yfv1cQ7kz7rIZviUmN+EgEM=
101112
honnef.co/go/tools v0.0.0-20190102054323-c2f93a96b099/go.mod h1:rf3lG4BRIbNafJWhAfAdb/ePZxsR/4RtNHQocxwk9r4=

instrumentation/google.golang.org/grpc/otelgrpc/example/server/main.go

+2-3
Original file line numberDiff line numberDiff line change
@@ -24,7 +24,6 @@ import (
2424

2525
"go.opentelemetry.io/contrib/instrumentation/google.golang.org/grpc/otelgrpc/example/api"
2626
"go.opentelemetry.io/contrib/instrumentation/google.golang.org/grpc/otelgrpc/example/config"
27-
"go.opentelemetry.io/otel/api/global"
2827

2928
"go.opentelemetry.io/contrib/instrumentation/google.golang.org/grpc/otelgrpc"
3029

@@ -118,8 +117,8 @@ func main() {
118117
}
119118

120119
s := grpc.NewServer(
121-
grpc.UnaryInterceptor(otelgrpc.UnaryServerInterceptor(global.Tracer(""))),
122-
grpc.StreamInterceptor(otelgrpc.StreamServerInterceptor(global.Tracer(""))),
120+
grpc.UnaryInterceptor(otelgrpc.UnaryServerInterceptor()),
121+
grpc.StreamInterceptor(otelgrpc.StreamServerInterceptor()),
123122
)
124123

125124
api.RegisterHelloServiceServer(s, &server{})

instrumentation/google.golang.org/grpc/otelgrpc/example_interceptor_test.go

+4-20
Original file line numberDiff line numberDiff line change
@@ -16,36 +16,20 @@ package otelgrpc
1616

1717
import (
1818
"google.golang.org/grpc"
19-
20-
"go.opentelemetry.io/otel/api/global"
2119
)
2220

2321
func ExampleStreamClientInterceptor() {
24-
tracer := global.Tracer("client-instrumentation")
25-
_, _ = grpc.Dial(
26-
"localhost",
27-
grpc.WithStreamInterceptor(StreamClientInterceptor(tracer)),
28-
)
22+
_, _ = grpc.Dial("localhost", grpc.WithStreamInterceptor(StreamClientInterceptor()))
2923
}
3024

3125
func ExampleUnaryClientInterceptor() {
32-
tracer := global.Tracer("client-instrumentation")
33-
_, _ = grpc.Dial(
34-
"localhost",
35-
grpc.WithUnaryInterceptor(UnaryClientInterceptor(tracer)),
36-
)
26+
_, _ = grpc.Dial("localhost", grpc.WithUnaryInterceptor(UnaryClientInterceptor()))
3727
}
3828

3929
func ExampleStreamServerInterceptor() {
40-
tracer := global.Tracer("server-instrumentation")
41-
_ = grpc.NewServer(
42-
grpc.StreamInterceptor(StreamServerInterceptor(tracer)),
43-
)
30+
_ = grpc.NewServer(grpc.StreamInterceptor(StreamServerInterceptor()))
4431
}
4532

4633
func ExampleUnaryServerInterceptor() {
47-
tracer := global.Tracer("server-instrumentation")
48-
_ = grpc.NewServer(
49-
grpc.UnaryInterceptor(UnaryServerInterceptor(tracer)),
50-
)
34+
_ = grpc.NewServer(grpc.UnaryInterceptor(UnaryServerInterceptor()))
5135
}

instrumentation/google.golang.org/grpc/otelgrpc/go.mod

+3
Original file line numberDiff line numberDiff line change
@@ -2,9 +2,12 @@ module go.opentelemetry.io/contrib/instrumentation/google.golang.org/grpc/otelgr
22

33
go 1.14
44

5+
replace go.opentelemetry.io/contrib => ../../../../
6+
57
require (
68
github.com/golang/protobuf v1.4.2
79
github.com/stretchr/testify v1.6.1
10+
go.opentelemetry.io/contrib v0.12.0
811
go.opentelemetry.io/otel v0.12.0
912
google.golang.org/grpc v1.32.0
1013
)

instrumentation/google.golang.org/grpc/otelgrpc/go.sum

+9
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,8 @@ github.com/client9/misspell v0.3.4/go.mod h1:qj6jICC3Q7zFZvVWo7KLAzC3yx5G7kyvSDk
66
github.com/cncf/udpa/go v0.0.0-20191209042840-269d4d468f6f/go.mod h1:M8M6+tZqaGXZJjfX53e64911xZQV5JYwmTeXPW+k8Sc=
77
github.com/davecgh/go-spew v1.1.0 h1:ZDRjVQ15GmhC3fiQ8ni8+OwkZQO4DARzQgrnXU1Liz8=
88
github.com/davecgh/go-spew v1.1.0/go.mod h1:J7Y8YcW2NihsgmVo/mv3lAwl/skON4iLHjSsI+c5H38=
9+
github.com/davecgh/go-spew v1.1.1 h1:vj9j/u1bqnvCEfJOwUhtlOARqs3+rkHYY13jYWTU97c=
10+
github.com/davecgh/go-spew v1.1.1/go.mod h1:J7Y8YcW2NihsgmVo/mv3lAwl/skON4iLHjSsI+c5H38=
911
github.com/envoyproxy/go-control-plane v0.9.0/go.mod h1:YTl/9mNaCwkRvm6d1a2C3ymFceY/DCBVvsKhRF0iEA4=
1012
github.com/envoyproxy/go-control-plane v0.9.4/go.mod h1:6rpuAdCZL397s3pYoYcLgu1mIlRU8Am5FuJP05cCM98=
1113
github.com/envoyproxy/protoc-gen-validate v0.1.0/go.mod h1:iSmxcyjqTsJpI2R4NaDN7+kN2VEUnK/pcBlmesArF7c=
@@ -27,6 +29,11 @@ github.com/google/go-cmp v0.3.1/go.mod h1:8QqcDgzrUqlUb/G2PQTWiueGozuR1884gddMyw
2729
github.com/google/go-cmp v0.4.0/go.mod h1:v8dTdLbMG2kIc/vJvl+f65V22dbkXbowE6jgT/gNBxE=
2830
github.com/google/go-cmp v0.5.2 h1:X2ev0eStA3AbceY54o37/0PQ/UWqKEiiO2dKL5OPaFM=
2931
github.com/google/go-cmp v0.5.2/go.mod h1:v8dTdLbMG2kIc/vJvl+f65V22dbkXbowE6jgT/gNBxE=
32+
github.com/kr/pretty v0.1.0 h1:L/CwN0zerZDmRFUapSPitk6f+Q3+0za1rQkzVuMiMFI=
33+
github.com/kr/pretty v0.1.0/go.mod h1:dAy3ld7l9f0ibDNOQOHHMYYIIbhfbHSm3C4ZsoJORNo=
34+
github.com/kr/pty v1.1.1/go.mod h1:pFQYn66WHrOpPYNljwOMqo10TkYh1fy3cYio2l3bCsQ=
35+
github.com/kr/text v0.1.0 h1:45sCR5RtlFHMR4UwH9sdQ5TC8v0qDQCHnXt+kaKSTVE=
36+
github.com/kr/text v0.1.0/go.mod h1:4Jbv+DJW3UT/LiOwJeYQe1efqtUx/iVham/4vfdArNI=
3037
github.com/pmezard/go-difflib v1.0.0 h1:4DBwDE0NGyQoBHbLQYPwSUPoCMWR5BEzIk/f1lZbAQM=
3138
github.com/pmezard/go-difflib v1.0.0/go.mod h1:iKH77koFhYxTK1pcRnkKkqfTogsbg7gZNVY4sRDYZ/4=
3239
github.com/prometheus/client_model v0.0.0-20190812154241-14fe0d1b01d4/go.mod h1:xMI15A0UPsDsEKsMN9yxemIoYk6Tm2C1GtYGdfGttqA=
@@ -81,6 +88,8 @@ google.golang.org/protobuf v1.23.0 h1:4MY060fB1DLGMB/7MBTLnwQUY6+F09GEiz6SsrNqyz
8188
google.golang.org/protobuf v1.23.0/go.mod h1:EGpADcykh3NcUnDUJcl1+ZksZNG86OlYog2l/sGQquU=
8289
gopkg.in/check.v1 v0.0.0-20161208181325-20d25e280405 h1:yhCVgyC4o1eVCa2tZl7eS0r+SDo693bJlVdllGtEeKM=
8390
gopkg.in/check.v1 v0.0.0-20161208181325-20d25e280405/go.mod h1:Co6ibVJAznAaIkqp8huTwlJQCZ016jof/cbN4VW5Yz0=
91+
gopkg.in/check.v1 v1.0.0-20190902080502-41f04d3bba15 h1:YR8cESwS4TdDjEe65xsg0ogRM/Nc3DYOhEAlW+xobZo=
92+
gopkg.in/check.v1 v1.0.0-20190902080502-41f04d3bba15/go.mod h1:Co6ibVJAznAaIkqp8huTwlJQCZ016jof/cbN4VW5Yz0=
8493
gopkg.in/yaml.v3 v3.0.0-20200313102051-9f266ea9e77c h1:dUUwHk2QECo/6vqA44rthZ8ie2QXMNeKRTHCNY2nXvo=
8594
gopkg.in/yaml.v3 v3.0.0-20200313102051-9f266ea9e77c/go.mod h1:K4uyk7z7BCEPqu6E+C64Yfv1cQ7kz7rIZviUmN+EgEM=
8695
honnef.co/go/tools v0.0.0-20190102054323-c2f93a96b099/go.mod h1:rf3lG4BRIbNafJWhAfAdb/ePZxsR/4RtNHQocxwk9r4=

instrumentation/google.golang.org/grpc/otelgrpc/grpc_test.go

+16-27
Original file line numberDiff line numberDiff line change
@@ -27,7 +27,6 @@ import (
2727
"google.golang.org/grpc/test/bufconn"
2828

2929
"go.opentelemetry.io/contrib/instrumentation/google.golang.org/grpc/otelgrpc"
30-
"go.opentelemetry.io/otel/api/trace"
3130
"go.opentelemetry.io/otel/api/trace/tracetest"
3231
"go.opentelemetry.io/otel/label"
3332
"go.opentelemetry.io/otel/semconv"
@@ -73,51 +72,50 @@ func doCalls(cOpt []grpc.DialOption, sOpt []grpc.ServerOption) error {
7372

7473
func TestInterceptors(t *testing.T) {
7574
clientUnarySR := new(tracetest.StandardSpanRecorder)
76-
clientUnaryTracer := tracetest.NewTracerProvider(tracetest.WithSpanRecorder(clientUnarySR)).Tracer("TestUnaryClientInterceptor")
75+
clientUnaryTP := tracetest.NewTracerProvider(tracetest.WithSpanRecorder(clientUnarySR))
7776

7877
clientStreamSR := new(tracetest.StandardSpanRecorder)
79-
clientStreamTracer := tracetest.NewTracerProvider(tracetest.WithSpanRecorder(clientStreamSR)).Tracer("TestStreamClientInterceptor")
78+
clientStreamTP := tracetest.NewTracerProvider(tracetest.WithSpanRecorder(clientStreamSR))
8079

8180
serverUnarySR := new(tracetest.StandardSpanRecorder)
82-
serverUnaryTracer := tracetest.NewTracerProvider(tracetest.WithSpanRecorder(serverUnarySR)).Tracer("TestUnaryServerInterceptor")
81+
serverUnaryTP := tracetest.NewTracerProvider(tracetest.WithSpanRecorder(serverUnarySR))
8382

8483
serverStreamSR := new(tracetest.StandardSpanRecorder)
85-
serverStreamTracer := tracetest.NewTracerProvider(tracetest.WithSpanRecorder(serverStreamSR)).Tracer("TestStreamServerInterceptor")
84+
serverStreamTP := tracetest.NewTracerProvider(tracetest.WithSpanRecorder(serverStreamSR))
8685

8786
assert.NoError(t, doCalls(
8887
[]grpc.DialOption{
89-
grpc.WithUnaryInterceptor(otelgrpc.UnaryClientInterceptor(clientUnaryTracer)),
90-
grpc.WithStreamInterceptor(otelgrpc.StreamClientInterceptor(clientStreamTracer)),
88+
grpc.WithUnaryInterceptor(otelgrpc.UnaryClientInterceptor(otelgrpc.WithTracerProvider(clientUnaryTP))),
89+
grpc.WithStreamInterceptor(otelgrpc.StreamClientInterceptor(otelgrpc.WithTracerProvider(clientStreamTP))),
9190
},
9291
[]grpc.ServerOption{
93-
grpc.UnaryInterceptor(otelgrpc.UnaryServerInterceptor(serverUnaryTracer)),
94-
grpc.StreamInterceptor(otelgrpc.StreamServerInterceptor(serverStreamTracer)),
92+
grpc.UnaryInterceptor(otelgrpc.UnaryServerInterceptor(otelgrpc.WithTracerProvider(serverUnaryTP))),
93+
grpc.StreamInterceptor(otelgrpc.StreamServerInterceptor(otelgrpc.WithTracerProvider(serverStreamTP))),
9594
},
9695
))
9796

9897
t.Run("UnaryClientSpans", func(t *testing.T) {
99-
checkUnaryClientSpans(t, clientUnaryTracer, clientUnarySR.Completed())
98+
checkUnaryClientSpans(t, clientUnarySR.Completed())
10099
})
101100

102101
t.Run("StreamClientSpans", func(t *testing.T) {
103-
checkStreamClientSpans(t, clientStreamTracer, clientStreamSR.Completed())
102+
checkStreamClientSpans(t, clientStreamSR.Completed())
104103
})
105104

106105
t.Run("UnaryServerSpans", func(t *testing.T) {
107-
checkUnaryServerSpans(t, serverUnaryTracer, serverUnarySR.Completed())
106+
checkUnaryServerSpans(t, serverUnarySR.Completed())
108107
})
109108

110109
t.Run("StreamServerSpans", func(t *testing.T) {
111-
checkStreamServerSpans(t, serverStreamTracer, serverStreamSR.Completed())
110+
checkStreamServerSpans(t, serverStreamSR.Completed())
112111
})
113112
}
114113

115-
func checkUnaryClientSpans(t *testing.T, tracer trace.Tracer, spans []*tracetest.Span) {
114+
func checkUnaryClientSpans(t *testing.T, spans []*tracetest.Span) {
116115
require.Len(t, spans, 2)
117116

118117
emptySpan := spans[0]
119118
assert.True(t, emptySpan.Ended())
120-
assert.Equal(t, tracer, emptySpan.Tracer())
121119
assert.Equal(t, "grpc.testing.TestService/EmptyCall", emptySpan.Name())
122120
assert.Equal(t, []tracetest.Event{
123121
{
@@ -145,7 +143,6 @@ func checkUnaryClientSpans(t *testing.T, tracer trace.Tracer, spans []*tracetest
145143

146144
largeSpan := spans[1]
147145
assert.True(t, largeSpan.Ended())
148-
assert.Equal(t, tracer, largeSpan.Tracer())
149146
assert.Equal(t, "grpc.testing.TestService/UnaryCall", largeSpan.Name())
150147
assert.Equal(t, []tracetest.Event{
151148
{
@@ -174,12 +171,11 @@ func checkUnaryClientSpans(t *testing.T, tracer trace.Tracer, spans []*tracetest
174171
}, largeSpan.Attributes())
175172
}
176173

177-
func checkStreamClientSpans(t *testing.T, tracer trace.Tracer, spans []*tracetest.Span) {
174+
func checkStreamClientSpans(t *testing.T, spans []*tracetest.Span) {
178175
require.Len(t, spans, 3)
179176

180177
streamInput := spans[0]
181178
assert.True(t, streamInput.Ended())
182-
assert.Equal(t, tracer, streamInput.Tracer())
183179
assert.Equal(t, "grpc.testing.TestService/StreamingInputCall", streamInput.Name())
184180
// sizes from reqSizes in "google.golang.org/grpc/interop".
185181
assert.Equal(t, []tracetest.Event{
@@ -225,7 +221,6 @@ func checkStreamClientSpans(t *testing.T, tracer trace.Tracer, spans []*tracetes
225221

226222
streamOutput := spans[1]
227223
assert.True(t, streamOutput.Ended())
228-
assert.Equal(t, tracer, streamOutput.Tracer())
229224
assert.Equal(t, "grpc.testing.TestService/StreamingOutputCall", streamOutput.Name())
230225
// sizes from respSizes in "google.golang.org/grpc/interop".
231226
assert.Equal(t, []tracetest.Event{
@@ -278,7 +273,6 @@ func checkStreamClientSpans(t *testing.T, tracer trace.Tracer, spans []*tracetes
278273

279274
pingPong := spans[2]
280275
assert.True(t, pingPong.Ended())
281-
assert.Equal(t, tracer, pingPong.Tracer())
282276
assert.Equal(t, "grpc.testing.TestService/FullDuplexCall", pingPong.Name())
283277
assert.Equal(t, []tracetest.Event{
284278
{
@@ -353,12 +347,11 @@ func checkStreamClientSpans(t *testing.T, tracer trace.Tracer, spans []*tracetes
353347
}, pingPong.Attributes())
354348
}
355349

356-
func checkStreamServerSpans(t *testing.T, tracer trace.Tracer, spans []*tracetest.Span) {
350+
func checkStreamServerSpans(t *testing.T, spans []*tracetest.Span) {
357351
require.Len(t, spans, 3)
358352

359353
streamInput := spans[0]
360354
assert.True(t, streamInput.Ended())
361-
assert.Equal(t, tracer, streamInput.Tracer())
362355
assert.Equal(t, "grpc.testing.TestService/StreamingInputCall", streamInput.Name())
363356
// sizes from reqSizes in "google.golang.org/grpc/interop".
364357
assert.Equal(t, []tracetest.Event{
@@ -411,7 +404,6 @@ func checkStreamServerSpans(t *testing.T, tracer trace.Tracer, spans []*tracetes
411404

412405
streamOutput := spans[1]
413406
assert.True(t, streamOutput.Ended())
414-
assert.Equal(t, tracer, streamOutput.Tracer())
415407
assert.Equal(t, "grpc.testing.TestService/StreamingOutputCall", streamOutput.Name())
416408
// sizes from respSizes in "google.golang.org/grpc/interop".
417409
assert.Equal(t, []tracetest.Event{
@@ -464,7 +456,6 @@ func checkStreamServerSpans(t *testing.T, tracer trace.Tracer, spans []*tracetes
464456

465457
pingPong := spans[2]
466458
assert.True(t, pingPong.Ended())
467-
assert.Equal(t, tracer, pingPong.Tracer())
468459
assert.Equal(t, "grpc.testing.TestService/FullDuplexCall", pingPong.Name())
469460
assert.Equal(t, []tracetest.Event{
470461
{
@@ -539,12 +530,11 @@ func checkStreamServerSpans(t *testing.T, tracer trace.Tracer, spans []*tracetes
539530
}, pingPong.Attributes())
540531
}
541532

542-
func checkUnaryServerSpans(t *testing.T, tracer trace.Tracer, spans []*tracetest.Span) {
533+
func checkUnaryServerSpans(t *testing.T, spans []*tracetest.Span) {
543534
require.Len(t, spans, 2)
544535

545536
emptySpan := spans[0]
546537
assert.True(t, emptySpan.Ended())
547-
assert.Equal(t, tracer, emptySpan.Tracer())
548538
assert.Equal(t, "grpc.testing.TestService/EmptyCall", emptySpan.Name())
549539
assert.Equal(t, []tracetest.Event{
550540
{
@@ -572,7 +562,6 @@ func checkUnaryServerSpans(t *testing.T, tracer trace.Tracer, spans []*tracetest
572562

573563
largeSpan := spans[1]
574564
assert.True(t, largeSpan.Ended())
575-
assert.Equal(t, tracer, largeSpan.Tracer())
576565
assert.Equal(t, "grpc.testing.TestService/UnaryCall", largeSpan.Name())
577566
assert.Equal(t, []tracetest.Event{
578567
{

0 commit comments

Comments
 (0)