config: Add resource attributes #17

Merged
fyrchik merged 1 commit from feat/tracing_attributes into master 2024-11-12 08:45:10 +00:00
2 changed files with 9 additions and 1 deletions
Showing only changes of commit f17779933e - Show all commits

View file

@ -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)
}

View file

@ -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(
Review

resource.NewWithAttributes performs attributes validation

`resource.NewWithAttributes` performs attributes validation
semconv.SchemaURL,
attrs...,