Skip to content

Commit

Permalink
feat: make verbose resource otel optional (#17)
Browse files Browse the repository at this point in the history
  • Loading branch information
mabdh authored Jun 11, 2024
1 parent fac8486 commit 8d652d0
Showing 1 changed file with 20 additions and 12 deletions.
32 changes: 20 additions & 12 deletions telemetry/opentelemetry.go
Original file line number Diff line number Diff line change
Expand Up @@ -22,10 +22,11 @@ import (
)

type OpenTelemetryConfig struct {
Enabled bool `yaml:"enabled" mapstructure:"enabled" default:"false"`
CollectorAddr string `yaml:"collector_addr" mapstructure:"collector_addr" default:"localhost:4317"`
PeriodicReadInterval time.Duration `yaml:"periodic_read_interval" mapstructure:"periodic_read_interval" default:"1s"`
TraceSampleProbability float64 `yaml:"trace_sample_probability" mapstructure:"trace_sample_probability" default:"1"`
Enabled bool `yaml:"enabled" mapstructure:"enabled" default:"false"`
CollectorAddr string `yaml:"collector_addr" mapstructure:"collector_addr" default:"localhost:4317"`
PeriodicReadInterval time.Duration `yaml:"periodic_read_interval" mapstructure:"periodic_read_interval" default:"1s"`
TraceSampleProbability float64 `yaml:"trace_sample_probability" mapstructure:"trace_sample_probability" default:"1"`
VerboseResourceLabelsEnabled bool `yaml:"verbose_resource_labels_enabled" mapstructure:"verbose_resource_labels_enabled" default:"false"`
}

func initOTLP(ctx context.Context, cfg Config, logger log.Logger) (func(), error) {
Expand All @@ -34,19 +35,26 @@ func initOTLP(ctx context.Context, cfg Config, logger log.Logger) (func(), error
return noOp, nil
}

res, err := resource.New(ctx,
resourceOptions := []resource.Option{
resource.WithFromEnv(),
resource.WithTelemetrySDK(),
resource.WithOS(),
resource.WithHost(),
resource.WithProcess(),
resource.WithProcessRuntimeName(),
resource.WithProcessRuntimeVersion(),
resource.WithAttributes(
semconv.ServiceName(cfg.AppName),
semconv.ServiceVersion(cfg.AppVersion),
),
)
}

if cfg.OpenTelemetry.VerboseResourceLabelsEnabled {
resourceOptions = append(resourceOptions,
resource.WithTelemetrySDK(),
resource.WithOS(),
resource.WithHost(),
resource.WithProcess(),
resource.WithProcessRuntimeName(),
resource.WithProcessRuntimeVersion(),
)
}

res, err := resource.New(ctx, resourceOptions...)
if err != nil {
return nil, fmt.Errorf("create resource: %w", err)
}
Expand Down

0 comments on commit 8d652d0

Please sign in to comment.