Skip to content

Commit

Permalink
spanner: check database name and add a trace span even when using the…
Browse files Browse the repository at this point in the history
… emulator

These are sensible to use even for use with an emulator.

Updates #1181.

Change-Id: I5664f98ca2a700abe976cbbd587e8f2ee291d01b
Reviewed-on: https://code-review.googlesource.com/c/gocloud/+/43232
Reviewed-by: kokoro <noreply+kokoro@google.com>
Reviewed-by: Jean de Klerk <deklerk@google.com>
  • Loading branch information
dsymonds committed Jul 31, 2019
1 parent dc6be4b commit acf4f9b
Show file tree
Hide file tree
Showing 2 changed files with 8 additions and 8 deletions.
14 changes: 7 additions & 7 deletions spanner/client.go
Expand Up @@ -149,15 +149,15 @@ func NewClientWithConfig(ctx context.Context, database string, config ClientConf
config.MaxBurst = 10
}

if emulatorAddr := os.Getenv("SPANNER_EMULATOR_HOST"); emulatorAddr == "" {
// Validate database path.
if err := validDatabaseName(database); err != nil {
return nil, err
}
// Validate database path.
if err := validDatabaseName(database); err != nil {
return nil, err
}

ctx = trace.StartSpan(ctx, "cloud.google.com/go/spanner.NewClient")
defer func() { trace.EndSpan(ctx, err) }()
ctx = trace.StartSpan(ctx, "cloud.google.com/go/spanner.NewClient")
defer func() { trace.EndSpan(ctx, err) }()

if emulatorAddr := os.Getenv("SPANNER_EMULATOR_HOST"); emulatorAddr == "" {
// gRPC options.
allOpts := []option.ClientOption{
option.WithEndpoint(endpoint),
Expand Down
2 changes: 1 addition & 1 deletion spanner/client_test.go
Expand Up @@ -424,7 +424,7 @@ func TestNewClient_ConnectToEmulator(t *testing.T) {
os.Setenv("SPANNER_EMULATOR_HOST", s.Addr())
defer os.Setenv("SPANNER_EMULATOR_HOST", oldEnv)

c, err := NewClient(ctx, "some-db")
c, err := NewClient(ctx, "projects/some-proj/instances/some-inst/databases/some-db")
if err != nil {
t.Fatal(err)
}
Expand Down

0 comments on commit acf4f9b

Please sign in to comment.