Skip to content

Commit fcb73fa

Browse files
mjlshendragonlord93
authored andcommitted
[receiver/awsxray] update to aws-sdk-go-v2 (open-telemetry#39717)
<!--Ex. Fixing a bug - Describe the bug and how this fixes the issue. Ex. Adding a feature - Explain what this achieves.--> #### Description aws-sdk-go is being [deprecated on July 31, 2025](https://aws.amazon.com/blogs/developer/announcing-end-of-support-for-aws-sdk-for-go-v1-on-july-31-2025/). This PR updates `receiver/awsxray` and finishes updating `internal/aws/xray` to aws-sdk-go-v2. <!-- Issue number (e.g. open-telemetry#1234) or full URL to issue, if applicable. --> #### Link to tracking issue Fixes open-telemetry#37732 <!--Describe what testing was performed and which tests were added.--> #### Testing I converted the existing unit tests to aws-sdk-go-v2 as well, keeping the original intent of the tests. --------- Signed-off-by: Michael Shen <[email protected]>
1 parent 3e5fcc4 commit fcb73fa

File tree

9 files changed

+93
-58
lines changed

9 files changed

+93
-58
lines changed

internal/aws/xray/go.mod

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,6 @@ module github.com/open-telemetry/opentelemetry-collector-contrib/internal/aws/xr
33
go 1.23.0
44

55
require (
6-
github.com/aws/aws-sdk-go v1.55.7
76
github.com/aws/aws-sdk-go-v2 v1.36.3
87
github.com/aws/aws-sdk-go-v2/feature/ec2/imds v1.16.30
98
github.com/aws/aws-sdk-go-v2/service/xray v1.31.4
@@ -16,6 +15,7 @@ require (
1615
)
1716

1817
require (
18+
github.com/aws/aws-sdk-go v1.55.7 // indirect
1919
github.com/aws/aws-sdk-go-v2/config v1.29.14 // indirect
2020
github.com/aws/aws-sdk-go-v2/credentials v1.17.67 // indirect
2121
github.com/aws/aws-sdk-go-v2/internal/configsources v1.3.34 // indirect

internal/aws/xray/telemetry/recorder.go

Lines changed: 15 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -9,9 +9,9 @@ import (
99
"time"
1010

1111
"github.com/aws/aws-sdk-go-v2/aws"
12+
awshttp "github.com/aws/aws-sdk-go-v2/aws/transport/http"
1213
"github.com/aws/aws-sdk-go-v2/service/xray/types"
13-
"github.com/aws/aws-sdk-go/aws/awserr"
14-
"github.com/aws/aws-sdk-go/aws/request"
14+
smithyhttp "github.com/aws/smithy-go/transport/http"
1515
)
1616

1717
type Recorder interface {
@@ -120,30 +120,27 @@ func (tr *telemetryRecorder) RecordConnectionError(err error) {
120120
if err == nil {
121121
return
122122
}
123-
var requestFailure awserr.RequestFailure
124-
if ok := errors.As(err, &requestFailure); ok {
125-
switch requestFailure.StatusCode() / 100 {
123+
124+
var (
125+
responseErr *awshttp.ResponseError
126+
requestErr *smithyhttp.RequestSendError
127+
timeoutErr *awshttp.ResponseTimeoutError
128+
)
129+
if ok := errors.As(err, &responseErr); ok {
130+
switch responseErr.HTTPStatusCode() / 100 {
126131
case 5:
127132
atomic.AddInt32(tr.record.BackendConnectionErrors.HTTPCode5XXCount, 1)
128133
case 4:
129134
atomic.AddInt32(tr.record.BackendConnectionErrors.HTTPCode4XXCount, 1)
130135
default:
131136
atomic.AddInt32(tr.record.BackendConnectionErrors.OtherCount, 1)
132137
}
138+
} else if ok := errors.As(err, &timeoutErr); ok {
139+
atomic.AddInt32(tr.record.BackendConnectionErrors.TimeoutCount, 1)
140+
} else if ok := errors.As(err, &requestErr); ok {
141+
atomic.AddInt32(tr.record.BackendConnectionErrors.UnknownHostCount, 1)
133142
} else {
134-
var awsError awserr.Error
135-
if ok = errors.As(err, &awsError); ok {
136-
switch awsError.Code() {
137-
case request.ErrCodeResponseTimeout:
138-
atomic.AddInt32(tr.record.BackendConnectionErrors.TimeoutCount, 1)
139-
case request.ErrCodeRequestError:
140-
atomic.AddInt32(tr.record.BackendConnectionErrors.UnknownHostCount, 1)
141-
default:
142-
atomic.AddInt32(tr.record.BackendConnectionErrors.OtherCount, 1)
143-
}
144-
} else {
145-
atomic.AddInt32(tr.record.BackendConnectionErrors.OtherCount, 1)
146-
}
143+
atomic.AddInt32(tr.record.BackendConnectionErrors.OtherCount, 1)
147144
}
148145
tr.hasRecording.Store(true)
149146
}

internal/aws/xray/telemetry/recorder_test.go

Lines changed: 48 additions & 22 deletions
Original file line numberDiff line numberDiff line change
@@ -9,67 +9,89 @@ import (
99
"testing"
1010

1111
"github.com/aws/aws-sdk-go-v2/aws"
12+
awshttp "github.com/aws/aws-sdk-go-v2/aws/transport/http"
1213
"github.com/aws/aws-sdk-go-v2/service/xray/types"
13-
"github.com/aws/aws-sdk-go/aws/awserr"
14-
"github.com/aws/aws-sdk-go/aws/request"
14+
smithyhttp "github.com/aws/smithy-go/transport/http"
1515
"github.com/stretchr/testify/assert"
1616
)
1717

1818
func TestRecordConnectionError(t *testing.T) {
19-
type testParameters struct {
19+
tests := []struct {
20+
name string
2021
input error
2122
want func() types.TelemetryRecord
22-
}
23-
testCases := []testParameters{
23+
}{
2424
{
25-
input: awserr.NewRequestFailure(nil, http.StatusInternalServerError, ""),
25+
name: "5xx error",
26+
input: &awshttp.ResponseError{
27+
ResponseError: &smithyhttp.ResponseError{
28+
Response: &smithyhttp.Response{
29+
Response: &http.Response{
30+
StatusCode: http.StatusInternalServerError,
31+
},
32+
},
33+
},
34+
},
2635
want: func() types.TelemetryRecord {
2736
record := NewRecord()
2837
record.BackendConnectionErrors.HTTPCode5XXCount = aws.Int32(1)
2938
return record
3039
},
3140
},
3241
{
33-
input: awserr.NewRequestFailure(nil, http.StatusBadRequest, ""),
42+
name: "4xx error",
43+
input: &awshttp.ResponseError{
44+
ResponseError: &smithyhttp.ResponseError{
45+
Response: &smithyhttp.Response{
46+
Response: &http.Response{
47+
StatusCode: http.StatusBadRequest,
48+
},
49+
},
50+
},
51+
},
3452
want: func() types.TelemetryRecord {
3553
record := NewRecord()
3654
record.BackendConnectionErrors.HTTPCode4XXCount = aws.Int32(1)
3755
return record
3856
},
3957
},
4058
{
41-
input: awserr.NewRequestFailure(nil, http.StatusFound, ""),
59+
name: "Other error (302)",
60+
input: &awshttp.ResponseError{
61+
ResponseError: &smithyhttp.ResponseError{
62+
Response: &smithyhttp.Response{
63+
Response: &http.Response{
64+
StatusCode: http.StatusFound,
65+
},
66+
},
67+
},
68+
},
4269
want: func() types.TelemetryRecord {
4370
record := NewRecord()
4471
record.BackendConnectionErrors.OtherCount = aws.Int32(1)
4572
return record
4673
},
4774
},
4875
{
49-
input: awserr.New(request.ErrCodeResponseTimeout, "", nil),
76+
name: "response timeout",
77+
input: &awshttp.ResponseTimeoutError{},
5078
want: func() types.TelemetryRecord {
5179
record := NewRecord()
5280
record.BackendConnectionErrors.TimeoutCount = aws.Int32(1)
5381
return record
5482
},
5583
},
5684
{
57-
input: awserr.New(request.ErrCodeRequestError, "", nil),
85+
name: "request error",
86+
input: &smithyhttp.RequestSendError{},
5887
want: func() types.TelemetryRecord {
5988
record := NewRecord()
6089
record.BackendConnectionErrors.UnknownHostCount = aws.Int32(1)
6190
return record
6291
},
6392
},
6493
{
65-
input: awserr.New(request.ErrCodeSerialization, "", nil),
66-
want: func() types.TelemetryRecord {
67-
record := NewRecord()
68-
record.BackendConnectionErrors.OtherCount = aws.Int32(1)
69-
return record
70-
},
71-
},
72-
{
94+
name: "other error (test)",
7395
input: errors.New("test"),
7496
want: func() types.TelemetryRecord {
7597
record := NewRecord()
@@ -78,14 +100,18 @@ func TestRecordConnectionError(t *testing.T) {
78100
},
79101
},
80102
{
103+
name: "no error",
81104
input: nil,
82105
want: NewRecord,
83106
},
84107
}
108+
85109
recorder := NewRecorder()
86-
for _, testCase := range testCases {
87-
recorder.RecordConnectionError(testCase.input)
88-
snapshot := recorder.Rotate()
89-
assert.Equal(t, testCase.want().BackendConnectionErrors, snapshot.BackendConnectionErrors)
110+
for _, test := range tests {
111+
t.Run(test.name, func(t *testing.T) {
112+
recorder.RecordConnectionError(test.input)
113+
snapshot := recorder.Rotate()
114+
assert.Equal(t, test.want().BackendConnectionErrors, snapshot.BackendConnectionErrors)
115+
})
90116
}
91117
}

internal/aws/xray/testdata/sampleapp/sample.go

Lines changed: 23 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -5,15 +5,19 @@ package main
55

66
import (
77
"context"
8+
"log"
9+
"os"
810

911
"github.com/aws/aws-sdk-go-v2/aws"
1012
"github.com/aws/aws-sdk-go-v2/config"
1113
"github.com/aws/aws-sdk-go-v2/feature/dynamodb/attributevalue"
1214
"github.com/aws/aws-sdk-go-v2/service/dynamodb"
13-
"github.com/aws/aws-xray-sdk-go/v2/instrumentation/awsv2"
15+
xrayv2 "github.com/aws/aws-xray-sdk-go/v2/instrumentation/awsv2"
1416
"github.com/aws/aws-xray-sdk-go/v2/xray"
1517
)
1618

19+
var dynamo *dynamodb.Client
20+
1721
const (
1822
existingTableName = "xray_sample_table"
1923
nonExistingTableName = "does_not_exist"
@@ -25,21 +29,29 @@ type Record struct {
2529
}
2630

2731
func main() {
28-
cfg, err := config.LoadDefaultConfig(context.Background(), config.WithRegion("us-west-2"))
32+
ctx, seg := initSegment(context.Background(), "DDB")
33+
34+
cfg, err := config.LoadDefaultConfig(ctx, config.WithRegion("us-west-2"))
2935
if err != nil {
30-
panic(err)
36+
log.Println(err)
37+
os.Exit(1)
3138
}
32-
awsv2.AWSV2Instrumentor(&cfg.APIOptions)
3339

34-
client := dynamodb.NewFromConfig(cfg)
40+
xrayv2.AWSV2Instrumentor(&cfg.APIOptions)
41+
42+
dynamo = dynamodb.NewFromConfig(cfg)
3543

36-
ctx, seg := xray.BeginSegment(context.Background(), "DDB")
3744
seg.User = "xraysegmentdump"
38-
err = ddbExpectedFailure(ctx, client)
39-
seg.Close(err)
45+
seg.Close(ddbExpectedFailure(ctx))
46+
}
47+
48+
func initSegment(ctx context.Context, name string) (context.Context, *xray.Segment) {
49+
respCtx, seg := xray.BeginSegment(ctx, name)
50+
defer seg.Close(nil)
51+
return respCtx, seg
4052
}
4153

42-
func ddbExpectedFailure(ctx context.Context, client *dynamodb.Client) error {
54+
func ddbExpectedFailure(ctx context.Context) error {
4355
err := xray.Capture(ctx, "DDB.DescribeExistingTableAndPutToMissingTable", func(ctx1 context.Context) error {
4456
err := xray.AddAnnotation(ctx1, "DDB.DescribeExistingTableAndPutToMissingTable.Annotation", "anno")
4557
if err != nil {
@@ -50,7 +62,7 @@ func ddbExpectedFailure(ctx context.Context, client *dynamodb.Client) error {
5062
return err
5163
}
5264

53-
_, err = client.DescribeTable(ctx1, &dynamodb.DescribeTableInput{
65+
_, err = dynamo.DescribeTable(ctx1, &dynamodb.DescribeTableInput{
5466
TableName: aws.String(existingTableName),
5567
})
5668
if err != nil {
@@ -67,7 +79,7 @@ func ddbExpectedFailure(ctx context.Context, client *dynamodb.Client) error {
6779
return err
6880
}
6981

70-
_, err = client.PutItem(ctx1, &dynamodb.PutItemInput{
82+
_, err = dynamo.PutItem(ctx1, &dynamodb.PutItemInput{
7183
TableName: aws.String(nonExistingTableName),
7284
Item: item,
7385
})

internal/aws/xray/tracesegment_test.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -11,7 +11,7 @@ import (
1111
"path/filepath"
1212
"testing"
1313

14-
"github.com/aws/aws-sdk-go/aws"
14+
"github.com/aws/aws-sdk-go-v2/aws"
1515
"github.com/stretchr/testify/assert"
1616
)
1717

receiver/awsxrayreceiver/go.mod

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,7 @@ module github.com/open-telemetry/opentelemetry-collector-contrib/receiver/awsxra
33
go 1.23.0
44

55
require (
6-
github.com/aws/aws-sdk-go v1.55.7
6+
github.com/aws/aws-sdk-go-v2 v1.36.3
77
github.com/aws/aws-sdk-go-v2/service/xray v1.31.4
88
github.com/google/go-cmp v0.7.0
99
github.com/google/uuid v1.6.0
@@ -33,7 +33,7 @@ require (
3333
)
3434

3535
require (
36-
github.com/aws/aws-sdk-go-v2 v1.36.3 // indirect
36+
github.com/aws/aws-sdk-go v1.55.7 // indirect
3737
github.com/aws/aws-sdk-go-v2/config v1.29.14 // indirect
3838
github.com/aws/aws-sdk-go-v2/credentials v1.17.67 // indirect
3939
github.com/aws/aws-sdk-go-v2/feature/ec2/imds v1.16.30 // indirect

receiver/awsxrayreceiver/internal/translator/aws_test.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,7 @@ package translator
66
import (
77
"testing"
88

9-
"github.com/aws/aws-sdk-go/aws"
9+
"github.com/aws/aws-sdk-go-v2/aws"
1010
"github.com/stretchr/testify/assert"
1111
"go.opentelemetry.io/collector/pdata/pcommon"
1212
conventions "go.opentelemetry.io/otel/semconv/v1.18.0"

receiver/awsxrayreceiver/internal/translator/cause_test.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,7 @@ package translator
66
import (
77
"testing"
88

9-
"github.com/aws/aws-sdk-go/aws"
9+
"github.com/aws/aws-sdk-go-v2/aws"
1010
"github.com/stretchr/testify/assert"
1111

1212
awsxray "github.com/open-telemetry/opentelemetry-collector-contrib/internal/aws/xray"

receiver/awsxrayreceiver/internal/translator/translator_test.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -11,8 +11,8 @@ import (
1111
"testing"
1212
"time"
1313

14+
"github.com/aws/aws-sdk-go-v2/aws"
1415
"github.com/aws/aws-sdk-go-v2/service/xray/types"
15-
"github.com/aws/aws-sdk-go/aws"
1616
"github.com/stretchr/testify/assert"
1717
"go.opentelemetry.io/collector/pdata/pcommon"
1818
"go.opentelemetry.io/collector/pdata/ptrace"

0 commit comments

Comments
 (0)