Skip to content

Commit 6f37dec

Browse files
authored
Add support for deployment.environment.name (#1722)
# Description of the issue ApplicationSignalsProcessor relies on the resource attribute `deployment.environment` as a customer-provided override for ApplicationSignals `Environment`. However, `deployment.environment` has been deprecated and replaced with `deployment.environment.name` in the upstream. # Description of changes In this PR, we are adding support for the new attribute, while maintaining support for the old attribute, since customers may still specify `deployment.environment`, for example, if they are running on older OTEL versions. Callout: We are no longer getting these attribute names from semconv as: 1. We were relying on go.opentelemetry.io/collector/semconv/v1.22.0, which does not have `deployment.environment.name` 2. https://pkg.go.dev/go.opentelemetry.io/collector/semconv has been deprecated 3. It's replacement, https://pkg.go.dev/go.opentelemetry.io/otel/semconv does not include `deployment.environment.name`: https://github.com/search?q=repo%3Aopen-telemetry%2Fopentelemetry-go+deployment.environment.name&type=code 4. Nor does it include `deployment.environment` in the latest releases (1.3x): https://github.com/search?q=repo%3Aopen-telemetry%2Fopentelemetry-go+deployment.environment&type=code So we hardcode these attributes within the processor logic.
1 parent 5715f35 commit 6f37dec

File tree

3 files changed

+37
-29
lines changed

3 files changed

+37
-29
lines changed

plugins/processors/awsapplicationsignals/internal/attributes/attributes.go

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -27,6 +27,10 @@ const (
2727
ResourceDetectionHostName = "host.name"
2828
ResourceDetectionASG = "ec2.tag.aws:autoscaling:groupName"
2929

30+
// deployment resource attributes
31+
AttributeDeploymentEnvironment = "deployment.environment"
32+
AttributeDeploymentEnvironmentName = "deployment.environment.name"
33+
3034
// ApplicationSignals behaviour-changing attributes
3135
AWSApplicationSignalsMetricResourceKeys = "aws.application_signals.metric_resource_keys"
3236
)

plugins/processors/awsapplicationsignals/internal/resolver/attributesresolver.go

Lines changed: 8 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,6 @@ import (
99
"fmt"
1010

1111
"go.opentelemetry.io/collector/pdata/pcommon"
12-
semconv "go.opentelemetry.io/collector/semconv/v1.22.0"
1312
"go.uber.org/zap"
1413

1514
"github.com/aws/amazon-cloudwatch-agent/plugins/processors/awsapplicationsignals/common"
@@ -28,16 +27,18 @@ const (
2827
)
2928

3029
var GenericInheritedAttributes = map[string]string{
31-
semconv.AttributeDeploymentEnvironment: attr.AWSLocalEnvironment,
32-
attr.ResourceDetectionHostName: common.AttributeHost,
30+
attr.AttributeDeploymentEnvironment: attr.AWSLocalEnvironment,
31+
attr.AttributeDeploymentEnvironmentName: attr.AWSLocalEnvironment,
32+
attr.ResourceDetectionHostName: common.AttributeHost,
3333
}
3434

3535
// DefaultInheritedAttributes is an allow-list that also renames attributes from the resource detection processor
3636
var DefaultInheritedAttributes = map[string]string{
37-
semconv.AttributeDeploymentEnvironment: attr.AWSLocalEnvironment,
38-
attr.ResourceDetectionASG: common.AttributeEC2AutoScalingGroup,
39-
attr.ResourceDetectionHostId: common.AttributeEC2InstanceId,
40-
attr.ResourceDetectionHostName: common.AttributeHost,
37+
attr.AttributeDeploymentEnvironment: attr.AWSLocalEnvironment,
38+
attr.AttributeDeploymentEnvironmentName: attr.AWSLocalEnvironment,
39+
attr.ResourceDetectionASG: common.AttributeEC2AutoScalingGroup,
40+
attr.ResourceDetectionHostId: common.AttributeEC2InstanceId,
41+
attr.ResourceDetectionHostName: common.AttributeHost,
4142
}
4243

4344
type subResolver interface {

plugins/processors/awsapplicationsignals/internal/resolver/attributesresolver_test.go

Lines changed: 25 additions & 22 deletions
Original file line numberDiff line numberDiff line change
@@ -131,41 +131,44 @@ func TestResourceAttributesResolverWithCustomEnvironment(t *testing.T) {
131131
attributesResolver := NewAttributesResolver([]config.Resolver{tt.resolver}, logger)
132132
resolver := attributesResolver.subResolvers[0]
133133

134-
attributes := pcommon.NewMap()
134+
// Test hosted in env overrides default env
135135
resourceAttributes := pcommon.NewMap()
136-
// insert default env
137136
resourceAttributes.PutStr(attr.ResourceDetectionASG, "my-asg")
138137
resourceAttributes.PutStr(semconv.AttributeAWSECSTaskARN, "arn:aws:ecs:us-west-1:123456789123:task/my-cluster/10838bed-421f-43ef-870a-f43feacbbb5b")
138+
resourceAttributes.PutStr(attr.AWSHostedInEnvironment, "hosted_in_env")
139+
validateLocalEnvResolution(t, resolver, resourceAttributes, "hosted_in_env")
139140

140-
// insert custom env
141-
resourceAttributes.PutStr(attr.AWSHostedInEnvironment, "env1")
142-
resolver.Process(attributes, resourceAttributes)
143-
envAttr, ok := attributes.Get(attr.AWSLocalEnvironment)
144-
assert.True(t, ok)
145-
assert.Equal(t, "env1", envAttr.Str())
146-
147-
attributes = pcommon.NewMap()
141+
// Test deployment env overrides hosted in env
148142
resourceAttributes = pcommon.NewMap()
143+
resourceAttributes.PutStr(attr.AWSHostedInEnvironment, "hosted_in_env")
144+
resourceAttributes.PutStr(attr.AttributeDeploymentEnvironment, "dep_env")
145+
validateLocalEnvResolution(t, resolver, resourceAttributes, "dep_env")
149146

150-
resourceAttributes.PutStr(attr.AWSHostedInEnvironment, "error")
151-
resourceAttributes.PutStr(semconv.AttributeDeploymentEnvironment, "env2")
152-
resolver.Process(attributes, resourceAttributes)
153-
envAttr, ok = attributes.Get(attr.AWSLocalEnvironment)
154-
assert.True(t, ok)
155-
assert.Equal(t, "env2", envAttr.Str())
147+
resourceAttributes = pcommon.NewMap()
148+
resourceAttributes.PutStr(attr.AWSHostedInEnvironment, "hosted_in_env")
149+
resourceAttributes.PutStr(attr.AttributeDeploymentEnvironmentName, "dep_env_name")
150+
validateLocalEnvResolution(t, resolver, resourceAttributes, "dep_env_name")
156151

157-
attributes = pcommon.NewMap()
152+
// Test deployment env works standalone
158153
resourceAttributes = pcommon.NewMap()
154+
resourceAttributes.PutStr(attr.AttributeDeploymentEnvironment, "dep_env")
155+
validateLocalEnvResolution(t, resolver, resourceAttributes, "dep_env")
159156

160-
resourceAttributes.PutStr(semconv.AttributeDeploymentEnvironment, "env3")
161-
resolver.Process(attributes, resourceAttributes)
162-
envAttr, ok = attributes.Get(attr.AWSLocalEnvironment)
163-
assert.True(t, ok)
164-
assert.Equal(t, "env3", envAttr.Str())
157+
resourceAttributes = pcommon.NewMap()
158+
resourceAttributes.PutStr(attr.AttributeDeploymentEnvironmentName, "dep_env_name")
159+
validateLocalEnvResolution(t, resolver, resourceAttributes, "dep_env_name")
165160
})
166161
}
167162
}
168163

164+
func validateLocalEnvResolution(t *testing.T, resolver subResolver, resourceAttributes pcommon.Map, expectedEnv string) {
165+
attributes := pcommon.NewMap()
166+
resolver.Process(attributes, resourceAttributes)
167+
envAttr, ok := attributes.Get(attr.AWSLocalEnvironment)
168+
assert.True(t, ok)
169+
assert.Equal(t, expectedEnv, envAttr.Str())
170+
}
171+
169172
func TestAttributesResolver_Process(t *testing.T) {
170173
attributes := pcommon.NewMap()
171174
resourceAttributes := pcommon.NewMap()

0 commit comments

Comments
 (0)