Skip to content

Commit

Permalink
fix(opentelemetry): add OTEL_RESOURCE_ATTRIBUTES spaces trimming (#26233
Browse files Browse the repository at this point in the history
)

Signed-off-by: Wassim DHIF <wassim.dhif@datadoghq.com>
  • Loading branch information
wdhif authored Jun 4, 2024
1 parent 525470f commit 4335d82
Show file tree
Hide file tree
Showing 2 changed files with 37 additions and 0 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -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])
}
Expand Down
36 changes: 36 additions & 0 deletions comp/core/tagger/taggerimpl/collectors/workloadmeta_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -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{
Expand Down

0 comments on commit 4335d82

Please sign in to comment.