Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
27 changes: 27 additions & 0 deletions .chloggen/stanley.liu_os-type.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,27 @@
# Use this changelog template to create an entry for release notes.

# One of 'breaking', 'deprecation', 'new_component', 'enhancement', 'bug_fix'
change_type: enhancement

# The name of the component, or a single word describing the area of concern, (e.g. receiver/filelog)
component: extension/datadog

# A brief description of the change. Surround your text with quotes ("") if it needs to start with a backtick (`).
note: Set `os.type` resource attribute if not already present for Fleet Automation metadata.

# Mandatory: One or more tracking issues related to the change. You can use the PR number here if no issue exists.
issues: [46896]

# (Optional) One or more lines of additional information to render under the primary note.
# These lines will be padded with 2 spaces and then inserted directly into the document.
# Use pipe (|) for multiline entries.
subtext:

# If your change doesn't affect end users or the exported elements of any package,
# you should instead start your pull request title with [chore] or use the "Skip Changelog" label.
# Optional: The change log or logs in which this entry should be included.
# e.g. '[user]' or '[user, api]'
# Include 'user' if the change is relevant to end users.
# Include 'api' if there is a change to a library API.
# Default: '[user]'
change_logs: []
6 changes: 6 additions & 0 deletions extension/datadogextension/extension.go
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@ package datadogextension // import "github.com/open-telemetry/opentelemetry-coll

import (
"context"
"runtime"
"sync"
"time"

Expand All @@ -20,6 +21,7 @@ import (
"go.opentelemetry.io/collector/pdata/pcommon"
"go.opentelemetry.io/collector/service"
"go.opentelemetry.io/collector/service/hostcapabilities"
conventions "go.opentelemetry.io/otel/semconv/v1.38.0"
"go.uber.org/zap"

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

// configure payloadSender struct
ctxWithCancel, cancel := context.WithCancel(ctx)
Expand Down
8 changes: 5 additions & 3 deletions extension/datadogextension/extension_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@ package datadogextension
import (
"context"
"errors"
"runtime"
"sync"
"testing"
"time"
Expand Down Expand Up @@ -227,9 +228,9 @@ func TestCollectorResourceAttributesArePopulated(t *testing.T) {
err = ext.NotifyConfig(t.Context(), conf)
require.NoError(t, err)

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

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

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

Expand Down
2 changes: 1 addition & 1 deletion extension/datadogextension/go.mod
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,7 @@ require (
go.opentelemetry.io/collector/pdata v1.53.1-0.20260312222452-c212d203a110
go.opentelemetry.io/collector/service v0.147.1-0.20260312222452-c212d203a110
go.opentelemetry.io/collector/service/hostcapabilities v0.147.1-0.20260312222452-c212d203a110
go.opentelemetry.io/otel v1.42.0
go.uber.org/zap v1.27.1
)

Expand Down Expand Up @@ -253,7 +254,6 @@ require (
go.opentelemetry.io/collector/receiver/xreceiver v0.147.1-0.20260312222452-c212d203a110 // indirect
go.opentelemetry.io/contrib/instrumentation/net/http/otelhttp v0.67.0 // indirect
go.opentelemetry.io/contrib/otelconf v0.22.0 // indirect
go.opentelemetry.io/otel v1.42.0 // indirect
go.opentelemetry.io/otel/exporters/otlp/otlplog/otlploggrpc v0.18.0 // indirect
go.opentelemetry.io/otel/exporters/otlp/otlplog/otlploghttp v0.18.0 // indirect
go.opentelemetry.io/otel/exporters/otlp/otlpmetric/otlpmetricgrpc v1.42.0 // indirect
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -228,7 +228,6 @@ const successfulInstanceResponse = `{
"collector_resource_attributes": {},
"collector_deployment_type": "unknown",
"collector_installation_method": "",
"os": "",
"ttl": 900000000000
},
"uuid": "test-uuid"
Expand Down
3 changes: 0 additions & 3 deletions extension/datadogextension/internal/payload/payload.go
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,6 @@ package payload // import "github.com/open-telemetry/opentelemetry-collector-con
import (
"encoding/json"
"errors"
"runtime"

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

Expand Down Expand Up @@ -110,7 +108,6 @@ func PrepareOtelCollectorMetadata(
FullConfiguration: fullConfig,
CollectorDeploymentType: deploymentType,
CollectorInstallationMethod: installationMethod,
OS: runtime.GOOS,
TTL: ttl,
}
}
22 changes: 0 additions & 22 deletions extension/datadogextension/internal/payload/payload_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -465,28 +465,6 @@ func TestPrepareOtelCollectorMetadata_DeploymentType(t *testing.T) {
}
}

func TestPrepareOtelCollectorMetadata_OS(t *testing.T) {
buildInfo := CustomBuildInfo{Command: "otelcol", Description: "Test Collector", Version: "1.0.0"}
metadata := PrepareOtelCollectorMetadata(
"test-host", "config", "test-uuid", "1.0.0", "datadoghq.com", "{}",
"unknown", "", buildInfo, int64(5*time.Minute*3),
)

assert.NotEmpty(t, metadata.OS)

payload := &OtelCollectorPayload{Hostname: "test-host", Timestamp: time.Now().UnixNano(), UUID: "test-uuid", Metadata: metadata}
jsonData, err := json.Marshal(payload)
require.NoError(t, err)

var jsonMap map[string]any
err = json.Unmarshal(jsonData, &jsonMap)
require.NoError(t, err)

metadataMap, ok := jsonMap["otel_collector"].(map[string]any)
require.True(t, ok)
assert.NotEmpty(t, metadataMap["os"])
}

func TestPrepareOtelCollectorMetadata_InstallationMethod(t *testing.T) {
tests := []struct {
name string
Expand Down
Loading