Skip to content

Commit e788e31

Browse files
authored
[extension/opamp] Add os.description as non-identifying agent attribute (#35816)
**Description:** <Describe what has changed.> <!--Ex. Fixing a bug - Describe the bug and how this fixes the issue. Ex. Adding a feature - Explain what this achieves.--> The opamp extension now reports additional information about the host machine's operating system, specifically the version. It does so by reporting the semantic convention `os.description`(defined [here](https://opentelemetry.io/docs/specs/semconv/attributes-registry/os/)) as a non-identifying attribute in the agent description message. **Link to tracking Issue:** <Issue number if applicable> Closes #35555 **Testing:** <Describe what testing was performed and which tests were added.> Unit tests updated. Verified `os.description` attribute shows up with values like 'macOS 15.0' and 'Ubuntu 20.04.6 LTS'
1 parent 58a77db commit e788e31

File tree

5 files changed

+58
-2
lines changed

5 files changed

+58
-2
lines changed
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. filelogreceiver)
7+
component: opampextension
8+
9+
# A brief description of the change. Surround your text with quotes ("") if it needs to start with a backtick (`).
10+
note: Report OS description semantic convention (`os.description`) as a part of non-identifying agent description.
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: [35555]
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: []

cmd/opampsupervisor/e2e_test.go

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -752,7 +752,8 @@ func TestSupervisorAgentDescriptionConfigApplies(t *testing.T) {
752752
},
753753
}
754754

755-
require.Equal(t, expectedDescription, ad.AgentDescription)
755+
require.Subset(t, ad.AgentDescription.IdentifyingAttributes, expectedDescription.IdentifyingAttributes)
756+
require.Subset(t, ad.AgentDescription.NonIdentifyingAttributes, expectedDescription.NonIdentifyingAttributes)
756757

757758
time.Sleep(250 * time.Millisecond)
758759
}

extension/opampextension/go.mod

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -60,7 +60,7 @@ require (
6060
go.uber.org/multierr v1.11.0 // indirect
6161
golang.org/x/net v0.28.0 // indirect
6262
golang.org/x/sys v0.25.0 // indirect
63-
golang.org/x/text v0.17.0 // indirect
63+
golang.org/x/text v0.17.0
6464
google.golang.org/genproto/googleapis/rpc v0.0.0-20240814211410-ddb44dafa142 // indirect
6565
google.golang.org/protobuf v1.35.1 // indirect
6666
)

extension/opampextension/opamp_agent.go

Lines changed: 23 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -19,6 +19,7 @@ import (
1919
"github.com/open-telemetry/opamp-go/client"
2020
"github.com/open-telemetry/opamp-go/client/types"
2121
"github.com/open-telemetry/opamp-go/protobufs"
22+
"github.com/shirou/gopsutil/v4/host"
2223
"go.opentelemetry.io/collector/component"
2324
"go.opentelemetry.io/collector/component/componentstatus"
2425
"go.opentelemetry.io/collector/confmap"
@@ -27,6 +28,8 @@ import (
2728
semconv "go.opentelemetry.io/collector/semconv/v1.27.0"
2829
"go.uber.org/zap"
2930
"golang.org/x/exp/maps"
31+
"golang.org/x/text/cases"
32+
"golang.org/x/text/language"
3033
"gopkg.in/yaml.v3"
3134

3235
"github.com/open-telemetry/opentelemetry-collector-contrib/extension/opampcustommessages"
@@ -278,6 +281,7 @@ func (o *opampAgent) createAgentDescription() error {
278281
if err != nil {
279282
return err
280283
}
284+
description := getOSDescription(o.logger)
281285

282286
ident := []*protobufs.KeyValue{
283287
stringKeyValue(semconv.AttributeServiceInstanceID, o.instanceID.String()),
@@ -291,6 +295,7 @@ func (o *opampAgent) createAgentDescription() error {
291295
nonIdentifyingAttributeMap[semconv.AttributeOSType] = runtime.GOOS
292296
nonIdentifyingAttributeMap[semconv.AttributeHostArch] = runtime.GOARCH
293297
nonIdentifyingAttributeMap[semconv.AttributeHostName] = hostname
298+
nonIdentifyingAttributeMap[semconv.AttributeOSDescription] = description
294299

295300
for k, v := range o.cfg.AgentDescription.NonIdentifyingAttributes {
296301
nonIdentifyingAttributeMap[k] = v
@@ -367,3 +372,21 @@ func (o *opampAgent) setHealth(ch *protobufs.ComponentHealth) {
367372
}
368373
}
369374
}
375+
376+
func getOSDescription(logger *zap.Logger) string {
377+
info, err := host.Info()
378+
if err != nil {
379+
logger.Error("failed getting host info", zap.Error(err))
380+
return runtime.GOOS
381+
}
382+
switch runtime.GOOS {
383+
case "darwin":
384+
return "macOS " + info.PlatformVersion
385+
case "linux":
386+
return cases.Title(language.English).String(info.Platform) + " " + info.PlatformVersion
387+
case "windows":
388+
return info.Platform + " " + info.PlatformVersion
389+
default:
390+
return runtime.GOOS
391+
}
392+
}

extension/opampextension/opamp_agent_test.go

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -19,6 +19,7 @@ import (
1919
"go.opentelemetry.io/collector/confmap/confmaptest"
2020
"go.opentelemetry.io/collector/extension/extensiontest"
2121
semconv "go.opentelemetry.io/collector/semconv/v1.27.0"
22+
"go.uber.org/zap"
2223
)
2324

2425
func TestNewOpampAgent(t *testing.T) {
@@ -53,6 +54,7 @@ func TestNewOpampAgentAttributes(t *testing.T) {
5354
func TestCreateAgentDescription(t *testing.T) {
5455
hostname, err := os.Hostname()
5556
require.NoError(t, err)
57+
description := getOSDescription(zap.NewNop())
5658

5759
serviceName := "otelcol-distrot"
5860
serviceVersion := "distro.0"
@@ -76,6 +78,7 @@ func TestCreateAgentDescription(t *testing.T) {
7678
NonIdentifyingAttributes: []*protobufs.KeyValue{
7779
stringKeyValue(semconv.AttributeHostArch, runtime.GOARCH),
7880
stringKeyValue(semconv.AttributeHostName, hostname),
81+
stringKeyValue(semconv.AttributeOSDescription, description),
7982
stringKeyValue(semconv.AttributeOSType, runtime.GOOS),
8083
},
8184
},
@@ -99,6 +102,7 @@ func TestCreateAgentDescription(t *testing.T) {
99102
stringKeyValue(semconv.AttributeHostArch, runtime.GOARCH),
100103
stringKeyValue(semconv.AttributeHostName, hostname),
101104
stringKeyValue(semconv.AttributeK8SPodName, "my-very-cool-pod"),
105+
stringKeyValue(semconv.AttributeOSDescription, description),
102106
stringKeyValue(semconv.AttributeOSType, runtime.GOOS),
103107
},
104108
},
@@ -119,6 +123,7 @@ func TestCreateAgentDescription(t *testing.T) {
119123
NonIdentifyingAttributes: []*protobufs.KeyValue{
120124
stringKeyValue(semconv.AttributeHostArch, runtime.GOARCH),
121125
stringKeyValue(semconv.AttributeHostName, "override-host"),
126+
stringKeyValue(semconv.AttributeOSDescription, description),
122127
stringKeyValue(semconv.AttributeOSType, runtime.GOOS),
123128
},
124129
},

0 commit comments

Comments
 (0)