Skip to content

Commit

Permalink
Remove HTTP attributes from container tags in OTLP span -> Datadog sp… (
Browse files Browse the repository at this point in the history
#470)

* Remove HTTP attributes from container tags in OTLP span -> Datadog span mapping

* fix pr number
  • Loading branch information
IbraheemA authored Jan 17, 2025
1 parent 3aaff86 commit 4f7f618
Show file tree
Hide file tree
Showing 3 changed files with 14 additions and 34 deletions.
11 changes: 11 additions & 0 deletions .chloggen/remove-http-mappings-from-container-tags.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
# One of 'breaking', 'deprecation', 'new_component', 'enhancement', 'bug_fix'
change_type: bug_fix

# The name of the component (e.g. pkg/quantile)
component: pkg/otlp/attributes

# A brief description of the change. Surround your text with quotes ("") if it needs to start with a backtick (`).
note: Remove HTTP attributes from container tags in OTLP span -> Datadog span mapping

# The PR related to this change
issues: [470]
11 changes: 2 additions & 9 deletions pkg/otlp/attributes/attributes.go
Original file line number Diff line number Diff line change
Expand Up @@ -170,9 +170,9 @@ var (
"version": {},
}

// httpMapping defines the mapping between OpenTelemetry semantic conventions
// HTTPMappings defines the mapping between OpenTelemetry semantic conventions
// and Datadog Agent conventions for HTTP attributes.
httpMapping = map[string]string{
HTTPMappings = map[string]string{
semconv127.AttributeClientAddress: "http.client_ip",
semconv127.AttributeHTTPResponseBodySize: "http.response.content_length",
semconv127.AttributeHTTPResponseStatusCode: "http.status_code",
Expand Down Expand Up @@ -226,13 +226,6 @@ func TagsFromAttributes(attrs pcommon.Map) []string {
tags = append(tags, fmt.Sprintf("%s:%s", datadogKey, value.Str()))
}

// HTTP attributes mapping
if datadogKey, found := httpMapping[key]; found && value.Str() != "" {
tags = append(tags, fmt.Sprintf("%s:%s", datadogKey, value.Str()))
} else if strings.HasPrefix(key, "http.request.header.") {
tags = append(tags, fmt.Sprintf("http.request.headers.%s:%s", strings.TrimPrefix(key, "http.request.header."), value.Str()))
}

// Kubernetes DD tags
if _, found := kubernetesDDTags[key]; found {
tags = append(tags, fmt.Sprintf("%s:%s", key, value.Str()))
Expand Down
26 changes: 1 addition & 25 deletions pkg/otlp/attributes/attributes_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -41,18 +41,6 @@ func TestTagsFromAttributes(t *testing.T) {
semconv127.AttributeContainerName: "custom",
"datadog.container.tag.custom.team": "otel",
"kube_cronjob": "cron",
semconv127.AttributeClientAddress: "sample_client_address",
semconv127.AttributeHTTPResponseBodySize: "sample_content_length",
semconv127.AttributeHTTPResponseStatusCode: "sample_status_code",
semconv127.AttributeHTTPRequestBodySize: "sample_content_length",
"http.request.header.referrer": "sample_referrer",
semconv127.AttributeHTTPRequestMethod: "sample_method",
semconv127.AttributeHTTPRoute: "sample_route",
semconv127.AttributeNetworkProtocolVersion: "sample_version",
semconv127.AttributeServerAddress: "sample_server_name",
semconv127.AttributeURLFull: "sample_url",
semconv127.AttributeUserAgentOriginal: "sample_useragent",
"http.request.header.example": "test",
}
attrs := pcommon.NewMap()
attrs.FromRaw(attributeMap)
Expand All @@ -68,18 +56,6 @@ func TestTagsFromAttributes(t *testing.T) {
fmt.Sprintf("%s:%s", "container_name", "custom"),
fmt.Sprintf("%s:%s", "custom.team", "otel"),
fmt.Sprintf("%s:%s", "kube_cronjob", "cron"),
fmt.Sprintf("%s:%s", "http.client_ip", "sample_client_address"),
fmt.Sprintf("%s:%s", "http.response.content_length", "sample_content_length"),
fmt.Sprintf("%s:%s", "http.status_code", "sample_status_code"),
fmt.Sprintf("%s:%s", "http.request.content_length", "sample_content_length"),
fmt.Sprintf("%s:%s", "http.referrer", "sample_referrer"),
fmt.Sprintf("%s:%s", "http.method", "sample_method"),
fmt.Sprintf("%s:%s", "http.route", "sample_route"),
fmt.Sprintf("%s:%s", "http.version", "sample_version"),
fmt.Sprintf("%s:%s", "http.server_name", "sample_server_name"),
fmt.Sprintf("%s:%s", "http.url", "sample_url"),
fmt.Sprintf("%s:%s", "http.useragent", "sample_useragent"),
fmt.Sprintf("%s:%s", "http.request.headers.example", "test"),
}, TagsFromAttributes(attrs))
}

Expand Down Expand Up @@ -135,7 +111,7 @@ func TestContainerTagFromResourceAttributes(t *testing.T) {
fmt.Println(ContainerTagsFromResourceAttributes(attributes))
})

t.Run("semconv127 vs custom", func(t *testing.T) {
t.Run("conventions vs custom", func(t *testing.T) {
attributes := pcommon.NewMap()
err := attributes.FromRaw(map[string]interface{}{
semconv127.AttributeContainerName: "ok",
Expand Down

0 comments on commit 4f7f618

Please sign in to comment.