From e20ccdd0113f8d5ba269f8d936f52249f423f4a0 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=E5=94=90=E5=B0=8F=E9=B8=AD?= Date: Mon, 23 Oct 2023 21:22:16 +0800 Subject: [PATCH] Support for resource injection (#3383) Co-authored-by: Kevin Wan --- core/trace/agent.go | 4 +++- core/trace/resource.go | 10 ++++++++++ 2 files changed, 13 insertions(+), 1 deletion(-) create mode 100644 core/trace/resource.go diff --git a/core/trace/agent.go b/core/trace/agent.go index 19ae59cd..2a2e8c37 100644 --- a/core/trace/agent.go +++ b/core/trace/agent.go @@ -113,11 +113,13 @@ func createExporter(c Config) (sdktrace.SpanExporter, error) { } func startAgent(c Config) error { + AddResources(semconv.ServiceNameKey.String(c.Name)) + opts := []sdktrace.TracerProviderOption{ // Set the sampling rate based on the parent span to 100% sdktrace.WithSampler(sdktrace.ParentBased(sdktrace.TraceIDRatioBased(c.Sampler))), // Record information about this application in a Resource. - sdktrace.WithResource(resource.NewSchemaless(semconv.ServiceNameKey.String(c.Name))), + sdktrace.WithResource(resource.NewSchemaless(attrResources...)), } if len(c.Endpoint) > 0 { diff --git a/core/trace/resource.go b/core/trace/resource.go new file mode 100644 index 00000000..84d4d453 --- /dev/null +++ b/core/trace/resource.go @@ -0,0 +1,10 @@ +package trace + +import "go.opentelemetry.io/otel/attribute" + +var attrResources = make([]attribute.KeyValue, 0) + +// AddResources add more resources in addition to configured trace name. +func AddResources(attrs ...attribute.KeyValue) { + attrResources = append(attrResources, attrs...) +}