31 lines
701 B
Go
31 lines
701 B
Go
|
package otel
|
||
|
|
||
|
import (
|
||
|
"context"
|
||
|
"strings"
|
||
|
|
||
|
"go.opentelemetry.io/otel"
|
||
|
"go.opentelemetry.io/otel/metric"
|
||
|
"go.opentelemetry.io/otel/trace"
|
||
|
|
||
|
"gitea.libretechconsulting.com/rmcguire/go-app/pkg/config"
|
||
|
)
|
||
|
|
||
|
func GetTracer(ctx context.Context, components ...string) trace.Tracer {
|
||
|
return otel.Tracer(getName(ctx, components...))
|
||
|
}
|
||
|
|
||
|
func GetMeter(ctx context.Context, components ...string) metric.Meter {
|
||
|
return otel.Meter(getName(ctx, components...))
|
||
|
}
|
||
|
|
||
|
func getName(ctx context.Context, components ...string) string {
|
||
|
cfg := config.MustFromCtx(ctx)
|
||
|
|
||
|
path := make([]string, 0, len(components)+1)
|
||
|
path = append(path, cfg.Name)
|
||
|
path = append(path, components...)
|
||
|
|
||
|
return strings.Join(path, ".")
|
||
|
}
|