Skip to content

Commit

Permalink
feat(spanner): client built in metrics (#10998)
Browse files Browse the repository at this point in the history
* feat(spanner): client built in metrics

* add support of env disabling
  • Loading branch information
rahul2393 authored Nov 1, 2024
1 parent 1e27b43 commit d81a1a7
Show file tree
Hide file tree
Showing 2 changed files with 12 additions and 10 deletions.
19 changes: 12 additions & 7 deletions spanner/client.go
Original file line number Diff line number Diff line change
Expand Up @@ -349,6 +349,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 @@ -492,13 +498,12 @@ 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
// Check if native metrics are disabled via env.
if disableNativeMetrics, _ := strconv.ParseBool(os.Getenv("SPANNER_DISABLE_BUILTIN_METRICS")); disableNativeMetrics {
config.DisableNativeMetrics = 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 d81a1a7

Please sign in to comment.