From 01b14cb7f7ce1e2ee5c86c38544bb066dafb8b29 Mon Sep 17 00:00:00 2001 From: ale <ale@incal.net> Date: Sat, 13 Aug 2022 20:54:48 +0100 Subject: [PATCH] Set some default trace parameters --- tracing/tracing.go | 17 ++++++++++++++--- 1 file changed, 14 insertions(+), 3 deletions(-) diff --git a/tracing/tracing.go b/tracing/tracing.go index 8770791..d1b88b9 100644 --- a/tracing/tracing.go +++ b/tracing/tracing.go @@ -14,7 +14,9 @@ import ( othttp "go.opentelemetry.io/contrib/instrumentation/net/http/otelhttp" "go.opentelemetry.io/otel" "go.opentelemetry.io/otel/exporters/zipkin" + "go.opentelemetry.io/otel/sdk/resource" "go.opentelemetry.io/otel/sdk/trace" + semconv "go.opentelemetry.io/otel/semconv/v1.4.0" apitrace "go.opentelemetry.io/otel/trace" ) @@ -25,9 +27,6 @@ var ( // Global Tracer instance. Tracer apitrace.Tracer - // The active tracing configuration, if Enabled is true. - config tracingConfig - initOnce sync.Once ) @@ -76,6 +75,17 @@ func getServiceName() string { return filepath.Base(os.Args[0]) } +func defaultResource() *resource.Resource { + r, _ := resource.Merge( + resource.Default(), + resource.NewWithAttributes( + semconv.SchemaURL, + semconv.ServiceNameKey.String(getServiceName()), + ), + ) + return r +} + // Initialize tracing. Tracing will be enabled if the system-wide // tracing configuration file is present and valid. Explicitly set // TRACING_ENABLE=0 in the environment to disable tracing. @@ -118,6 +128,7 @@ func initTracing(serviceName string) { tp := trace.NewTracerProvider( trace.WithSampler(sampler), + trace.WithResource(defaultResource()), trace.WithBatcher(ze), ) -- GitLab