diff --git a/tracing/tracing.go b/tracing/tracing.go index 8770791e1d16259969eddc4e7eece9259c1ea189..d1b88b9df252b46cd02d35e88be022656d54ca46 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), )