From 4335d8244ffefb11e693c2669221de18d303fbd2 Mon Sep 17 00:00:00 2001 From: Wassim Dhif Date: Tue, 4 Jun 2024 13:07:47 +0200 Subject: [PATCH] fix(opentelemetry): add OTEL_RESOURCE_ATTRIBUTES spaces trimming (#26233) Signed-off-by: Wassim DHIF --- .../collectors/workloadmeta_extract.go | 1 + .../collectors/workloadmeta_test.go | 36 +++++++++++++++++++ 2 files changed, 37 insertions(+) diff --git a/comp/core/tagger/taggerimpl/collectors/workloadmeta_extract.go b/comp/core/tagger/taggerimpl/collectors/workloadmeta_extract.go index 45570f2599e0f..d2c8c2efcd778 100644 --- a/comp/core/tagger/taggerimpl/collectors/workloadmeta_extract.go +++ b/comp/core/tagger/taggerimpl/collectors/workloadmeta_extract.go @@ -769,6 +769,7 @@ func (c *WorkloadMetaCollector) addOpenTelemetryStandardTags(container *workload if otelResourceAttributes, ok := container.EnvVars[envVarOtelResourceAttributes]; ok { for _, pair := range strings.Split(otelResourceAttributes, ",") { fields := strings.SplitN(pair, "=", 2) + fields[0], fields[1] = strings.TrimSpace(fields[0]), strings.TrimSpace(fields[1]) if tag, ok := otelResourceAttributesMapping[fields[0]]; ok { tags.AddStandard(tag, fields[1]) } diff --git a/comp/core/tagger/taggerimpl/collectors/workloadmeta_test.go b/comp/core/tagger/taggerimpl/collectors/workloadmeta_test.go index 5258cb03445c8..871c690b80c84 100644 --- a/comp/core/tagger/taggerimpl/collectors/workloadmeta_test.go +++ b/comp/core/tagger/taggerimpl/collectors/workloadmeta_test.go @@ -1092,6 +1092,42 @@ func TestHandleContainer(t *testing.T) { }, }, }, + { + name: "tags from environment with opentelemetry sdk with whitespace", + container: workloadmeta.Container{ + EntityID: entityID, + EntityMeta: workloadmeta.EntityMeta{ + Name: containerName, + }, + EnvVars: map[string]string{ + // env as tags + "TEAM": "container-integrations", + "TIER": "node", + + // otel standard tags + "OTEL_SERVICE_NAME": svc, + "OTEL_RESOURCE_ATTRIBUTES": fmt.Sprintf("service.name= %s, service.version = %s , deployment.environment =%s", svc, version, env), + }, + }, + envAsTags: map[string]string{ + "team": "owner_team", + }, + expected: []*types.TagInfo{ + { + Source: containerSource, + Entity: taggerEntityID, + HighCardTags: []string{ + fmt.Sprintf("container_name:%s", containerName), + fmt.Sprintf("container_id:%s", entityID.ID), + }, + OrchestratorCardTags: []string{}, + LowCardTags: append([]string{ + "owner_team:container-integrations", + }, standardTags...), + StandardTags: standardTags, + }, + }, + }, { name: "tags from labels", container: workloadmeta.Container{