Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[extension/opampextension] Report service.namespace from BuildInfo #38253

Draft
wants to merge 1 commit into
base: main
Choose a base branch
from
Draft
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
2 changes: 2 additions & 0 deletions extension/opampextension/go.mod
Original file line number Diff line number Diff line change
Expand Up @@ -79,3 +79,5 @@ replace go.opentelemetry.io/collector/extension/extensionauth => go.opentelemetr
replace go.opentelemetry.io/collector/extension/extensionauth/extensionauthtest => go.opentelemetry.io/collector/extension/extensionauth/extensionauthtest v0.0.0-20250226024140-8099e51f9a77

replace go.opentelemetry.io/collector/service/hostcapabilities => go.opentelemetry.io/collector/service/hostcapabilities v0.0.0-20250226024140-8099e51f9a77

replace go.opentelemetry.io/collector/component => github.com/observIQ/opentelemetry-collector/component v0.0.0-20250227184409-742e731ecbde
4 changes: 2 additions & 2 deletions extension/opampextension/go.sum

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

14 changes: 12 additions & 2 deletions extension/opampextension/opamp_agent.go
Original file line number Diff line number Diff line change
Expand Up @@ -50,8 +50,9 @@ type opampAgent struct {
cfg *Config
logger *zap.Logger

agentType string
agentVersion string
agentType string
agentVersion string
agentNamespace string

instanceID uuid.UUID

Expand Down Expand Up @@ -262,6 +263,13 @@ func newOpampAgent(cfg *Config, set extension.Settings) (*opampAgent, error) {
agentVersion = sv.AsString()
}

agentNamespace := set.BuildInfo.Namespace

sb, ok := set.Resource.Attributes().Get(semconv.AttributeServiceNamespace)
if ok {
agentNamespace = sb.AsString()
}

uid, err := uuid.NewV7()
if err != nil {
return nil, fmt.Errorf("could not generate uuidv7: %w", err)
Expand All @@ -288,6 +296,7 @@ func newOpampAgent(cfg *Config, set extension.Settings) (*opampAgent, error) {
logger: set.Logger,
agentType: agentType,
agentVersion: agentVersion,
agentNamespace: agentNamespace,
instanceID: uid,
capabilities: cfg.Capabilities,
opampClient: opampClient,
Expand Down Expand Up @@ -340,6 +349,7 @@ func (o *opampAgent) createAgentDescription() error {
stringKeyValue(semconv.AttributeServiceInstanceID, o.instanceID.String()),
stringKeyValue(semconv.AttributeServiceName, o.agentType),
stringKeyValue(semconv.AttributeServiceVersion, o.agentVersion),
stringKeyValue(semconv.AttributeServiceNamespace, o.agentNamespace),
}

// Initially construct using a map to properly deduplicate any keys that
Expand Down
10 changes: 9 additions & 1 deletion extension/opampextension/opamp_agent_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -34,11 +34,12 @@ import (
func TestNewOpampAgent(t *testing.T) {
cfg := createDefaultConfig()
set := extensiontest.NewNopSettings(extensiontest.NopType)
set.BuildInfo = component.BuildInfo{Version: "test version", Command: "otelcoltest"}
set.BuildInfo = component.BuildInfo{Version: "test version", Command: "otelcoltest", Namespace: "opentelemetry-test"}
o, err := newOpampAgent(cfg.(*Config), set)
assert.NoError(t, err)
assert.Equal(t, "otelcoltest", o.agentType)
assert.Equal(t, "test version", o.agentVersion)
assert.Equal(t, "opentelemetry-test", o.agentNamespace)
assert.NotEmpty(t, o.instanceID.String())
assert.True(t, o.capabilities.ReportsEffectiveConfig)
assert.True(t, o.capabilities.ReportsHealth)
Expand All @@ -54,10 +55,12 @@ func TestNewOpampAgentAttributes(t *testing.T) {
set.Resource.Attributes().PutStr(semconv.AttributeServiceName, "otelcol-distro")
set.Resource.Attributes().PutStr(semconv.AttributeServiceVersion, "distro.0")
set.Resource.Attributes().PutStr(semconv.AttributeServiceInstanceID, "f8999bc1-4c9b-4619-9bae-7f009d2411ec")
set.Resource.Attributes().PutStr(semconv.AttributeServiceNamespace, "opentelemetry-test")
o, err := newOpampAgent(cfg.(*Config), set)
assert.NoError(t, err)
assert.Equal(t, "otelcol-distro", o.agentType)
assert.Equal(t, "distro.0", o.agentVersion)
assert.Equal(t, "opentelemetry-test", o.agentNamespace)
assert.Equal(t, "f8999bc1-4c9b-4619-9bae-7f009d2411ec", o.instanceID.String())
assert.NoError(t, o.Shutdown(context.Background()))
}
Expand All @@ -70,6 +73,7 @@ func TestCreateAgentDescription(t *testing.T) {
serviceName := "otelcol-distrot"
serviceVersion := "distro.0"
serviceInstanceUUID := "f8999bc1-4c9b-4619-9bae-7f009d2411ec"
serviceNamespace := "opentelemetry-test"

testCases := []struct {
name string
Expand All @@ -85,6 +89,7 @@ func TestCreateAgentDescription(t *testing.T) {
stringKeyValue(semconv.AttributeServiceInstanceID, serviceInstanceUUID),
stringKeyValue(semconv.AttributeServiceName, serviceName),
stringKeyValue(semconv.AttributeServiceVersion, serviceVersion),
stringKeyValue(semconv.AttributeServiceNamespace, serviceNamespace),
},
NonIdentifyingAttributes: []*protobufs.KeyValue{
stringKeyValue(semconv.AttributeHostArch, runtime.GOARCH),
Expand All @@ -107,6 +112,7 @@ func TestCreateAgentDescription(t *testing.T) {
stringKeyValue(semconv.AttributeServiceInstanceID, serviceInstanceUUID),
stringKeyValue(semconv.AttributeServiceName, serviceName),
stringKeyValue(semconv.AttributeServiceVersion, serviceVersion),
stringKeyValue(semconv.AttributeServiceNamespace, serviceNamespace),
},
NonIdentifyingAttributes: []*protobufs.KeyValue{
stringKeyValue("env", "prod"),
Expand All @@ -130,6 +136,7 @@ func TestCreateAgentDescription(t *testing.T) {
stringKeyValue(semconv.AttributeServiceInstanceID, serviceInstanceUUID),
stringKeyValue(semconv.AttributeServiceName, serviceName),
stringKeyValue(semconv.AttributeServiceVersion, serviceVersion),
stringKeyValue(semconv.AttributeServiceNamespace, serviceNamespace),
},
NonIdentifyingAttributes: []*protobufs.KeyValue{
stringKeyValue(semconv.AttributeHostArch, runtime.GOARCH),
Expand All @@ -150,6 +157,7 @@ func TestCreateAgentDescription(t *testing.T) {
set.Resource.Attributes().PutStr(semconv.AttributeServiceName, serviceName)
set.Resource.Attributes().PutStr(semconv.AttributeServiceVersion, serviceVersion)
set.Resource.Attributes().PutStr(semconv.AttributeServiceInstanceID, serviceInstanceUUID)
set.Resource.Attributes().PutStr(semconv.AttributeServiceNamespace, serviceNamespace)

o, err := newOpampAgent(cfg, set)
require.NoError(t, err)
Expand Down
Loading