Go app framework
This commit is contained in:
30
pkg/otel/util.go
Normal file
30
pkg/otel/util.go
Normal file
@ -0,0 +1,30 @@
|
||||
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, ".")
|
||||
}
|
Reference in New Issue
Block a user