From 208e31c3d47271970de9a5b7a2dd0bf292a18f50 Mon Sep 17 00:00:00 2001 From: Ryan D McGuire Date: Sat, 4 Jan 2025 20:18:48 -0500 Subject: [PATCH] Prefer otel service name --- pkg/otel/util.go | 8 +++++++- 1 file changed, 7 insertions(+), 1 deletion(-) diff --git a/pkg/otel/util.go b/pkg/otel/util.go index be0866c..3f8d79e 100644 --- a/pkg/otel/util.go +++ b/pkg/otel/util.go @@ -2,6 +2,7 @@ package otel import ( "context" + "os" "strings" "go.opentelemetry.io/otel" @@ -22,8 +23,13 @@ func GetMeter(ctx context.Context, components ...string) metric.Meter { func getName(ctx context.Context, components ...string) string { cfg := config.MustFromCtx(ctx) + serviceName := cfg.Name + if otelEnvName := os.Getenv("OTEL_SERVICE_NAME"); otelEnvName != "" { + serviceName = otelEnvName + } + path := make([]string, 0, len(components)+1) - path = append(path, cfg.Name) + path = append(path, serviceName) path = append(path, components...) return strings.Join(path, ".")