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

Wire Spanner's logging up to zerolog #2181

Merged
merged 1 commit into from
Dec 30, 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
4 changes: 2 additions & 2 deletions go.mod
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -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
Expand Down
8 changes: 4 additions & 4 deletions go.sum
Original file line number Diff line number Diff line change
Expand Up @@ -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=
Expand Down
4 changes: 4 additions & 0 deletions internal/datastore/spanner/spanner.go
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@ package spanner
import (
"context"
"fmt"
"log/slog"
"os"
"regexp"
"strconv"
Expand All @@ -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"
Expand Down Expand Up @@ -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(
Expand Down
Loading