完善 otel 配置
This commit is contained in:
@@ -3,6 +3,7 @@ package globals
|
||||
import (
|
||||
"context"
|
||||
"fmt"
|
||||
"log/slog"
|
||||
"platform/pkg/env"
|
||||
|
||||
"go.opentelemetry.io/otel"
|
||||
@@ -17,11 +18,17 @@ import (
|
||||
var tp *trace.TracerProvider
|
||||
|
||||
func initOtel(ctx context.Context) error {
|
||||
addr := env.OtelHost + ":" + env.OtelPort
|
||||
name := "lanhu-platform"
|
||||
if env.OtelNameSuffix != "" {
|
||||
name += "-" + env.OtelNameSuffix
|
||||
}
|
||||
slog.Info("初始化 otel", "endpoint", addr, "service_suffix", name)
|
||||
|
||||
if env.OtelHost == "" || env.OtelPort == "" {
|
||||
return nil
|
||||
}
|
||||
|
||||
addr := env.OtelHost + ":" + env.OtelPort
|
||||
exporter, err := otlptracegrpc.New(ctx,
|
||||
otlptracegrpc.WithEndpoint(addr),
|
||||
otlptracegrpc.WithInsecure(),
|
||||
@@ -36,7 +43,7 @@ func initOtel(ctx context.Context) error {
|
||||
trace.WithResource(
|
||||
resource.NewWithAttributes(
|
||||
semconv.SchemaURL,
|
||||
semconv.ServiceNameKey.String("lanhu-platform"),
|
||||
semconv.ServiceNameKey.String(name),
|
||||
),
|
||||
),
|
||||
)
|
||||
|
||||
Reference in New Issue
Block a user