Skip to content

Commit

Permalink
updated config to use type parameter
Browse files Browse the repository at this point in the history
Signed-off-by: Daniel Rammer <[email protected]>
  • Loading branch information
hamersaw committed Nov 8, 2023
1 parent acf81e7 commit f90c2a4
Show file tree
Hide file tree
Showing 2 changed files with 17 additions and 14 deletions.
16 changes: 10 additions & 6 deletions flytestdlib/otelutils/config.go
Original file line number Diff line number Diff line change
Expand Up @@ -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"`
}

Expand Down
15 changes: 7 additions & 8 deletions flytestdlib/otelutils/factory.go
Original file line number Diff line number Diff line change
Expand Up @@ -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 {
Expand All @@ -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(
Expand All @@ -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
}

Expand Down

0 comments on commit f90c2a4

Please sign in to comment.