Skip to content

Commit a2411bb

Browse files
authored
[extension/datadog] Set os.type in resource attributes instead of os field (open-telemetry#46896)
<!--Ex. Fixing a bug - Describe the bug and how this fixes the issue. Ex. Adding a feature - Explain what this achieves.--> #### Description Follow up to open-telemetry#46881. Set `os.type` to `runtime.GOOS` in the datadog extension if not already present in resource attributes. Remove previous field for `OS`. <!-- Issue number (e.g. open-telemetry#1234) or full URL to issue, if applicable. --> #### Link to tracking issue <!--Describe what testing was performed and which tests were added.--> #### Testing Unit tests <!--Describe the documentation added.--> #### Documentation <!--Please delete paragraphs that you did not use before submitting.-->
1 parent cfb23f8 commit a2411bb

7 files changed

Lines changed: 39 additions & 30 deletions

File tree

.chloggen/stanley.liu_os-type.yaml

Lines changed: 27 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,27 @@
1+
# Use this changelog template to create an entry for release notes.
2+
3+
# One of 'breaking', 'deprecation', 'new_component', 'enhancement', 'bug_fix'
4+
change_type: enhancement
5+
6+
# The name of the component, or a single word describing the area of concern, (e.g. receiver/filelog)
7+
component: extension/datadog
8+
9+
# A brief description of the change. Surround your text with quotes ("") if it needs to start with a backtick (`).
10+
note: Set `os.type` resource attribute if not already present for Fleet Automation metadata.
11+
12+
# Mandatory: One or more tracking issues related to the change. You can use the PR number here if no issue exists.
13+
issues: [46896]
14+
15+
# (Optional) One or more lines of additional information to render under the primary note.
16+
# These lines will be padded with 2 spaces and then inserted directly into the document.
17+
# Use pipe (|) for multiline entries.
18+
subtext:
19+
20+
# If your change doesn't affect end users or the exported elements of any package,
21+
# you should instead start your pull request title with [chore] or use the "Skip Changelog" label.
22+
# Optional: The change log or logs in which this entry should be included.
23+
# e.g. '[user]' or '[user, api]'
24+
# Include 'user' if the change is relevant to end users.
25+
# Include 'api' if there is a change to a library API.
26+
# Default: '[user]'
27+
change_logs: []

extension/datadogextension/extension.go

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,7 @@ package datadogextension // import "github.com/open-telemetry/opentelemetry-coll
55

66
import (
77
"context"
8+
"runtime"
89
"sync"
910
"time"
1011

@@ -20,6 +21,7 @@ import (
2021
"go.opentelemetry.io/collector/pdata/pcommon"
2122
"go.opentelemetry.io/collector/service"
2223
"go.opentelemetry.io/collector/service/hostcapabilities"
24+
conventions "go.opentelemetry.io/otel/semconv/v1.38.0"
2325
"go.uber.org/zap"
2426

2527
"github.com/open-telemetry/opentelemetry-collector-contrib/extension/datadogextension/internal/componentchecker"
@@ -391,6 +393,10 @@ func newExtension(
391393
return true
392394
})
393395
}
396+
// Ensure os.type is always present; defer to any value already set by a resource detector
397+
if _, ok := resourceMap[string(conventions.OSTypeKey)]; !ok {
398+
resourceMap[string(conventions.OSTypeKey)] = runtime.GOOS
399+
}
394400

395401
// configure payloadSender struct
396402
ctxWithCancel, cancel := context.WithCancel(ctx)

extension/datadogextension/extension_test.go

Lines changed: 5 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,7 @@ package datadogextension
66
import (
77
"context"
88
"errors"
9+
"runtime"
910
"sync"
1011
"testing"
1112
"time"
@@ -227,9 +228,9 @@ func TestCollectorResourceAttributesArePopulated(t *testing.T) {
227228
err = ext.NotifyConfig(t.Context(), conf)
228229
require.NoError(t, err)
229230

230-
// Expect map with keys and values
231+
// Expect map with keys and values (os.type is always injected as a fallback)
231232
require.NotNil(t, ext.otelCollectorMetadata)
232-
expected := map[string]string{"a_key": "1", "b_key": "2"}
233+
expected := map[string]string{"a_key": "1", "b_key": "2", "os.type": runtime.GOOS}
233234
assert.Equal(t, expected, ext.otelCollectorMetadata.CollectorResourceAttributes)
234235

235236
// Cleanup
@@ -274,12 +275,13 @@ func TestCollectorResourceAttributesWithMultipleKeys(t *testing.T) {
274275
err = ext.NotifyConfig(t.Context(), conf)
275276
require.NoError(t, err)
276277

277-
// Verify all resource attributes are collected
278+
// Verify all resource attributes are collected (os.type is always injected as a fallback)
278279
require.NotNil(t, ext.otelCollectorMetadata)
279280
expected := map[string]string{
280281
"deployment.environment.name": "prod",
281282
"cloud.region": "us-east",
282283
"team.name": "backend",
284+
"os.type": runtime.GOOS,
283285
}
284286
assert.Equal(t, expected, ext.otelCollectorMetadata.CollectorResourceAttributes)
285287

extension/datadogextension/go.mod

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -27,6 +27,7 @@ require (
2727
go.opentelemetry.io/collector/pdata v1.53.1-0.20260312222452-c212d203a110
2828
go.opentelemetry.io/collector/service v0.147.1-0.20260312222452-c212d203a110
2929
go.opentelemetry.io/collector/service/hostcapabilities v0.147.1-0.20260312222452-c212d203a110
30+
go.opentelemetry.io/otel v1.42.0
3031
go.uber.org/zap v1.27.1
3132
)
3233

@@ -253,7 +254,6 @@ require (
253254
go.opentelemetry.io/collector/receiver/xreceiver v0.147.1-0.20260312222452-c212d203a110 // indirect
254255
go.opentelemetry.io/contrib/instrumentation/net/http/otelhttp v0.67.0 // indirect
255256
go.opentelemetry.io/contrib/otelconf v0.22.0 // indirect
256-
go.opentelemetry.io/otel v1.42.0 // indirect
257257
go.opentelemetry.io/otel/exporters/otlp/otlplog/otlploggrpc v0.18.0 // indirect
258258
go.opentelemetry.io/otel/exporters/otlp/otlplog/otlploghttp v0.18.0 // indirect
259259
go.opentelemetry.io/otel/exporters/otlp/otlpmetric/otlpmetricgrpc v1.42.0 // indirect

extension/datadogextension/internal/httpserver/httpserver_test.go

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -228,7 +228,6 @@ const successfulInstanceResponse = `{
228228
"collector_resource_attributes": {},
229229
"collector_deployment_type": "unknown",
230230
"collector_installation_method": "",
231-
"os": "",
232231
"ttl": 900000000000
233232
},
234233
"uuid": "test-uuid"

extension/datadogextension/internal/payload/payload.go

Lines changed: 0 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,6 @@ package payload // import "github.com/open-telemetry/opentelemetry-collector-con
77
import (
88
"encoding/json"
99
"errors"
10-
"runtime"
1110

1211
"github.com/DataDog/datadog-agent/pkg/serializer/marshaler"
1312
)
@@ -39,7 +38,6 @@ type OtelCollector struct {
3938
CollectorResourceAttributes map[string]string `json:"collector_resource_attributes"`
4039
CollectorDeploymentType string `json:"collector_deployment_type"` // deployment type: gateway, daemonset, or unknown
4140
CollectorInstallationMethod string `json:"collector_installation_method"` // installation method: kubernetes, bare-metal, docker, ecs-fargate, eks-fargate, or ""
42-
OS string `json:"os"` // runtime operating system (runtime.GOOS)
4341
TTL int64 `json:"ttl"`
4442
}
4543

@@ -110,7 +108,6 @@ func PrepareOtelCollectorMetadata(
110108
FullConfiguration: fullConfig,
111109
CollectorDeploymentType: deploymentType,
112110
CollectorInstallationMethod: installationMethod,
113-
OS: runtime.GOOS,
114111
TTL: ttl,
115112
}
116113
}

extension/datadogextension/internal/payload/payload_test.go

Lines changed: 0 additions & 22 deletions
Original file line numberDiff line numberDiff line change
@@ -465,28 +465,6 @@ func TestPrepareOtelCollectorMetadata_DeploymentType(t *testing.T) {
465465
}
466466
}
467467

468-
func TestPrepareOtelCollectorMetadata_OS(t *testing.T) {
469-
buildInfo := CustomBuildInfo{Command: "otelcol", Description: "Test Collector", Version: "1.0.0"}
470-
metadata := PrepareOtelCollectorMetadata(
471-
"test-host", "config", "test-uuid", "1.0.0", "datadoghq.com", "{}",
472-
"unknown", "", buildInfo, int64(5*time.Minute*3),
473-
)
474-
475-
assert.NotEmpty(t, metadata.OS)
476-
477-
payload := &OtelCollectorPayload{Hostname: "test-host", Timestamp: time.Now().UnixNano(), UUID: "test-uuid", Metadata: metadata}
478-
jsonData, err := json.Marshal(payload)
479-
require.NoError(t, err)
480-
481-
var jsonMap map[string]any
482-
err = json.Unmarshal(jsonData, &jsonMap)
483-
require.NoError(t, err)
484-
485-
metadataMap, ok := jsonMap["otel_collector"].(map[string]any)
486-
require.True(t, ok)
487-
assert.NotEmpty(t, metadataMap["os"])
488-
}
489-
490468
func TestPrepareOtelCollectorMetadata_InstallationMethod(t *testing.T) {
491469
tests := []struct {
492470
name string

0 commit comments

Comments
 (0)