diff --git a/spanner/client_test.go b/spanner/client_test.go index 82b2a9a2d493..29b3323fbb32 100644 --- a/spanner/client_test.go +++ b/spanner/client_test.go @@ -76,7 +76,7 @@ func setupMockedTestServerWithConfigAndGCPMultiendpointPool(t *testing.T, config if len(token) != 1 { return status.Errorf(codes.Internal, "unexpected number of api client token headers: %v", len(token)) } - if !strings.HasPrefix(token[0], "gl-go/") { + if !strings.Contains(token[0], "gl-go/") { return status.Errorf(codes.Internal, "unexpected api client token: %v", token[0]) } if !strings.Contains(token[0], "gccl/") { diff --git a/spanner/metrics.go b/spanner/metrics.go index ad9005afeadf..ffa57aa39d3e 100644 --- a/spanner/metrics.go +++ b/spanner/metrics.go @@ -167,7 +167,7 @@ var ( return "global" } - // GCM exporter should use the same options as Bigtable client + // GCM exporter should use the same options as Spanner client // createExporterOptions takes Spanner client options and returns exporter options // Overwritten in tests createExporterOptions = func(spannerOpts ...option.ClientOption) []option.ClientOption { diff --git a/spanner/metrics_monitoring_exporter.go b/spanner/metrics_monitoring_exporter.go index bbf5d62d37ce..d70365935f6e 100644 --- a/spanner/metrics_monitoring_exporter.go +++ b/spanner/metrics_monitoring_exporter.go @@ -30,6 +30,7 @@ import ( monitoring "cloud.google.com/go/monitoring/apiv3/v2" "cloud.google.com/go/monitoring/apiv3/v2/monitoringpb" "cloud.google.com/go/spanner/internal" + "github.com/googleapis/gax-go/v2/callctx" "go.opentelemetry.io/otel/attribute" otelmetric "go.opentelemetry.io/otel/sdk/metric" otelmetricdata "go.opentelemetry.io/otel/sdk/metric/metricdata" @@ -38,7 +39,6 @@ import ( googlemetricpb "google.golang.org/genproto/googleapis/api/metric" monitoredrespb "google.golang.org/genproto/googleapis/api/monitoredres" "google.golang.org/grpc/codes" - "google.golang.org/grpc/metadata" "google.golang.org/grpc/status" "google.golang.org/protobuf/types/known/timestamppb" ) @@ -149,7 +149,7 @@ func (me *monitoringExporter) exportTimeSeries(ctx context.Context, rm *otelmetr Name: name, TimeSeries: tss[i:j], } - err = me.client.CreateServiceTimeSeries(metadata.NewOutgoingContext(ctx, metadata.Pairs("x-goog-api-client", "gccl/"+internal.Version)), req) + err = me.client.CreateServiceTimeSeries(callctx.SetHeaders(ctx, "x-goog-api-client", "gccl/"+internal.Version), req) if err != nil { if status.Code(err) == codes.PermissionDenied { err = fmt.Errorf("%w Need monitoring metric writer permission on project=%s. Follow https://cloud.google.com/spanner/docs/view-manage-client-side-metrics#access-client-side-metrics to set up permissions", diff --git a/spanner/spannertest/integration_test.go b/spanner/spannertest/integration_test.go index 22165c0ba34d..dbdfa3ac8aeb 100644 --- a/spanner/spannertest/integration_test.go +++ b/spanner/spannertest/integration_test.go @@ -142,10 +142,7 @@ func makeClient(t *testing.T) (*spanner.Client, *dbadmin.DatabaseAdminClient, *v client, _, err = spanner.NewMultiEndpointClient(ctx, dbName(), gmeCfg, opts...) os.Setenv("SPANNER_EMULATOR_HOST", old) } else { - opts = append(opts, - option.WithGRPCDialOption(grpc.WithTransportCredentials(insecure.NewCredentials())), - option.WithoutAuthentication(), - option.WithEndpoint(srv.Addr)) + opts = append(opts, option.WithGRPCConn(conn)) client, err = spanner.NewClient(ctx, dbName(), opts...) } if err != nil {