-
Notifications
You must be signed in to change notification settings - Fork 651
Description
This function was deprecated in the last year and should be removed.
- Remove the deprecated
StreamClientInterceptor
function:
opentelemetry-go-contrib/instrumentation/google.golang.org/grpc/otelgrpc/interceptor.go
Lines 211 to 266 in 2a6af7d
// StreamClientInterceptor returns a grpc.StreamClientInterceptor suitable // for use in a grpc.NewClient call. // // Deprecated: Use [NewClientHandler] instead. func StreamClientInterceptor(opts ...Option) grpc.StreamClientInterceptor { cfg := newConfig(opts, "client") tracer := cfg.TracerProvider.Tracer( ScopeName, trace.WithInstrumentationVersion(Version()), ) return func( ctx context.Context, desc *grpc.StreamDesc, cc *grpc.ClientConn, method string, streamer grpc.Streamer, callOpts ...grpc.CallOption, ) (grpc.ClientStream, error) { i := &InterceptorInfo{ Method: method, Type: StreamClient, } if cfg.InterceptorFilter != nil && !cfg.InterceptorFilter(i) { return streamer(ctx, desc, cc, method, callOpts...) } name, attr, _ := telemetryAttributes(method, cc.Target()) startOpts := append([]trace.SpanStartOption{ trace.WithSpanKind(trace.SpanKindClient), trace.WithAttributes(attr...), }, cfg.SpanStartOptions..., ) ctx, span := tracer.Start( ctx, name, startOpts..., ) ctx = inject(ctx, cfg.Propagators) s, err := streamer(ctx, desc, cc, method, callOpts...) if err != nil { grpcStatus, _ := status.FromError(err) span.SetStatus(codes.Error, grpcStatus.Message()) span.SetAttributes(statusCodeAttr(grpcStatus.Code())) span.End() return s, err } stream := wrapClientStream(s, desc, span, cfg) return stream, nil } } - Remove the benchmark test:
opentelemetry-go-contrib/instrumentation/google.golang.org/grpc/otelgrpc/benchmark_test.go
Lines 97 to 103 in 2a6af7d
func BenchmarkStreamClientInterceptor(b *testing.B) { benchmark(b, []grpc.DialOption{ grpc.WithStreamInterceptor(otelgrpc.StreamClientInterceptor( otelgrpc.WithTracerProvider(tracerProvider), )), }, nil) } - Remove the tests
- https://github.com/open-telemetry/opentelemetry-go-contrib/blob/2a6af7def1f050f24f6739c8d45745eb3f3f2d95/instrumentation/google.golang.org/grpc/otelgrpc/test/interceptor_test.go#L376C6-L835
opentelemetry-go-contrib/instrumentation/google.golang.org/grpc/otelgrpc/test/interceptor_test.go
Lines 1112 to 1129 in 2a6af7d
func BenchmarkStreamClientInterceptor(b *testing.B) { listener, err := net.Listen("tcp", "127.0.0.1:0") require.NoError(b, err, "failed to open port") client := newGrpcTest(b, listener, []grpc.DialOption{ //nolint:staticcheck // Interceptors are deprecated and will be removed in the next release. grpc.WithStreamInterceptor(otelgrpc.StreamClientInterceptor()), }, []grpc.ServerOption{}, ) b.ResetTimer() ctx, cancel := context.WithCancel(context.Background()) defer cancel() for i := 0; i < b.N; i++ { test.DoClientStreaming(ctx, client) } } opentelemetry-go-contrib/instrumentation/google.golang.org/grpc/otelgrpc/test/grpc_test.go
Lines 106 to 110 in 2a6af7d
//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), )), opentelemetry-go-contrib/instrumentation/google.golang.org/grpc/otelgrpc/test/grpc_test.go
Lines 134 to 136 in 2a6af7d
t.Run("StreamClientSpans", func(t *testing.T) { checkStreamClientSpans(t, clientStreamSR.Ended(), listener.Addr().String()) }) opentelemetry-go-contrib/instrumentation/google.golang.org/grpc/otelgrpc/test/grpc_test.go
Lines 215 to 386 in 2a6af7d
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{ otelgrpc.RPCMessageIDKey.Int(1), otelgrpc.RPCMessageTypeKey.String("SENT"), }, }, { Name: "message", Attributes: []attribute.KeyValue{ otelgrpc.RPCMessageIDKey.Int(2), otelgrpc.RPCMessageTypeKey.String("SENT"), }, }, { Name: "message", Attributes: []attribute.KeyValue{ otelgrpc.RPCMessageIDKey.Int(3), otelgrpc.RPCMessageTypeKey.String("SENT"), }, }, { Name: "message", Attributes: []attribute.KeyValue{ otelgrpc.RPCMessageIDKey.Int(4), otelgrpc.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"), otelgrpc.RPCSystemGRPC, otelgrpc.GRPCStatusCodeKey.Int64(int64(codes.OK)), semconv.NetSockPeerAddr(host), semconv.NetSockPeerPort(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{ otelgrpc.RPCMessageIDKey.Int(1), otelgrpc.RPCMessageTypeKey.String("SENT"), }, }, { Name: "message", Attributes: []attribute.KeyValue{ otelgrpc.RPCMessageIDKey.Int(1), otelgrpc.RPCMessageTypeKey.String("RECEIVED"), }, }, { Name: "message", Attributes: []attribute.KeyValue{ otelgrpc.RPCMessageIDKey.Int(2), otelgrpc.RPCMessageTypeKey.String("RECEIVED"), }, }, { Name: "message", Attributes: []attribute.KeyValue{ otelgrpc.RPCMessageIDKey.Int(3), otelgrpc.RPCMessageTypeKey.String("RECEIVED"), }, }, { Name: "message", Attributes: []attribute.KeyValue{ otelgrpc.RPCMessageIDKey.Int(4), otelgrpc.RPCMessageTypeKey.String("RECEIVED"), }, }, }, streamOutput.Events()) assert.ElementsMatch(t, []attribute.KeyValue{ semconv.RPCMethod("StreamingOutputCall"), semconv.RPCService("grpc.testing.TestService"), otelgrpc.RPCSystemGRPC, otelgrpc.GRPCStatusCodeKey.Int64(int64(codes.OK)), semconv.NetSockPeerAddr(host), semconv.NetSockPeerPort(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{ otelgrpc.RPCMessageIDKey.Int(1), otelgrpc.RPCMessageTypeKey.String("SENT"), }, }, { Name: "message", Attributes: []attribute.KeyValue{ otelgrpc.RPCMessageIDKey.Int(1), otelgrpc.RPCMessageTypeKey.String("RECEIVED"), }, }, { Name: "message", Attributes: []attribute.KeyValue{ otelgrpc.RPCMessageIDKey.Int(2), otelgrpc.RPCMessageTypeKey.String("SENT"), }, }, { Name: "message", Attributes: []attribute.KeyValue{ otelgrpc.RPCMessageIDKey.Int(2), otelgrpc.RPCMessageTypeKey.String("RECEIVED"), }, }, { Name: "message", Attributes: []attribute.KeyValue{ otelgrpc.RPCMessageIDKey.Int(3), otelgrpc.RPCMessageTypeKey.String("SENT"), }, }, { Name: "message", Attributes: []attribute.KeyValue{ otelgrpc.RPCMessageIDKey.Int(3), otelgrpc.RPCMessageTypeKey.String("RECEIVED"), }, }, { Name: "message", Attributes: []attribute.KeyValue{ otelgrpc.RPCMessageIDKey.Int(4), otelgrpc.RPCMessageTypeKey.String("SENT"), }, }, { Name: "message", Attributes: []attribute.KeyValue{ otelgrpc.RPCMessageIDKey.Int(4), otelgrpc.RPCMessageTypeKey.String("RECEIVED"), }, }, }, pingPong.Events()) assert.ElementsMatch(t, []attribute.KeyValue{ semconv.RPCMethod("FullDuplexCall"), semconv.RPCService("grpc.testing.TestService"), otelgrpc.RPCSystemGRPC, otelgrpc.GRPCStatusCodeKey.Int64(int64(codes.OK)), semconv.NetSockPeerAddr(host), semconv.NetSockPeerPort(port), }, pingPong.Attributes()) }
- Add a changelog entry in the
### Removed
section of the unreleased changelog for the removal.