github.com/asynkron/protoactor-go@v0.0.0-20240308120642-ef91a6abee75/actor/config_opts.go (about) 1 package actor 2 3 import ( 4 "log/slog" 5 "time" 6 7 "go.opentelemetry.io/otel/metric" 8 ) 9 10 // ConfigOption is a function that configures the actor system 11 type ConfigOption func(config *Config) 12 13 // Configure sets the configuration options 14 func Configure(options ...ConfigOption) *Config { 15 config := defaultConfig() 16 for _, option := range options { 17 option(config) 18 } 19 20 return config 21 } 22 23 // WithDeadLetterThrottleInterval sets the dead letter throttle interval 24 func WithDeadLetterThrottleInterval(duration time.Duration) ConfigOption { 25 return func(config *Config) { 26 config.DeadLetterThrottleInterval = duration 27 } 28 } 29 30 // WithDeadLetterThrottleCount sets the dead letter throttle count 31 func WithDeadLetterThrottleCount(count int32) ConfigOption { 32 return func(config *Config) { 33 config.DeadLetterThrottleCount = count 34 } 35 } 36 37 // WithDeadLetterRequestLogging sets the dead letter request logging on or off 38 func WithDeadLetterRequestLogging(enabled bool) ConfigOption { 39 return func(config *Config) { 40 config.DeadLetterRequestLogging = enabled 41 } 42 } 43 44 // WithDeveloperSupervisionLogging sets the developer supervision logging on or off 45 func WithDeveloperSupervisionLogging(enabled bool) ConfigOption { 46 return func(config *Config) { 47 config.DeveloperSupervisionLogging = enabled 48 } 49 } 50 51 // WithDiagnosticsSerializer sets the diagnostics serializer 52 func WithDiagnosticsSerializer(serializer func(Actor) string) ConfigOption { 53 return func(config *Config) { 54 config.DiagnosticsSerializer = serializer 55 } 56 } 57 58 // WithMetricProviders sets the metric providers 59 func WithMetricProviders(provider metric.MeterProvider) ConfigOption { 60 61 return func(config *Config) { 62 config.MetricsProvider = provider 63 } 64 } 65 66 // WithDefaultPrometheusProvider sets the default prometheus provider 67 func WithDefaultPrometheusProvider(port ...int) ConfigOption { 68 _port := 2222 69 if len(port) > 0 { 70 _port = port[0] 71 } 72 73 return WithMetricProviders(defaultPrometheusProvider(_port)) 74 } 75 76 // WithLoggerFactory sets the logger factory to use for the actor system 77 func WithLoggerFactory(factory func(system *ActorSystem) *slog.Logger) ConfigOption { 78 return func(config *Config) { 79 config.LoggerFactory = factory 80 } 81 }