diff --git a/instrumentation/google.golang.org/grpc/otelgrpc/benchmark_test.go b/instrumentation/google.golang.org/grpc/otelgrpc/benchmark_test.go index 87d3fae5ddd..4d9282397cb 100644 --- a/instrumentation/google.golang.org/grpc/otelgrpc/benchmark_test.go +++ b/instrumentation/google.golang.org/grpc/otelgrpc/benchmark_test.go @@ -38,8 +38,7 @@ func benchmark(b *testing.B, cOpt []grpc.DialOption, sOpt []grpc.ServerOption) { ctx := context.Background() dial := func(context.Context, string) (net.Conn, error) { return l.Dial() } - conn, err := grpc.DialContext( - ctx, + conn, err := grpc.NewClient( "bufnet", append([]grpc.DialOption{ grpc.WithContextDialer(dial), diff --git a/instrumentation/google.golang.org/grpc/otelgrpc/example/client/main.go b/instrumentation/google.golang.org/grpc/otelgrpc/example/client/main.go index c0433b875b8..2f681b1d270 100644 --- a/instrumentation/google.golang.org/grpc/otelgrpc/example/client/main.go +++ b/instrumentation/google.golang.org/grpc/otelgrpc/example/client/main.go @@ -32,7 +32,7 @@ func main() { }() var conn *grpc.ClientConn - conn, err = grpc.Dial("127.0.0.1:7777", grpc.WithTransportCredentials(insecure.NewCredentials()), + conn, err = grpc.NewClient("127.0.0.1:7777", grpc.WithTransportCredentials(insecure.NewCredentials()), grpc.WithStatsHandler(otelgrpc.NewClientHandler()), ) if err != nil { diff --git a/instrumentation/google.golang.org/grpc/otelgrpc/example_test.go b/instrumentation/google.golang.org/grpc/otelgrpc/example_test.go index 48a887b306f..c9a28b8b734 100644 --- a/instrumentation/google.golang.org/grpc/otelgrpc/example_test.go +++ b/instrumentation/google.golang.org/grpc/otelgrpc/example_test.go @@ -10,7 +10,7 @@ import ( ) func ExampleNewClientHandler() { - _, _ = grpc.Dial("localhost", grpc.WithStatsHandler(otelgrpc.NewClientHandler())) + _, _ = grpc.NewClient("localhost", grpc.WithStatsHandler(otelgrpc.NewClientHandler())) } func ExampleNewServerHandler() { diff --git a/instrumentation/google.golang.org/grpc/otelgrpc/interceptor.go b/instrumentation/google.golang.org/grpc/otelgrpc/interceptor.go index a4fa5357a56..b129e377938 100644 --- a/instrumentation/google.golang.org/grpc/otelgrpc/interceptor.go +++ b/instrumentation/google.golang.org/grpc/otelgrpc/interceptor.go @@ -48,7 +48,7 @@ var ( ) // UnaryClientInterceptor returns a grpc.UnaryClientInterceptor suitable -// for use in a grpc.Dial call. +// for use in a grpc.NewClient call. // // Deprecated: Use [NewClientHandler] instead. func UnaryClientInterceptor(opts ...Option) grpc.UnaryClientInterceptor { @@ -185,7 +185,7 @@ func (w *clientStream) CloseSend() error { return err } -func wrapClientStream(ctx context.Context, s grpc.ClientStream, desc *grpc.StreamDesc, span trace.Span, cfg *config) *clientStream { +func wrapClientStream(s grpc.ClientStream, desc *grpc.StreamDesc, span trace.Span, cfg *config) *clientStream { return &clientStream{ ClientStream: s, span: span, @@ -208,7 +208,7 @@ func (w *clientStream) endSpan(err error) { } // StreamClientInterceptor returns a grpc.StreamClientInterceptor suitable -// for use in a grpc.Dial call. +// for use in a grpc.NewClient call. // // Deprecated: Use [NewClientHandler] instead. func StreamClientInterceptor(opts ...Option) grpc.StreamClientInterceptor { @@ -259,7 +259,7 @@ func StreamClientInterceptor(opts ...Option) grpc.StreamClientInterceptor { span.End() return s, err } - stream := wrapClientStream(ctx, s, desc, span, cfg) + stream := wrapClientStream(s, desc, span, cfg) return stream, nil } } diff --git a/instrumentation/google.golang.org/grpc/otelgrpc/test/grpc_test.go b/instrumentation/google.golang.org/grpc/otelgrpc/test/grpc_test.go index a82cdbc2041..004b07085cf 100644 --- a/instrumentation/google.golang.org/grpc/otelgrpc/test/grpc_test.go +++ b/instrumentation/google.golang.org/grpc/otelgrpc/test/grpc_test.go @@ -35,7 +35,7 @@ var wantInstrumentationScope = instrumentation.Scope{ Version: otelgrpc.Version(), } -// newGrpcTest creats a grpc server, starts it, and returns the client, closes everything down during test cleanup. +// newGrpcTest creates a grpc server, starts it, and returns the client, closes everything down during test cleanup. func newGrpcTest(t testing.TB, listener net.Listener, cOpt []grpc.DialOption, sOpt []grpc.ServerOption) pb.TestServiceClient { grpcServer := grpc.NewServer(sOpt...) pb.RegisterTestServiceServer(grpcServer, test.NewTestServer()) @@ -47,17 +47,15 @@ func newGrpcTest(t testing.TB, listener net.Listener, cOpt []grpc.DialOption, sO grpcServer.Stop() assert.NoError(t, <-errCh) }) - ctx := context.Background() - cOpt = append(cOpt, grpc.WithBlock(), grpc.WithTransportCredentials(insecure.NewCredentials())) + cOpt = append(cOpt, grpc.WithTransportCredentials(insecure.NewCredentials())) if l, ok := listener.(interface{ Dial() (net.Conn, error) }); ok { dial := func(context.Context, string) (net.Conn, error) { return l.Dial() } cOpt = append(cOpt, grpc.WithContextDialer(dial)) } - conn, err := grpc.DialContext( - ctx, + conn, err := grpc.NewClient( listener.Addr().String(), cOpt..., ) diff --git a/instrumentation/google.golang.org/grpc/otelgrpc/test/interceptor_test.go b/instrumentation/google.golang.org/grpc/otelgrpc/test/interceptor_test.go index 0e7e4018319..f264e470f28 100644 --- a/instrumentation/google.golang.org/grpc/otelgrpc/test/interceptor_test.go +++ b/instrumentation/google.golang.org/grpc/otelgrpc/test/interceptor_test.go @@ -69,10 +69,7 @@ func ctxDialer() func(context.Context, string) (net.Conn, error) { } func TestUnaryClientInterceptor(t *testing.T) { - ctx, cancel := context.WithCancel(context.Background()) - t.Cleanup(cancel) - - clientConn, err := grpc.DialContext(ctx, "fake:8906", + clientConn, err := grpc.NewClient("fake:8906", grpc.WithContextDialer(ctxDialer()), grpc.WithTransportCredentials(insecure.NewCredentials()), ) @@ -377,11 +374,8 @@ func newMockClientStream(opts clientStreamOpts) *mockClientStream { } func createInterceptedStreamClient(t *testing.T, method string, opts clientStreamOpts) (grpc.ClientStream, *tracetest.SpanRecorder) { - ctx, cancel := context.WithCancel(context.Background()) - t.Cleanup(cancel) - mockStream := newMockClientStream(opts) - clientConn, err := grpc.DialContext(ctx, "fake:8906", + clientConn, err := grpc.NewClient("fake:8906", grpc.WithContextDialer(ctxDialer()), grpc.WithTransportCredentials(insecure.NewCredentials()), ) @@ -632,10 +626,7 @@ func TestStreamClientInterceptorOnUnidirectionalClientServerStream(t *testing.T) func TestStreamClientInterceptorCancelContext(t *testing.T) { defer goleak.VerifyNone(t) - ctx, cancel := context.WithCancel(context.Background()) - t.Cleanup(cancel) - - clientConn, err := grpc.DialContext(ctx, "fake:8906", + clientConn, err := grpc.NewClient("fake:8906", grpc.WithContextDialer(ctxDialer()), grpc.WithTransportCredentials(insecure.NewCredentials()), ) @@ -696,10 +687,7 @@ func TestStreamClientInterceptorCancelContext(t *testing.T) { func TestStreamClientInterceptorWithError(t *testing.T) { defer goleak.VerifyNone(t) - ctx, cancel := context.WithCancel(context.Background()) - t.Cleanup(cancel) - - clientConn, err := grpc.DialContext(ctx, "fake:8906", + clientConn, err := grpc.NewClient("fake:8906", grpc.WithContextDialer(ctxDialer()), grpc.WithTransportCredentials(insecure.NewCredentials()), ) diff --git a/propagators/opencensus/examples/opencensus_client/client.go b/propagators/opencensus/examples/opencensus_client/client.go index 9544045c2ae..dddd876a764 100644 --- a/propagators/opencensus/examples/opencensus_client/client.go +++ b/propagators/opencensus/examples/opencensus_client/client.go @@ -29,7 +29,7 @@ func main() { // Set up a connection to the server with the OpenCensus // stats handler to enable tracing. - conn, err := grpc.Dial(address, grpc.WithStatsHandler(&ocgrpc.ClientHandler{}), grpc.WithTransportCredentials(insecure.NewCredentials())) + conn, err := grpc.NewClient(address, grpc.WithStatsHandler(&ocgrpc.ClientHandler{}), grpc.WithTransportCredentials(insecure.NewCredentials())) if err != nil { log.Fatalf("Cannot connect: %v", err) }