Prefer otel service name
This commit is contained in:
parent
4e62e11e9e
commit
208e31c3d4
@ -2,6 +2,7 @@ package otel
|
|||||||
|
|
||||||
import (
|
import (
|
||||||
"context"
|
"context"
|
||||||
|
"os"
|
||||||
"strings"
|
"strings"
|
||||||
|
|
||||||
"go.opentelemetry.io/otel"
|
"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 {
|
func getName(ctx context.Context, components ...string) string {
|
||||||
cfg := config.MustFromCtx(ctx)
|
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 := make([]string, 0, len(components)+1)
|
||||||
path = append(path, cfg.Name)
|
path = append(path, serviceName)
|
||||||
path = append(path, components...)
|
path = append(path, components...)
|
||||||
|
|
||||||
return strings.Join(path, ".")
|
return strings.Join(path, ".")
|
||||||
|
Loading…
Reference in New Issue
Block a user