Skip to content

Commit

Permalink
feat(spanner): client built in metrics
Browse files Browse the repository at this point in the history
  • Loading branch information
rahul2393 committed Oct 16, 2024
1 parent 1a33f93 commit a9ada9b
Show file tree
Hide file tree
Showing 2 changed files with 8 additions and 10 deletions.
15 changes: 8 additions & 7 deletions spanner/client.go
Original file line number Diff line number Diff line change
Expand Up @@ -350,6 +350,12 @@ type ClientConfig struct {
//
// Default: false
EnableEndToEndTracing bool

// DisableNativeMetrics indicates whether native metrics should be disabled or not.
// If true, native metrics will not be emitted.
//
// Default: false
DisableNativeMetrics bool
}

type openTelemetryConfig struct {
Expand Down Expand Up @@ -493,13 +499,8 @@ func newClientWithConfig(ctx context.Context, database string, config ClientConf
// Do not emit native metrics when emulator is being used
metricsProvider = noop.NewMeterProvider()
}

// SPANNER_ENABLE_BUILTIN_METRICS environment variable is used to enable
// native metrics for the Spanner client, which overrides the default.
//
// This is an EXPERIMENTAL feature and may be changed or removed in the future.
if os.Getenv("SPANNER_ENABLE_BUILTIN_METRICS") != "true" {
// Do not emit native metrics when SPANNER_ENABLE_BUILTIN_METRICS is not set to true
if config.DisableNativeMetrics {
// Do not emit native metrics when DisableNativeMetrics is set
metricsProvider = noop.NewMeterProvider()
}

Expand Down
3 changes: 0 additions & 3 deletions spanner/metrics_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,6 @@ package spanner
import (
"context"
"fmt"
"os"
"sort"
"testing"

Expand All @@ -39,8 +38,6 @@ import (
)

func TestNewBuiltinMetricsTracerFactory(t *testing.T) {
os.Setenv("SPANNER_ENABLE_BUILTIN_METRICS", "true")
defer os.Unsetenv("SPANNER_ENABLE_BUILTIN_METRICS")
ctx := context.Background()
clientUID := "test-uid"
createSessionRPC := "Spanner.BatchCreateSessions"
Expand Down

0 comments on commit a9ada9b

Please sign in to comment.