Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

feat(spanner): client built in metrics #10998

Merged
merged 4 commits into from
Nov 1, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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
Loading