Skip to content

Commit e38d233

Browse files
authored
[exporter/awsxrayexporter] Merge in latest semconv for awsxrayexporter. (#36894)
<!--Ex. Fixing a bug - Describe the bug and how this fixes the issue. Ex. Adding a feature - Explain what this achieves.--> #### Description The PR merge in latest semconv pkg and update existing semantic conventions utilization. And further update `awsxrayexporter` to be able to handle following both new versions of http span attributes: `http.response.status_code` migrated from [http.status_code](https://opentelemetry.io/docs/specs/semconv/attributes-registry/http/#http-status-code) `url.query` migrated from [http.target](https://opentelemetry.io/docs/specs/semconv/attributes-registry/http/#http-target). Otel Java SDK has renamed `telemetry.auto.version` to `telemetry.distro.version` ([Upstream PR](open-telemetry/opentelemetry-java-instrumentation#9065)), update `awsxrayexporter` to be able to detect both attributes. <!-- Issue number (e.g. #1234) or full URL to issue, if applicable. --> #### Link to tracking issue N/A <!--Describe what testing was performed and which tests were added.--> #### Testing Unit test passed <!--Describe the documentation added.--> #### Documentation N/A
1 parent 7ec077e commit e38d233

File tree

15 files changed

+831
-631
lines changed

15 files changed

+831
-631
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: awsxrayexporter
8+
9+
# A brief description of the change. Surround your text with quotes ("") if it needs to start with a backtick (`).
10+
note: merge in latest semantic conventions for awsxrayexporter.
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: [36894]
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: [user]

exporter/awsxrayexporter/awsxray_test.go

Lines changed: 16 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -19,7 +19,7 @@ import (
1919
"go.opentelemetry.io/collector/exporter/exportertest"
2020
"go.opentelemetry.io/collector/pdata/pcommon"
2121
"go.opentelemetry.io/collector/pdata/ptrace"
22-
conventions "go.opentelemetry.io/collector/semconv/v1.12.0"
22+
conventionsv112 "go.opentelemetry.io/collector/semconv/v1.12.0"
2323
"go.uber.org/zap"
2424

2525
"github.com/open-telemetry/opentelemetry-collector-contrib/internal/aws/awsutil"
@@ -172,22 +172,22 @@ func constructW3CFormatTraceSpanData(ispans ptrace.ScopeSpans) {
172172
func constructResource() pcommon.Resource {
173173
resource := pcommon.NewResource()
174174
attrs := resource.Attributes()
175-
attrs.PutStr(conventions.AttributeServiceName, "signup_aggregator")
176-
attrs.PutStr(conventions.AttributeContainerName, "signup_aggregator")
177-
attrs.PutStr(conventions.AttributeContainerImageName, "otel/signupaggregator")
178-
attrs.PutStr(conventions.AttributeContainerImageTag, "v1")
179-
attrs.PutStr(conventions.AttributeCloudProvider, conventions.AttributeCloudProviderAWS)
180-
attrs.PutStr(conventions.AttributeCloudAccountID, "999999998")
181-
attrs.PutStr(conventions.AttributeCloudRegion, "us-west-2")
182-
attrs.PutStr(conventions.AttributeCloudAvailabilityZone, "us-west-1b")
175+
attrs.PutStr(conventionsv112.AttributeServiceName, "signup_aggregator")
176+
attrs.PutStr(conventionsv112.AttributeContainerName, "signup_aggregator")
177+
attrs.PutStr(conventionsv112.AttributeContainerImageName, "otel/signupaggregator")
178+
attrs.PutStr(conventionsv112.AttributeContainerImageTag, "v1")
179+
attrs.PutStr(conventionsv112.AttributeCloudProvider, conventionsv112.AttributeCloudProviderAWS)
180+
attrs.PutStr(conventionsv112.AttributeCloudAccountID, "999999998")
181+
attrs.PutStr(conventionsv112.AttributeCloudRegion, "us-west-2")
182+
attrs.PutStr(conventionsv112.AttributeCloudAvailabilityZone, "us-west-1b")
183183
return resource
184184
}
185185

186186
func constructHTTPClientSpan(traceID pcommon.TraceID) ptrace.Span {
187187
attributes := make(map[string]any)
188-
attributes[conventions.AttributeHTTPMethod] = http.MethodGet
189-
attributes[conventions.AttributeHTTPURL] = "https://api.example.com/users/junit"
190-
attributes[conventions.AttributeHTTPStatusCode] = 200
188+
attributes[conventionsv112.AttributeHTTPMethod] = http.MethodGet
189+
attributes[conventionsv112.AttributeHTTPURL] = "https://api.example.com/users/junit"
190+
attributes[conventionsv112.AttributeHTTPStatusCode] = 200
191191
endTime := time.Now().Round(time.Second)
192192
startTime := endTime.Add(-90 * time.Second)
193193
spanAttributes := constructSpanAttributes(attributes)
@@ -212,10 +212,10 @@ func constructHTTPClientSpan(traceID pcommon.TraceID) ptrace.Span {
212212

213213
func constructHTTPServerSpan(traceID pcommon.TraceID) ptrace.Span {
214214
attributes := make(map[string]any)
215-
attributes[conventions.AttributeHTTPMethod] = http.MethodGet
216-
attributes[conventions.AttributeHTTPURL] = "https://api.example.com/users/junit"
217-
attributes[conventions.AttributeHTTPClientIP] = "192.168.15.32"
218-
attributes[conventions.AttributeHTTPStatusCode] = 200
215+
attributes[conventionsv112.AttributeHTTPMethod] = http.MethodGet
216+
attributes[conventionsv112.AttributeHTTPURL] = "https://api.example.com/users/junit"
217+
attributes[conventionsv112.AttributeHTTPClientIP] = "192.168.15.32"
218+
attributes[conventionsv112.AttributeHTTPStatusCode] = 200
219219
endTime := time.Now().Round(time.Second)
220220
startTime := endTime.Add(-90 * time.Second)
221221
spanAttributes := constructSpanAttributes(attributes)

exporter/awsxrayexporter/internal/translator/aws.go

Lines changed: 37 additions & 36 deletions
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,8 @@ import (
99

1010
"github.com/aws/aws-sdk-go/aws"
1111
"go.opentelemetry.io/collector/pdata/pcommon"
12-
conventions "go.opentelemetry.io/collector/semconv/v1.12.0"
12+
conventionsv112 "go.opentelemetry.io/collector/semconv/v1.12.0"
13+
conventions "go.opentelemetry.io/collector/semconv/v1.27.0"
1314

1415
awsxray "github.com/open-telemetry/opentelemetry-collector-contrib/internal/aws/xray"
1516
)
@@ -58,71 +59,71 @@ func makeAws(attributes map[string]pcommon.Value, resource pcommon.Resource, log
5859
filtered := make(map[string]pcommon.Value)
5960
resource.Attributes().Range(func(key string, value pcommon.Value) bool {
6061
switch key {
61-
case conventions.AttributeCloudProvider:
62+
case conventionsv112.AttributeCloudProvider:
6263
cloud = value.Str()
63-
case conventions.AttributeCloudPlatform:
64+
case conventionsv112.AttributeCloudPlatform:
6465
service = value.Str()
65-
case conventions.AttributeCloudAccountID:
66+
case conventionsv112.AttributeCloudAccountID:
6667
account = value.Str()
67-
case conventions.AttributeCloudAvailabilityZone:
68+
case conventionsv112.AttributeCloudAvailabilityZone:
6869
zone = value.Str()
69-
case conventions.AttributeHostID:
70+
case conventionsv112.AttributeHostID:
7071
hostID = value.Str()
71-
case conventions.AttributeHostType:
72+
case conventionsv112.AttributeHostType:
7273
hostType = value.Str()
73-
case conventions.AttributeHostImageID:
74+
case conventionsv112.AttributeHostImageID:
7475
amiID = value.Str()
75-
case conventions.AttributeContainerName:
76+
case conventionsv112.AttributeContainerName:
7677
if container == "" {
7778
container = value.Str()
7879
}
79-
case conventions.AttributeK8SPodName:
80+
case conventionsv112.AttributeK8SPodName:
8081
podUID = value.Str()
81-
case conventions.AttributeServiceNamespace:
82+
case conventionsv112.AttributeServiceNamespace:
8283
namespace = value.Str()
83-
case conventions.AttributeServiceInstanceID:
84+
case conventionsv112.AttributeServiceInstanceID:
8485
deployID = value.Str()
85-
case conventions.AttributeServiceVersion:
86+
case conventionsv112.AttributeServiceVersion:
8687
versionLabel = value.Str()
87-
case conventions.AttributeTelemetrySDKName:
88+
case conventionsv112.AttributeTelemetrySDKName:
8889
sdkName = value.Str()
89-
case conventions.AttributeTelemetrySDKLanguage:
90+
case conventionsv112.AttributeTelemetrySDKLanguage:
9091
sdkLanguage = value.Str()
91-
case conventions.AttributeTelemetrySDKVersion:
92+
case conventionsv112.AttributeTelemetrySDKVersion:
9293
sdkVersion = value.Str()
93-
case conventions.AttributeTelemetryAutoVersion:
94+
case conventionsv112.AttributeTelemetryAutoVersion, conventions.AttributeTelemetryDistroVersion:
9495
autoVersion = value.Str()
95-
case conventions.AttributeContainerID:
96+
case conventionsv112.AttributeContainerID:
9697
containerID = value.Str()
97-
case conventions.AttributeK8SClusterName:
98+
case conventionsv112.AttributeK8SClusterName:
9899
clusterName = value.Str()
99-
case conventions.AttributeAWSECSClusterARN:
100+
case conventionsv112.AttributeAWSECSClusterARN:
100101
clusterArn = value.Str()
101-
case conventions.AttributeAWSECSContainerARN:
102+
case conventionsv112.AttributeAWSECSContainerARN:
102103
containerArn = value.Str()
103-
case conventions.AttributeAWSECSTaskARN:
104+
case conventionsv112.AttributeAWSECSTaskARN:
104105
taskArn = value.Str()
105-
case conventions.AttributeAWSECSTaskFamily:
106+
case conventionsv112.AttributeAWSECSTaskFamily:
106107
taskFamily = value.Str()
107-
case conventions.AttributeAWSECSLaunchtype:
108+
case conventionsv112.AttributeAWSECSLaunchtype:
108109
launchType = value.Str()
109-
case conventions.AttributeAWSLogGroupNames:
110+
case conventionsv112.AttributeAWSLogGroupNames:
110111
logGroups = normalizeToSlice(value)
111-
case conventions.AttributeAWSLogGroupARNs:
112+
case conventionsv112.AttributeAWSLogGroupARNs:
112113
logGroupArns = normalizeToSlice(value)
113114
}
114115
return true
115116
})
116117

117118
if awsOperation, ok := attributes[awsxray.AWSOperationAttribute]; ok {
118119
operation = awsOperation.Str()
119-
} else if rpcMethod, ok := attributes[conventions.AttributeRPCMethod]; ok {
120+
} else if rpcMethod, ok := attributes[conventionsv112.AttributeRPCMethod]; ok {
120121
operation = rpcMethod.Str()
121122
}
122123

123124
for key, value := range attributes {
124125
switch key {
125-
case conventions.AttributeRPCMethod:
126+
case conventionsv112.AttributeRPCMethod:
126127
// Determinstically handled with if else above
127128
case awsxray.AWSOperationAttribute:
128129
// Determinstically handled with if else above
@@ -148,15 +149,15 @@ func makeAws(attributes map[string]pcommon.Value, resource pcommon.Resource, log
148149
filtered[key] = value
149150
}
150151
}
151-
if cloud != conventions.AttributeCloudProviderAWS && cloud != "" {
152+
if cloud != conventionsv112.AttributeCloudProviderAWS && cloud != "" {
152153
return filtered, nil // not AWS so return nil
153154
}
154155

155156
// Favor Semantic Conventions for specific SQS and DynamoDB attributes.
156-
if value, ok := attributes[conventions.AttributeMessagingURL]; ok {
157+
if value, ok := attributes[conventionsv112.AttributeMessagingURL]; ok {
157158
queueURL = value.Str()
158159
}
159-
if value, ok := attributes[conventions.AttributeAWSDynamoDBTableNames]; ok {
160+
if value, ok := attributes[conventionsv112.AttributeAWSDynamoDBTableNames]; ok {
160161
switch value.Type() {
161162
case pcommon.ValueTypeSlice:
162163
if value.Slice().Len() == 1 {
@@ -176,7 +177,7 @@ func makeAws(attributes map[string]pcommon.Value, resource pcommon.Resource, log
176177
// EC2 - add ec2 metadata to xray request if
177178
// 1. cloud.platfrom is set to "aws_ec2" or
178179
// 2. there is an non-blank host/instance id found
179-
if service == conventions.AttributeCloudPlatformAWSEC2 || hostID != "" {
180+
if service == conventionsv112.AttributeCloudPlatformAWSEC2 || hostID != "" {
180181
ec2 = &awsxray.EC2Metadata{
181182
InstanceID: awsxray.String(hostID),
182183
AvailabilityZone: awsxray.String(zone),
@@ -186,7 +187,7 @@ func makeAws(attributes map[string]pcommon.Value, resource pcommon.Resource, log
186187
}
187188

188189
// ECS
189-
if service == conventions.AttributeCloudPlatformAWSECS {
190+
if service == conventionsv112.AttributeCloudPlatformAWSECS {
190191
ecs = &awsxray.ECSMetadata{
191192
ContainerName: awsxray.String(container),
192193
ContainerID: awsxray.String(containerID),
@@ -200,7 +201,7 @@ func makeAws(attributes map[string]pcommon.Value, resource pcommon.Resource, log
200201
}
201202

202203
// Beanstalk
203-
if service == conventions.AttributeCloudPlatformAWSElasticBeanstalk && deployID != "" {
204+
if service == conventionsv112.AttributeCloudPlatformAWSElasticBeanstalk && deployID != "" {
204205
deployNum, err := strconv.ParseInt(deployID, 10, 64)
205206
if err != nil {
206207
deployNum = 0
@@ -213,7 +214,7 @@ func makeAws(attributes map[string]pcommon.Value, resource pcommon.Resource, log
213214
}
214215

215216
// EKS or native Kubernetes
216-
if service == conventions.AttributeCloudPlatformAWSEKS || clusterName != "" {
217+
if service == conventionsv112.AttributeCloudPlatformAWSEKS || clusterName != "" {
217218
eks = &awsxray.EKSMetadata{
218219
ClusterName: awsxray.String(clusterName),
219220
Pod: awsxray.String(podUID),
@@ -242,7 +243,7 @@ func makeAws(attributes map[string]pcommon.Value, resource pcommon.Resource, log
242243

243244
if sdkName != "" && sdkLanguage != "" {
244245
// Convention for SDK name for xray SDK information is e.g., `X-Ray SDK for Java`, `X-Ray for Go`.
245-
// We fill in with e.g, `opentelemetry for java` by using the conventions
246+
// We fill in with e.g, `opentelemetry for java` by using the conventionsv112
246247
sdk = sdkName + " for " + sdkLanguage
247248
} else {
248249
sdk = sdkName

0 commit comments

Comments
 (0)