From f90c2a46b2e403a8f9fcade633db73ff340fd595 Mon Sep 17 00:00:00 2001 From: Daniel Rammer Date: Wed, 8 Nov 2023 02:21:31 -0600 Subject: [PATCH] updated config to use type parameter Signed-off-by: Daniel Rammer --- flytestdlib/otelutils/config.go | 16 ++++++++++------ flytestdlib/otelutils/factory.go | 15 +++++++-------- 2 files changed, 17 insertions(+), 14 deletions(-) diff --git a/flytestdlib/otelutils/config.go b/flytestdlib/otelutils/config.go index e7eba34ab4..3f3fb20e14 100644 --- a/flytestdlib/otelutils/config.go +++ b/flytestdlib/otelutils/config.go @@ -9,36 +9,40 @@ import ( //go:generate pflags Config --default-var=defaultConfig -type Type = string - const configSectionKey = "otel" +type ExporterType = string + +const ( + NoopExporter ExporterType = "noop" + FileExporter ExporterType = "file" + JaegerExporter ExporterType = "jaeger" +) + var ( ConfigSection = config.MustRegisterSection(configSectionKey, defaultConfig) defaultConfig = &Config{ + ExporterType: NoopExporter, FileConfig: FileConfig{ - Enabled: false, Filename: "/tmp/trace.txt", }, JaegerConfig: JaegerConfig{ - Enabled: false, Endpoint: "http://localhost:14268/api/traces", }, } ) type Config struct { + ExporterType ExporterType `json:"type" pflag:",Sets the type of exporter to configure [noop/file/jaeger]."` FileConfig FileConfig `json:"file" pflag:",Configuration for exporting telemetry traces to a file"` JaegerConfig JaegerConfig `json:"jaeger" pflag:",Configuration for exporting telemetry traces to a jaeger"` } type FileConfig struct { - Enabled bool `json:"enabled" pflag:",Set to true to enable the file exporter"` Filename string `json:"filename" pflag:",Filename to store exported telemetry traces"` } type JaegerConfig struct { - Enabled bool `json:"enabled" pflag:",Set to true to enable the jaeger exporter"` Endpoint string `json:"endpoint" pflag:",Endpoint for the jaeger telemtry trace ingestor"` } diff --git a/flytestdlib/otelutils/factory.go b/flytestdlib/otelutils/factory.go index ced04e552b..fd0fc63524 100644 --- a/flytestdlib/otelutils/factory.go +++ b/flytestdlib/otelutils/factory.go @@ -37,7 +37,10 @@ func RegisterTracerProvider(serviceName string, config *Config) error { } var opts []trace.TracerProviderOption - if config.FileConfig.Enabled { + switch config.ExporterType { + case NoopExporter: + return nil + case FileExporter: // configure file exporter f, err := os.Create(config.FileConfig.Filename) if err != nil { @@ -53,9 +56,7 @@ func RegisterTracerProvider(serviceName string, config *Config) error { } opts = append(opts, trace.WithBatcher(exporter)) - } - - if config.JaegerConfig.Enabled { + case JaegerExporter: // configure jaeger exporter exporter, err := jaeger.New( jaeger.WithCollectorEndpoint( @@ -67,10 +68,8 @@ func RegisterTracerProvider(serviceName string, config *Config) error { } opts = append(opts, trace.WithBatcher(exporter)) - } - - // if no exporters are enabled then we can return - if len(opts) == 0 { + default: + // TODO @hamersaw - warn return nil }