Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -31,6 +31,7 @@ This project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0.htm
- `go.opentelemetry.io/contrib/instrumentation/github.com/labstack/echo/otelecho`
- `go.opentelemetry.io/contrib/instrumentation/net/http/httptrace/otelhttptrace`
- `go.opentelemetry.io/contrib/instrumentation/net/http/otelhttp`
- The deprecated `StreamClientInterceptor` function from `go.opentelemetry.io/contrib/instrumentation/google.golang.org/grpc/otelgrpc` is removed. (#7646)

### Fixed

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -8,20 +8,16 @@ import (
"net"
"testing"

"go.opentelemetry.io/otel/trace/noop"
"google.golang.org/grpc"
"google.golang.org/grpc/credentials/insecure"
pb "google.golang.org/grpc/interop/grpc_testing"
"google.golang.org/grpc/test/bufconn"

"go.opentelemetry.io/contrib/instrumentation/google.golang.org/grpc/otelgrpc"
"go.opentelemetry.io/contrib/instrumentation/google.golang.org/grpc/otelgrpc/internal/test"
)

const bufSize = 2048

var tracerProvider = noop.NewTracerProvider()

func benchmark(b *testing.B, cOpt []grpc.DialOption, sOpt []grpc.ServerOption) {
l := bufconn.Listen(bufSize)
defer l.Close()
Expand Down Expand Up @@ -68,11 +64,3 @@ func benchmark(b *testing.B, cOpt []grpc.DialOption, sOpt []grpc.ServerOption) {
func BenchmarkNoInstrumentation(b *testing.B) {
benchmark(b, nil, nil)
}

func BenchmarkStreamClientInterceptor(b *testing.B) {
benchmark(b, []grpc.DialOption{
grpc.WithStreamInterceptor(otelgrpc.StreamClientInterceptor(
otelgrpc.WithTracerProvider(tracerProvider),
)),
}, nil)
}
1 change: 0 additions & 1 deletion instrumentation/google.golang.org/grpc/otelgrpc/go.mod
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,6 @@ require (
go.opentelemetry.io/otel/sdk v1.37.0
go.opentelemetry.io/otel/sdk/metric v1.37.0
go.opentelemetry.io/otel/trace v1.37.0
go.uber.org/goleak v1.3.0
google.golang.org/grpc v1.74.2
google.golang.org/protobuf v1.36.6
)
Expand Down
202 changes: 0 additions & 202 deletions instrumentation/google.golang.org/grpc/otelgrpc/grpc_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -6,15 +6,13 @@ package otelgrpc_test
import (
"context"
"net"
"strconv"
"testing"

"github.com/stretchr/testify/assert"
"github.com/stretchr/testify/require"
"go.opentelemetry.io/otel/attribute"
"go.opentelemetry.io/otel/sdk/instrumentation"
"go.opentelemetry.io/otel/sdk/trace"
"go.opentelemetry.io/otel/sdk/trace/tracetest"
semconv "go.opentelemetry.io/otel/semconv/v1.34.0"
"google.golang.org/grpc"
"google.golang.org/grpc/credentials/insecure"
Expand Down Expand Up @@ -73,206 +71,6 @@ func doCalls(ctx context.Context, client pb.TestServiceClient) {
test.DoPingPong(ctx, client)
}

func TestInterceptors(t *testing.T) {
t.Setenv("OTEL_METRICS_EXEMPLAR_FILTER", "always_off")

clientStreamSR := tracetest.NewSpanRecorder()
clientStreamTP := trace.NewTracerProvider(trace.WithSpanProcessor(clientStreamSR))

listener, err := net.Listen("tcp", "127.0.0.1:0")
require.NoError(t, err, "failed to open port")
client := newGrpcTest(t, listener,
[]grpc.DialOption{
//nolint:staticcheck // Interceptors are deprecated and will be removed in the next release.
grpc.WithStreamInterceptor(otelgrpc.StreamClientInterceptor(
otelgrpc.WithTracerProvider(clientStreamTP),
otelgrpc.WithMessageEvents(otelgrpc.ReceivedEvents, otelgrpc.SentEvents),
)),
},
[]grpc.ServerOption{},
)
ctx, cancel := context.WithCancel(context.Background())
defer cancel()
doCalls(ctx, client)

t.Run("StreamClientSpans", func(t *testing.T) {
checkStreamClientSpans(t, clientStreamSR.Ended(), listener.Addr().String())
})
}

func checkStreamClientSpans(t *testing.T, spans []trace.ReadOnlySpan, addr string) {
require.Len(t, spans, 3)

host, p, err := net.SplitHostPort(addr)
require.NoError(t, err)
port, err := strconv.Atoi(p)
require.NoError(t, err)

streamInput := spans[0]
assert.False(t, streamInput.EndTime().IsZero())
assert.Equal(t, "grpc.testing.TestService/StreamingInputCall", streamInput.Name())
// sizes from reqSizes in "go.opentelemetry.io/contrib/instrumentation/google.golang.org/grpc/otelgrpc/test".
assertEvents(t, []trace.Event{
{
Name: "message",
Attributes: []attribute.KeyValue{
semconv.RPCMessageIDKey.Int(1),
semconv.RPCMessageTypeKey.String("SENT"),
},
},
{
Name: "message",
Attributes: []attribute.KeyValue{
semconv.RPCMessageIDKey.Int(2),
semconv.RPCMessageTypeKey.String("SENT"),
},
},
{
Name: "message",
Attributes: []attribute.KeyValue{
semconv.RPCMessageIDKey.Int(3),
semconv.RPCMessageTypeKey.String("SENT"),
},
},
{
Name: "message",
Attributes: []attribute.KeyValue{
semconv.RPCMessageIDKey.Int(4),
semconv.RPCMessageTypeKey.String("SENT"),
},
},
// client does not record an event for the server response.
}, streamInput.Events())
assert.ElementsMatch(t, []attribute.KeyValue{
semconv.RPCMethod("StreamingInputCall"),
semconv.RPCService("grpc.testing.TestService"),
semconv.RPCSystemGRPC,
semconv.RPCGRPCStatusCodeOk,
semconv.ServerAddress(host),
semconv.ServerPort(port),
}, streamInput.Attributes())

streamOutput := spans[1]
assert.False(t, streamOutput.EndTime().IsZero())
assert.Equal(t, "grpc.testing.TestService/StreamingOutputCall", streamOutput.Name())
// sizes from respSizes in "go.opentelemetry.io/contrib/instrumentation/google.golang.org/grpc/otelgrpc/test".
assertEvents(t, []trace.Event{
{
Name: "message",
Attributes: []attribute.KeyValue{
semconv.RPCMessageIDKey.Int(1),
semconv.RPCMessageTypeKey.String("SENT"),
},
},
{
Name: "message",
Attributes: []attribute.KeyValue{
semconv.RPCMessageIDKey.Int(1),
semconv.RPCMessageTypeKey.String("RECEIVED"),
},
},
{
Name: "message",
Attributes: []attribute.KeyValue{
semconv.RPCMessageIDKey.Int(2),
semconv.RPCMessageTypeKey.String("RECEIVED"),
},
},
{
Name: "message",
Attributes: []attribute.KeyValue{
semconv.RPCMessageIDKey.Int(3),
semconv.RPCMessageTypeKey.String("RECEIVED"),
},
},
{
Name: "message",
Attributes: []attribute.KeyValue{
semconv.RPCMessageIDKey.Int(4),
semconv.RPCMessageTypeKey.String("RECEIVED"),
},
},
}, streamOutput.Events())
assert.ElementsMatch(t, []attribute.KeyValue{
semconv.RPCMethod("StreamingOutputCall"),
semconv.RPCService("grpc.testing.TestService"),
semconv.RPCSystemGRPC,
semconv.RPCGRPCStatusCodeOk,
semconv.ServerAddress(host),
semconv.ServerPort(port),
}, streamOutput.Attributes())

pingPong := spans[2]
assert.False(t, pingPong.EndTime().IsZero())
assert.Equal(t, "grpc.testing.TestService/FullDuplexCall", pingPong.Name())
assertEvents(t, []trace.Event{
{
Name: "message",
Attributes: []attribute.KeyValue{
semconv.RPCMessageIDKey.Int(1),
semconv.RPCMessageTypeKey.String("SENT"),
},
},
{
Name: "message",
Attributes: []attribute.KeyValue{
semconv.RPCMessageIDKey.Int(1),
semconv.RPCMessageTypeKey.String("RECEIVED"),
},
},
{
Name: "message",
Attributes: []attribute.KeyValue{
semconv.RPCMessageIDKey.Int(2),
semconv.RPCMessageTypeKey.String("SENT"),
},
},
{
Name: "message",
Attributes: []attribute.KeyValue{
semconv.RPCMessageIDKey.Int(2),
semconv.RPCMessageTypeKey.String("RECEIVED"),
},
},
{
Name: "message",
Attributes: []attribute.KeyValue{
semconv.RPCMessageIDKey.Int(3),
semconv.RPCMessageTypeKey.String("SENT"),
},
},
{
Name: "message",
Attributes: []attribute.KeyValue{
semconv.RPCMessageIDKey.Int(3),
semconv.RPCMessageTypeKey.String("RECEIVED"),
},
},
{
Name: "message",
Attributes: []attribute.KeyValue{
semconv.RPCMessageIDKey.Int(4),
semconv.RPCMessageTypeKey.String("SENT"),
},
},
{
Name: "message",
Attributes: []attribute.KeyValue{
semconv.RPCMessageIDKey.Int(4),
semconv.RPCMessageTypeKey.String("RECEIVED"),
},
},
}, pingPong.Events())
assert.ElementsMatch(t, []attribute.KeyValue{
semconv.RPCMethod("FullDuplexCall"),
semconv.RPCService("grpc.testing.TestService"),
semconv.RPCSystemGRPC,
semconv.RPCGRPCStatusCodeOk,
semconv.ServerAddress(host),
semconv.ServerPort(port),
}, pingPong.Attributes())
}

func assertEvents(t *testing.T, expected, actual []trace.Event) bool { //nolint:unparam
if !assert.Len(t, actual, len(expected)) {
return false
Expand Down
Loading
Loading