Skip to content
Snippets Groups Projects
Commit 01b14cb7 authored by ale's avatar ale
Browse files

Set some default trace parameters

parent 6b04d2d6
No related branches found
No related tags found
No related merge requests found
...@@ -14,7 +14,9 @@ import ( ...@@ -14,7 +14,9 @@ import (
othttp "go.opentelemetry.io/contrib/instrumentation/net/http/otelhttp" othttp "go.opentelemetry.io/contrib/instrumentation/net/http/otelhttp"
"go.opentelemetry.io/otel" "go.opentelemetry.io/otel"
"go.opentelemetry.io/otel/exporters/zipkin" "go.opentelemetry.io/otel/exporters/zipkin"
"go.opentelemetry.io/otel/sdk/resource"
"go.opentelemetry.io/otel/sdk/trace" "go.opentelemetry.io/otel/sdk/trace"
semconv "go.opentelemetry.io/otel/semconv/v1.4.0"
apitrace "go.opentelemetry.io/otel/trace" apitrace "go.opentelemetry.io/otel/trace"
) )
...@@ -25,9 +27,6 @@ var ( ...@@ -25,9 +27,6 @@ var (
// Global Tracer instance. // Global Tracer instance.
Tracer apitrace.Tracer Tracer apitrace.Tracer
// The active tracing configuration, if Enabled is true.
config tracingConfig
initOnce sync.Once initOnce sync.Once
) )
...@@ -76,6 +75,17 @@ func getServiceName() string { ...@@ -76,6 +75,17 @@ func getServiceName() string {
return filepath.Base(os.Args[0]) 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 // Initialize tracing. Tracing will be enabled if the system-wide
// tracing configuration file is present and valid. Explicitly set // tracing configuration file is present and valid. Explicitly set
// TRACING_ENABLE=0 in the environment to disable tracing. // TRACING_ENABLE=0 in the environment to disable tracing.
...@@ -118,6 +128,7 @@ func initTracing(serviceName string) { ...@@ -118,6 +128,7 @@ func initTracing(serviceName string) {
tp := trace.NewTracerProvider( tp := trace.NewTracerProvider(
trace.WithSampler(sampler), trace.WithSampler(sampler),
trace.WithResource(defaultResource()),
trace.WithBatcher(ze), trace.WithBatcher(ze),
) )
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Please register or to comment