logger to ctx

This commit is contained in:
Elio Bischof 2024-12-10 09:28:06 +01:00
parent 70e49c7e4c
commit e5e893d1f1
No known key found for this signature in database
GPG Key ID: 7B383FDE4DDBF1BD
9 changed files with 37 additions and 32 deletions

View File

@ -21,7 +21,7 @@ func NewCleanup() *cobra.Command {
Short: "cleans up migration if they got stuck",
Long: `cleans up migration if they got stuck`,
Run: func(cmd *cobra.Command, args []string) {
config := MustNewConfig(viper.GetViper())
config, _ := MustNewConfig(cmd.Context(), viper.GetViper())
Cleanup(config)
},
}

View File

@ -2,6 +2,7 @@ package setup
import (
"bytes"
"context"
"log/slog"
"strings"
"time"
@ -63,7 +64,7 @@ type InitProjections struct {
BulkLimit uint64
}
func MustNewConfig(v *viper.Viper) *Config {
func MustNewConfig(ctx context.Context, v *viper.Viper) (*Config, context.Context) {
config := new(Config)
err := v.Unmarshal(config,
viper.DecodeHook(mapstructure.ComposeDecodeHookFunc(
@ -89,11 +90,13 @@ func MustNewConfig(v *viper.Viper) *Config {
"version": build.Version(),
}
slog.SetDefault(config.Log.Slog())
logger := config.Log.Slog()
slog.SetDefault(logger)
loggerCtx := logging.ToContext(ctx, logger)
id.Configure(config.Machine)
return config
return config, loggerCtx
}
type Steps struct {

View File

@ -64,13 +64,13 @@ Requirements:
err = bindForMirror(cmd)
logging.OnError(err).Fatal("unable to bind \"for-mirror\" flag")
config := MustNewConfig(viper.GetViper())
config, ctx := MustNewConfig(cmd.Context(), viper.GetViper())
steps := MustNewSteps(viper.New())
masterKey, err := key.MasterKey(cmd)
logging.OnError(err).Panic("No master key provided")
Setup(cmd.Context(), config, steps, masterKey)
Setup(ctx, config, steps, masterKey)
},
}

View File

@ -1,6 +1,7 @@
package start
import (
"context"
"log/slog"
"time"
@ -88,7 +89,7 @@ type QuotasConfig struct {
Execution *logstore.EmitterConfig
}
func MustNewConfig(v *viper.Viper) *Config {
func MustNewConfig(ctx context.Context, v *viper.Viper) (*Config, context.Context) {
config := new(Config)
err := v.Unmarshal(config,
@ -117,7 +118,9 @@ func MustNewConfig(v *viper.Viper) *Config {
"version": build.Version(),
}
slog.SetDefault(config.Log.Slog())
logger := config.Log.Slog()
slog.SetDefault(logger)
loggerCtx := logging.ToContext(ctx, logger)
err = config.Tracing.NewTracer()
logging.OnError(err).Fatal("unable to set tracer")
@ -131,5 +134,5 @@ func MustNewConfig(v *viper.Viper) *Config {
id.Configure(config.Machine)
actions.SetHTTPConfig(&config.Actions.HTTP)
return config
return config, loggerCtx
}

View File

@ -109,12 +109,12 @@ Requirements:
if err != nil {
return err
}
config := MustNewConfig(viper.GetViper())
config, ctx := MustNewConfig(cmd.Context(), viper.GetViper())
masterKey, err := key.MasterKey(cmd)
if err != nil {
return err
}
return startZitadel(cmd.Context(), config, masterKey, server)
return startZitadel(ctx, config, masterKey, server)
},
}

View File

@ -34,13 +34,13 @@ Requirements:
err = setup.BindInitProjections(cmd)
logging.OnError(err).Fatal("unable to bind \"init-projections\" flag")
setupConfig := setup.MustNewConfig(viper.GetViper())
setupConfig, ctx := setup.MustNewConfig(cmd.Context(), viper.GetViper())
setupSteps := setup.MustNewSteps(viper.New())
setup.Setup(cmd.Context(), setupConfig, setupSteps, masterKey)
setup.Setup(ctx, setupConfig, setupSteps, masterKey)
startConfig := MustNewConfig(viper.GetViper())
startConfig, ctx := MustNewConfig(ctx, viper.GetViper())
err = startZitadel(cmd.Context(), startConfig, masterKey, server)
err = startZitadel(ctx, startConfig, masterKey, server)
logging.OnError(err).Fatal("unable to start zitadel")
},
}

View File

@ -32,13 +32,13 @@ Requirements:
err = setup.BindInitProjections(cmd)
logging.OnError(err).Fatal("unable to bind \"init-projections\" flag")
setupConfig := setup.MustNewConfig(viper.GetViper())
setupConfig, ctx := setup.MustNewConfig(cmd.Context(), viper.GetViper())
setupSteps := setup.MustNewSteps(viper.New())
setup.Setup(cmd.Context(), setupConfig, setupSteps, masterKey)
setup.Setup(ctx, setupConfig, setupSteps, masterKey)
startConfig := MustNewConfig(viper.GetViper())
startConfig, ctx := MustNewConfig(ctx, viper.GetViper())
err = startZitadel(cmd.Context(), startConfig, masterKey, server)
err = startZitadel(ctx, startConfig, masterKey, server)
logging.OnError(err).Fatal("unable to start zitadel")
},
}

8
go.mod
View File

@ -60,7 +60,7 @@ require (
github.com/sony/sonyflake v1.2.0
github.com/spf13/cobra v1.8.1
github.com/spf13/viper v1.19.0
github.com/stretchr/testify v1.9.0
github.com/stretchr/testify v1.10.0
github.com/superseriousbusiness/exifremove v0.0.0-20210330092427-6acd27eac203
github.com/ttacon/libphonenumber v1.2.1
github.com/twilio/twilio-go v1.22.2
@ -83,9 +83,9 @@ require (
golang.org/x/crypto v0.29.0
golang.org/x/exp v0.0.0-20240613232115-7f521ea00fb8
golang.org/x/net v0.28.0
golang.org/x/oauth2 v0.23.0
golang.org/x/sync v0.9.0
golang.org/x/text v0.20.0
golang.org/x/oauth2 v0.24.0
golang.org/x/sync v0.10.0
golang.org/x/text v0.21.0
google.golang.org/api v0.187.0
google.golang.org/genproto/googleapis/api v0.0.0-20240822170219-fc7c04adadcd
google.golang.org/grpc v1.65.0

17
go.sum
View File

@ -705,8 +705,9 @@ github.com/stretchr/testify v1.7.1/go.mod h1:6Fq8oRcR53rry900zMqJjRRixrwX3KX962/
github.com/stretchr/testify v1.8.0/go.mod h1:yNjHg4UonilssWZ8iaSj1OCr/vHnekPRkoO+kdMU+MU=
github.com/stretchr/testify v1.8.1/go.mod h1:w2LPCIKwWwSfY2zedu0+kehJoqGctiVI29o6fzry7u4=
github.com/stretchr/testify v1.8.4/go.mod h1:sz/lmYIOXD/1dqDmKjjqLyZ2RngseejIcXlSw2iwfAo=
github.com/stretchr/testify v1.9.0 h1:HtqpIVDClZ4nwg75+f6Lvsy/wHu+3BoSGCbBAcpTsTg=
github.com/stretchr/testify v1.9.0/go.mod h1:r2ic/lqez/lEtzL7wO/rwa5dbSLXVDPFyf8C91i36aY=
github.com/stretchr/testify v1.10.0 h1:Xv5erBjTwe/5IxqUQTdXv5kgmIvbHo3QQyRwhJsOfJA=
github.com/stretchr/testify v1.10.0/go.mod h1:r2ic/lqez/lEtzL7wO/rwa5dbSLXVDPFyf8C91i36aY=
github.com/subosito/gotenv v1.6.0 h1:9NlTDc1FTs4qu0DDq7AEtTPNw6SVm7uBMsUCUjABIf8=
github.com/subosito/gotenv v1.6.0/go.mod h1:Dk4QP5c2W3ibzajGcXpNraDfq2IrhjMIvMSWPKKo0FU=
github.com/superseriousbusiness/exifremove v0.0.0-20210330092427-6acd27eac203 h1:1SWXcTphBQjYGWRRxLFIAR1LVtQEj4eR7xPtyeOVM/c=
@ -737,8 +738,6 @@ github.com/yuin/gopher-lua v1.1.1 h1:kYKnWBjvbNP4XLT3+bPEwAXJx262OhaHDWDVOPjL46M
github.com/yuin/gopher-lua v1.1.1/go.mod h1:GBR0iDaNXjAgGg9zfCvksxSRnQx76gclCIb7kdAd1Pw=
github.com/zenazn/goji v1.0.1 h1:4lbD8Mx2h7IvloP7r2C0D6ltZP6Ufip8Hn0wmSK5LR8=
github.com/zenazn/goji v1.0.1/go.mod h1:7S9M489iMyHBNxwZnk9/EHS098H4/F6TATF2mIxtB1Q=
github.com/zitadel/logging v0.6.2-0.20241204114331-82224bfc6d2a h1:ITlhu6sJZBhq7XO1OxOoy3QL9EWmHRRKQSOqSSLCEWg=
github.com/zitadel/logging v0.6.2-0.20241204114331-82224bfc6d2a/go.mod h1:asotyKZQ4HXepSR3j0o++qGKeQiFt0ENDLTM4BG7tD0=
github.com/zitadel/logging v0.6.2-0.20241204121729-ea91bf60a83a h1:8lHtxjYdreKLivpa5KbvhI/BimesagWndQqDGdT7xo4=
github.com/zitadel/logging v0.6.2-0.20241204121729-ea91bf60a83a/go.mod h1:asotyKZQ4HXepSR3j0o++qGKeQiFt0ENDLTM4BG7tD0=
github.com/zitadel/oidc/v3 v3.32.0 h1:Mw0EPZRC6h+OXAuT0Uk2BZIjJQNHLqUpaJCm6c3IByc=
@ -880,8 +879,8 @@ golang.org/x/net v0.28.0/go.mod h1:yqtgsTWOOnlGLG9GFRrK3++bGOUEkNBoHZc8MEDWPNg=
golang.org/x/oauth2 v0.0.0-20180821212333-d2e6202438be/go.mod h1:N/0e6XlmueqKjAGxoOufVs8QHGRruUQn6yWY3a++T0U=
golang.org/x/oauth2 v0.0.0-20190226205417-e64efc72b421/go.mod h1:gOpvHmFTYa4IltrdGE7lF6nIHvwfUNPOp7c8zoXwtLw=
golang.org/x/oauth2 v0.0.0-20200107190931-bf48bf16ab8d/go.mod h1:gOpvHmFTYa4IltrdGE7lF6nIHvwfUNPOp7c8zoXwtLw=
golang.org/x/oauth2 v0.23.0 h1:PbgcYx2W7i4LvjJWEbf0ngHV6qJYr86PkAV3bXdLEbs=
golang.org/x/oauth2 v0.23.0/go.mod h1:XYTD2NtWslqkgxebSiOHnXEap4TF09sJSc7H1sXbhtI=
golang.org/x/oauth2 v0.24.0 h1:KTBBxWqUa0ykRPLtV69rRto9TLXcqYkeswu48x/gvNE=
golang.org/x/oauth2 v0.24.0/go.mod h1:XYTD2NtWslqkgxebSiOHnXEap4TF09sJSc7H1sXbhtI=
golang.org/x/sync v0.0.0-20180314180146-1d60e4601c6f/go.mod h1:RxMgew5VJxzue5/jJTE5uejpjVlOe/izrB70Jof72aM=
golang.org/x/sync v0.0.0-20181108010431-42b317875d0f/go.mod h1:RxMgew5VJxzue5/jJTE5uejpjVlOe/izrB70Jof72aM=
golang.org/x/sync v0.0.0-20181221193216-37e7f081c4d4/go.mod h1:RxMgew5VJxzue5/jJTE5uejpjVlOe/izrB70Jof72aM=
@ -892,8 +891,8 @@ golang.org/x/sync v0.0.0-20201020160332-67f06af15bc9/go.mod h1:RxMgew5VJxzue5/jJ
golang.org/x/sync v0.0.0-20210220032951-036812b2e83c/go.mod h1:RxMgew5VJxzue5/jJTE5uejpjVlOe/izrB70Jof72aM=
golang.org/x/sync v0.0.0-20220722155255-886fb9371eb4/go.mod h1:RxMgew5VJxzue5/jJTE5uejpjVlOe/izrB70Jof72aM=
golang.org/x/sync v0.1.0/go.mod h1:RxMgew5VJxzue5/jJTE5uejpjVlOe/izrB70Jof72aM=
golang.org/x/sync v0.9.0 h1:fEo0HyrW1GIgZdpbhCRO0PkJajUS5H9IFUztCgEo2jQ=
golang.org/x/sync v0.9.0/go.mod h1:Czt+wKu1gCyEFDUtn0jG5QVvpJ6rzVqr5aXyt9drQfk=
golang.org/x/sync v0.10.0 h1:3NQrjDixjgGwUOCaF8w2+VYHv0Ve/vGYSbdkTa98gmQ=
golang.org/x/sync v0.10.0/go.mod h1:Czt+wKu1gCyEFDUtn0jG5QVvpJ6rzVqr5aXyt9drQfk=
golang.org/x/sys v0.0.0-20180823144017-11551d06cbcc/go.mod h1:STP8DvDyc/dI5b8T5hshtkjS+E42TnysNCUPdjciGhY=
golang.org/x/sys v0.0.0-20180830151530-49385e6e1522/go.mod h1:STP8DvDyc/dI5b8T5hshtkjS+E42TnysNCUPdjciGhY=
golang.org/x/sys v0.0.0-20180905080454-ebe1bf3edb33/go.mod h1:STP8DvDyc/dI5b8T5hshtkjS+E42TnysNCUPdjciGhY=
@ -952,8 +951,8 @@ golang.org/x/text v0.3.7/go.mod h1:u+2+/6zg+i71rQMx5EYifcz6MCKuco9NR6JIITiCfzQ=
golang.org/x/text v0.7.0/go.mod h1:mrYo+phRRbMaCq/xk9113O4dZlRixOauAjOtrjsXDZ8=
golang.org/x/text v0.9.0/go.mod h1:e1OnstbJyHTd6l/uOt8jFFHp6TRDWZR/bV3emEE/zU8=
golang.org/x/text v0.14.0/go.mod h1:18ZOQIKpY8NJVqYksKHtTdi31H5itFRjB5/qKTNYzSU=
golang.org/x/text v0.20.0 h1:gK/Kv2otX8gz+wn7Rmb3vT96ZwuoxnQlY+HlJVj7Qug=
golang.org/x/text v0.20.0/go.mod h1:D4IsuqiFMhST5bX19pQ9ikHC2GsaKyk/oF+pn3ducp4=
golang.org/x/text v0.21.0 h1:zyQAAkrwaneQ066sspRyJaG9VNi/YJ1NfzcGB3hZ/qo=
golang.org/x/text v0.21.0/go.mod h1:4IBbMaMmOPCJ8SecivzSH54+73PCFmPWxNTLm+vZkEQ=
golang.org/x/time v0.0.0-20180412165947-fbb02b2291d2/go.mod h1:tRJNPiyCQ0inRvYxbN9jk5I+vvW/OXSQhTDSoE431IQ=
golang.org/x/time v0.0.0-20191024005414-555d28b269f0/go.mod h1:tRJNPiyCQ0inRvYxbN9jk5I+vvW/OXSQhTDSoE431IQ=
golang.org/x/time v0.5.0 h1:o7cqy6amK/52YcAKIPlM3a+Fpj35zvRj2TP+e1xFSfk=