From d4cedbe32e9fd2ffe519c0b5e8129e6b45f0b2a2 Mon Sep 17 00:00:00 2001 From: Joseph Schorr Date: Fri, 27 Dec 2024 13:26:43 -0500 Subject: [PATCH] Wire Spanner's logging up to zerolog --- go.mod | 4 ++-- go.sum | 8 ++++---- internal/datastore/spanner/spanner.go | 4 ++++ 3 files changed, 10 insertions(+), 6 deletions(-) diff --git a/go.mod b/go.mod index e625b5e43e..85fd452168 100644 --- a/go.mod +++ b/go.mod @@ -82,7 +82,7 @@ require ( github.com/rs/xid v1.6.0 github.com/rs/zerolog v1.33.0 github.com/samber/lo v1.47.0 - github.com/samber/slog-zerolog/v2 v2.6.0 // indirect + github.com/samber/slog-zerolog/v2 v2.7.2 github.com/schollz/progressbar/v3 v3.17.1 github.com/scylladb/go-set v1.0.2 github.com/sean-/sysexits v1.0.0 @@ -332,7 +332,7 @@ require ( github.com/ryszard/goskiplist v0.0.0-20150312221310-2dfbae5fcf46 // indirect github.com/sagikazarmark/locafero v0.3.0 // indirect github.com/sagikazarmark/slog-shim v0.1.0 // indirect - github.com/samber/slog-common v0.17.0 // indirect + github.com/samber/slog-common v0.18.0 // indirect github.com/sanposhiho/wastedassign/v2 v2.0.7 // indirect github.com/santhosh-tekuri/jsonschema/v5 v5.3.1 // indirect github.com/sashamelentyev/interfacebloat v1.1.0 // indirect diff --git a/go.sum b/go.sum index 251687d052..1fe3b1e357 100644 --- a/go.sum +++ b/go.sum @@ -1532,10 +1532,10 @@ github.com/sagikazarmark/slog-shim v0.1.0 h1:diDBnUNK9N/354PgrxMywXnAwEr1QZcOr6g github.com/sagikazarmark/slog-shim v0.1.0/go.mod h1:SrcSrq8aKtyuqEI1uvTDTK1arOWRIczQRv+GVI1AkeQ= github.com/samber/lo v1.47.0 h1:z7RynLwP5nbyRscyvcD043DWYoOcYRv3mV8lBeqOCLc= github.com/samber/lo v1.47.0/go.mod h1:RmDH9Ct32Qy3gduHQuKJ3gW1fMHAnE/fAzQuf6He5cU= -github.com/samber/slog-common v0.17.0 h1:HdRnk7QQTa9ByHlLPK3llCBo8ZSX3F/ZyeqVI5dfMtI= -github.com/samber/slog-common v0.17.0/go.mod h1:mZSJhinB4aqHziR0SKPqpVZjJ0JO35JfH+dDIWqaCBk= -github.com/samber/slog-zerolog/v2 v2.6.0 h1:S7Q7fvV6HB7NSa7WnI/7ymuVkQZg5XhNXM1ltmAOvGc= -github.com/samber/slog-zerolog/v2 v2.6.0/go.mod h1:vGzG7VhveVOnyHEpr7LpIuw28QxEOfV/dQxphJRB4iY= +github.com/samber/slog-common v0.18.0 h1:zPeXHM+WhMl2zSx76Rg3EE0jwXdkut9s45K+pwhcO1c= +github.com/samber/slog-common v0.18.0/go.mod h1:6Krf+hemckfEiRDqy3J/sTpKTJQvmOoFLj9Riz3IkRU= +github.com/samber/slog-zerolog/v2 v2.7.2 h1:z2Flxz1igvyKDLqv4QjZSC6kEyB02emXL7u49R7Jxx0= +github.com/samber/slog-zerolog/v2 v2.7.2/go.mod h1:TMj08Lvcs2dSNOw03UZ01Uw7001vIOjsixD3S+V5ZOE= github.com/sanposhiho/wastedassign/v2 v2.0.7 h1:J+6nrY4VW+gC9xFzUc+XjPD3g3wF3je/NsJFwFK7Uxc= github.com/sanposhiho/wastedassign/v2 v2.0.7/go.mod h1:KyZ0MWTwxxBmfwn33zh3k1dmsbF2ud9pAAGfoLfjhtI= github.com/santhosh-tekuri/jsonschema/v5 v5.3.1 h1:lZUw3E0/J3roVtGQ+SCrUrg3ON6NgVqpn3+iol9aGu4= diff --git a/internal/datastore/spanner/spanner.go b/internal/datastore/spanner/spanner.go index 6565b3dc6c..a0304a07e2 100644 --- a/internal/datastore/spanner/spanner.go +++ b/internal/datastore/spanner/spanner.go @@ -3,6 +3,7 @@ package spanner import ( "context" "fmt" + "log/slog" "os" "regexp" "strconv" @@ -14,6 +15,7 @@ import ( sq "github.com/Masterminds/squirrel" "github.com/google/uuid" "github.com/prometheus/client_golang/prometheus" + slogzerolog "github.com/samber/slog-zerolog/v2" "go.opencensus.io/plugin/ocgrpc" "go.opencensus.io/stats/view" "go.opentelemetry.io/contrib/instrumentation/google.golang.org/grpc/otelgrpc" @@ -150,12 +152,14 @@ func NewSpannerDatastore(ctx context.Context, database string, opts ...Option) ( spannerOpts = append(spannerOpts, option.WithCredentialsJSON(config.credentialsJSON)) } + slogger := slog.New(slogzerolog.Option{Level: slog.LevelDebug, Logger: &log.Logger}.NewZerologHandler()) spannerOpts = append(spannerOpts, option.WithCredentialsFile(config.credentialsFilePath), option.WithGRPCConnectionPool(max(config.readMaxOpen, config.writeMaxOpen)), option.WithGRPCDialOption( grpc.WithStatsHandler(otelgrpc.NewClientHandler()), ), + option.WithLogger(slogger), ) client, err := spanner.NewClientWithConfig(