From dc0aade75abfd9b0f8bd213050e4c86be8c209dc Mon Sep 17 00:00:00 2001 From: Sam Hazlehurst Date: Tue, 5 Nov 2024 11:26:11 -0500 Subject: [PATCH] chore: Add OTEL_AES_CREDENTIAL_PROVIDER key to agent description (#1938) * Add OTEL_AES_CREDENTIAL_PROVIDER key hash to agent description * Switch to sending key instead of hash, send in NonIdentifyingAttributes --- opamp/observiq/identity.go | 6 ++++++ opamp/observiq/identity_test.go | 4 ++++ 2 files changed, 10 insertions(+) diff --git a/opamp/observiq/identity.go b/opamp/observiq/identity.go index 13a7846a2..2c9b020f1 100644 --- a/opamp/observiq/identity.go +++ b/opamp/observiq/identity.go @@ -15,6 +15,7 @@ package observiq import ( + "os" "runtime" ios "github.com/observiq/bindplane-agent/internal/os" @@ -115,6 +116,11 @@ func (i *identity) ToAgentDescription() *protobufs.AgentDescription { nonIdentifyingAttributes = append(nonIdentifyingAttributes, opamp.StringKeyValue("service.labels", *i.labels)) } + key := os.Getenv("OTEL_AES_CREDENTIAL_PROVIDER") + if key != "" { + nonIdentifyingAttributes = append(nonIdentifyingAttributes, opamp.StringKeyValue("service.key", key)) + } + agentDesc := &protobufs.AgentDescription{ IdentifyingAttributes: identifyingAttributes, NonIdentifyingAttributes: nonIdentifyingAttributes, diff --git a/opamp/observiq/identity_test.go b/opamp/observiq/identity_test.go index 487fd26ef..eff6bf22f 100644 --- a/opamp/observiq/identity_test.go +++ b/opamp/observiq/identity_test.go @@ -15,6 +15,7 @@ package observiq import ( + "os" "runtime" "testing" @@ -104,6 +105,7 @@ func TestToAgentDescription(t *testing.T) { opamp.StringKeyValue("os.family", "linux"), opamp.StringKeyValue("host.name", "my-linux-box"), opamp.StringKeyValue("host.mac_address", "68-C7-B4-EB-A8-D2"), + opamp.StringKeyValue("service.key", "test-key"), }, }, }, @@ -135,12 +137,14 @@ func TestToAgentDescription(t *testing.T) { opamp.StringKeyValue("host.name", "my-linux-box"), opamp.StringKeyValue("host.mac_address", "68-C7-B4-EB-A8-D2"), opamp.StringKeyValue("service.labels", labelsContents), + opamp.StringKeyValue("service.key", "test-key"), }, }, }, } for _, tc := range testCases { + os.Setenv("OTEL_AES_CREDENTIAL_PROVIDER", "test-key") t.Run(tc.desc, func(t *testing.T) { actual := tc.ident.ToAgentDescription() assert.Equal(t, tc.expected, actual)