From f17779933e8888cc08cfdf6d3260d2744ba0c8c2 Mon Sep 17 00:00:00 2001 From: Dmitrii Stepanov Date: Tue, 12 Nov 2024 11:15:29 +0300 Subject: [PATCH] [#17] config: Add resource attributes Signed-off-by: Dmitrii Stepanov --- tracing/config.go | 7 ++++++- tracing/setup.go | 3 +++ 2 files changed, 9 insertions(+), 1 deletion(-) diff --git a/tracing/config.go b/tracing/config.go index ca4f2c4..fbfdb52 100644 --- a/tracing/config.go +++ b/tracing/config.go @@ -3,6 +3,7 @@ package tracing import ( "crypto/x509" "fmt" + "maps" ) // Exporter is type of tracing target. @@ -33,6 +34,9 @@ type Config struct { // Version is version of service instance. // Optional. Version string + // Attributes is KV list of attributes. + // Optional. + Attributes map[string]string } func (c *Config) validate() error { @@ -81,5 +85,6 @@ func (c *Config) hasChange(other *Config) bool { func (c *Config) serviceInfoEqual(other *Config) bool { return c.Service == other.Service && c.InstanceID == other.InstanceID && - c.Version == other.Version + c.Version == other.Version && + maps.Equal(c.Attributes, other.Attributes) } diff --git a/tracing/setup.go b/tracing/setup.go index 381722e..6e68044 100644 --- a/tracing/setup.go +++ b/tracing/setup.go @@ -162,6 +162,9 @@ func newResource(cfg *Config) *resource.Resource { if len(cfg.InstanceID) > 0 { attrs = append(attrs, semconv.ServiceInstanceID(cfg.InstanceID)) } + for k, v := range cfg.Attributes { + attrs = append(attrs, attribute.String(k, v)) + } return resource.NewWithAttributes( semconv.SchemaURL, attrs..., -- 2.45.2