feat: add env vars to control otel

This commit is contained in:
Kevin Franklin Kim 2022-06-29 23:58:23 +02:00
parent 50520b9abb
commit e6ecec93a4
3 changed files with 7 additions and 5 deletions

View File

@ -31,7 +31,7 @@ type (
func ClientWithOtelEnabled(v bool) ClientOption {
return func(o *ClientOptions) {
o.OtelEnabled = env.GetBool("OTEL_ENABLED", v)
o.OtelEnabled = v
}
}
@ -52,7 +52,7 @@ func DefaultClientOptions() ClientOptions {
Logger: log.Logger(),
Namespace: "default",
RegisterNamespace: nil,
OtelEnabled: env.GetBool("OTEL_ENABLED", false),
OtelEnabled: env.GetBool("TEMPORAL_OTEL_ENABLED", env.GetBool("OTEL_ENABLED", false)),
}
}

View File

@ -56,8 +56,10 @@ func WithDatabaseOptions(v *options.DatabaseOptions) Option {
func DefaultOptions() Options {
return Options{
OtelEnabled: env.GetBool("OTEL_ENABLED", false),
OtelOptions: nil,
OtelEnabled: env.GetBool("MONGO_OTEL_ENABLED", env.GetBool("OTEL_ENABLED", false)),
OtelOptions: []otelmongo.Option{
otelmongo.WithCommandAttributeDisabled(env.GetBool("OTEL_MONGO_COMMAND_ATTRIBUTE_DISABLED", false)),
},
ClientOptions: options.Client().
SetReadConcern(readconcern.Majority()).
SetWriteConcern(writeconcern.New(writeconcern.WMajority())),

View File

@ -83,7 +83,7 @@ func newTracerProvider(e sdktrace.SpanExporter) (trace.TracerProvider, error) {
tracerProvider := sdktrace.NewTracerProvider(
sdktrace.WithBatcher(e),
sdktrace.WithResource(resource),
sdktrace.WithSampler(sdktrace.AlwaysSample()),
sdktrace.WithSampler(sdktrace.TraceIDRatioBased(env.GetFloat64("OTEL_TRACE_RATIO", 1))),
)
otel.SetTracerProvider(tracerProvider)