Skip to content

Commit

Permalink
make otel service name configurable
Browse files Browse the repository at this point in the history
  • Loading branch information
myleshorton committed Nov 17, 2024
1 parent d182112 commit 12c1693
Showing 1 changed file with 6 additions and 2 deletions.
8 changes: 6 additions & 2 deletions otel/otel.go
Original file line number Diff line number Diff line change
Expand Up @@ -28,6 +28,7 @@ var (
stopperMx sync.Mutex

stopReconfiguration atomic.Bool
serviceName atomic.Value
)

type Config struct {
Expand All @@ -38,9 +39,10 @@ type Config struct {
}

// ConfigureOnce is used to prevent reinitialization of OpenTelemetry by later arriving configurations
func ConfigureOnce(cfg *Config) {
func ConfigureOnce(cfg *Config, name string) {
Configure(cfg)
stopReconfiguration.Store(true)
serviceName.Store(name)
}

func Configure(cfg *Config) {
Expand All @@ -51,6 +53,7 @@ func Configure(cfg *Config) {
log.Debugf("Connecting to endpoint %v", cfg.Endpoint)
log.Debugf("Using headers %v", cfg.Headers)

serviceName.Store("flashlight")
if cfg.SampleRate < 1 {
cfg.SampleRate = 1
}
Expand All @@ -71,8 +74,9 @@ func Configure(cfg *Config) {
} else {
log.Debug("Will report traces to OpenTelemetry")
// Create a TracerProvider that uses the above exporter
var name string = serviceName.Load().(string)
attributes := []attribute.KeyValue{
semconv.ServiceNameKey.String("flashlight"),
semconv.ServiceNameKey.String(name),
}
// Copy global attributes from ops
globalAttributesFromOps := ops.AsMap(nil, true)
Expand Down

0 comments on commit 12c1693

Please sign in to comment.