Skip to content

Commit

Permalink
add custom span options to tests
Browse files Browse the repository at this point in the history
  • Loading branch information
dubonzi committed May 2, 2023
1 parent 3a0a79f commit f26698c
Show file tree
Hide file tree
Showing 2 changed files with 12 additions and 3 deletions.
Expand Up @@ -8,6 +8,7 @@ require (
go.opentelemetry.io/otel v1.15.0
go.opentelemetry.io/otel/sdk v1.15.0
go.opentelemetry.io/otel/sdk/metric v0.38.0
go.opentelemetry.io/otel/trace v1.15.0
go.uber.org/goleak v1.2.1
google.golang.org/grpc v1.54.0
)
Expand All @@ -22,7 +23,6 @@ require (
github.com/kr/text v0.2.0 // indirect
github.com/pmezard/go-difflib v1.0.0 // indirect
go.opentelemetry.io/otel/metric v0.38.0 // indirect
go.opentelemetry.io/otel/trace v1.15.0 // indirect
golang.org/x/net v0.9.0 // indirect
golang.org/x/oauth2 v0.4.0 // indirect
golang.org/x/sys v0.7.0 // indirect
Expand Down
Expand Up @@ -30,6 +30,7 @@ import (
"go.opentelemetry.io/otel/sdk/trace"
"go.opentelemetry.io/otel/sdk/trace/tracetest"
semconv "go.opentelemetry.io/otel/semconv/v1.17.0"
oteltrace "go.opentelemetry.io/otel/trace"

"github.com/stretchr/testify/assert"
"github.com/stretchr/testify/require"
Expand Down Expand Up @@ -89,7 +90,7 @@ func TestUnaryClientInterceptor(t *testing.T) {

sr := tracetest.NewSpanRecorder()
tp := trace.NewTracerProvider(trace.WithSpanProcessor(sr))
unaryInterceptor := otelgrpc.UnaryClientInterceptor(otelgrpc.WithTracerProvider(tp))
unaryInterceptor := otelgrpc.UnaryClientInterceptor(otelgrpc.WithTracerProvider(tp), otelgrpc.WithSpanOptions(oteltrace.WithAttributes(attribute.Bool("custom", true))))

req := &grpc_testing.SimpleRequest{}
reply := &grpc_testing.SimpleResponse{}
Expand All @@ -113,6 +114,7 @@ func TestUnaryClientInterceptor(t *testing.T) {
otelgrpc.GRPCStatusCodeKey.Int64(0),
semconv.NetPeerName("fake"),
semconv.NetPeerPort(8906),
attribute.Bool("custom", true),
},
eventsAttr: []map[attribute.Key]attribute.Value{
{
Expand All @@ -135,6 +137,7 @@ func TestUnaryClientInterceptor(t *testing.T) {
otelgrpc.GRPCStatusCodeKey.Int64(0),
semconv.NetPeerName("fake"),
semconv.NetPeerPort(8906),
attribute.Bool("custom", true),
},
eventsAttr: []map[attribute.Key]attribute.Value{
{
Expand All @@ -157,6 +160,7 @@ func TestUnaryClientInterceptor(t *testing.T) {
otelgrpc.GRPCStatusCodeKey.Int64(int64(grpc_codes.OK)),
semconv.NetPeerName("fake"),
semconv.NetPeerPort(8906),
attribute.Bool("custom", true),
},
eventsAttr: []map[attribute.Key]attribute.Value{
{
Expand All @@ -180,6 +184,7 @@ func TestUnaryClientInterceptor(t *testing.T) {
otelgrpc.GRPCStatusCodeKey.Int64(int64(grpc_codes.Internal)),
semconv.NetPeerName("fake"),
semconv.NetPeerPort(8906),
attribute.Bool("custom", true),
},
eventsAttr: []map[attribute.Key]attribute.Value{
{
Expand All @@ -201,6 +206,7 @@ func TestUnaryClientInterceptor(t *testing.T) {
otelgrpc.GRPCStatusCodeKey.Int64(0),
semconv.NetPeerName("fake"),
semconv.NetPeerPort(8906),
attribute.Bool("custom", true),
},
eventsAttr: []map[attribute.Key]attribute.Value{
{
Expand All @@ -223,6 +229,7 @@ func TestUnaryClientInterceptor(t *testing.T) {
semconv.RPCMethod("method"),
semconv.NetPeerName("fake"),
semconv.NetPeerPort(8906),
attribute.Bool("custom", true),
},
eventsAttr: []map[attribute.Key]attribute.Value{
{
Expand Down Expand Up @@ -314,7 +321,7 @@ func createInterceptedStreamClient(t *testing.T, method string, opts clientStrea
// tracer
sr := tracetest.NewSpanRecorder()
tp := trace.NewTracerProvider(trace.WithSpanProcessor(sr))
streamCI := otelgrpc.StreamClientInterceptor(otelgrpc.WithTracerProvider(tp))
streamCI := otelgrpc.StreamClientInterceptor(otelgrpc.WithTracerProvider(tp), otelgrpc.WithSpanOptions(oteltrace.WithAttributes(attribute.Bool("custom", true))))

streamClient, err := streamCI(
context.Background(),
Expand Down Expand Up @@ -375,6 +382,7 @@ func TestStreamClientInterceptorOnBIDIStream(t *testing.T) {
semconv.RPCMethod("bar"),
semconv.NetPeerName("fake"),
semconv.NetPeerPort(8906),
attribute.Bool("custom", true),
}
assert.ElementsMatch(t, expectedAttr, span.Attributes())

Expand Down Expand Up @@ -443,6 +451,7 @@ func TestStreamClientInterceptorOnUnidirectionalClientServerStream(t *testing.T)
semconv.RPCMethod("bar"),
semconv.NetPeerName("fake"),
semconv.NetPeerPort(8906),
attribute.Bool("custom", true),
}
assert.ElementsMatch(t, expectedAttr, span.Attributes())

Expand Down

0 comments on commit f26698c

Please sign in to comment.