Skip to content

Commit b01f5f3

Browse files
[Instrumentation.AWS] Update to AWSSDK v4 (open-telemetry#2720)
1 parent 59dd1e4 commit b01f5f3

File tree

10 files changed

+79
-20
lines changed

10 files changed

+79
-20
lines changed

.github/workflows/ci.yml

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -210,6 +210,7 @@ jobs:
210210
with:
211211
project-name: OpenTelemetry.Instrumentation.AWS
212212
code-cov-name: Instrumentation.AWS
213+
tfm-list: '[ "net472", "net8.0", "net9.0" ]'
213214

214215
build-test-instrumentation-cassandra:
215216
needs: detect-changes

src/OpenTelemetry.Instrumentation.AWS/CHANGELOG.md

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,9 @@
22

33
## Unreleased
44

5+
* BREAKING: Update AWSSDK dependencies to v4.
6+
([#2720](https://github.com/open-telemetry/opentelemetry-dotnet-contrib/pull/2720))
7+
58
## 1.11.3
69

710
Released 2025-May-01

src/OpenTelemetry.Instrumentation.AWS/OpenTelemetry.Instrumentation.AWS.csproj

Lines changed: 9 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,9 @@
1-
<Project Sdk="Microsoft.NET.Sdk">
1+
<Project Sdk="Microsoft.NET.Sdk">
2+
3+
<!-- AWSSDK v4 does not support .NET Framework 4.6.2 -->
4+
<PropertyGroup>
5+
<NetFrameworkMinimumSupportedVersion>net472</NetFrameworkMinimumSupportedVersion>
6+
</PropertyGroup>
27

38
<PropertyGroup>
49
<!-- OmniSharp/VS Code requires TargetFrameworks to be in descending order for IntelliSense and analysis. -->
@@ -18,9 +23,9 @@
1823
</ItemGroup>
1924

2025
<ItemGroup>
21-
<PackageReference Include="AWSSDK.Core" Version="[3.7.400, 4.0.0)" />
22-
<PackageReference Include="AWSSDK.SimpleNotificationService" Version="[3.7.400, 4.0.0)" />
23-
<PackageReference Include="AWSSDK.SQS" Version="[3.7.400, 4.0.0)" />
26+
<PackageReference Include="AWSSDK.Core" Version="[4.0.0, 5.0.0)" />
27+
<PackageReference Include="AWSSDK.SimpleNotificationService" Version="[4.0.0, 5.0.0)" />
28+
<PackageReference Include="AWSSDK.SQS" Version="[4.0.0, 5.0.0)" />
2429
</ItemGroup>
2530

2631
<ItemGroup>

test/OpenTelemetry.Instrumentation.AWS.Tests/Implementation/RequestContextHelperTests.cs

Lines changed: 16 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -52,7 +52,10 @@ public void SQS_AddAttributes_MessageAttributes_TraceDataInjected()
5252
new("tracestate", "trace-state"),
5353
};
5454

55-
var originalRequest = new SQS.SendMessageRequest();
55+
var originalRequest = new SQS.SendMessageRequest()
56+
{
57+
MessageAttributes = [],
58+
};
5659

5760
var context = new TestRequestContext(originalRequest, new TestRequest());
5861

@@ -70,7 +73,10 @@ public void SNS_AddAttributes_MessageAttributes_TraceDataInjected()
7073
new("tracestate", "trace-state"),
7174
};
7275

73-
var originalRequest = new SNS.PublishRequest();
76+
var originalRequest = new SNS.PublishRequest()
77+
{
78+
MessageAttributes = [],
79+
};
7480

7581
var context = new TestRequestContext(originalRequest, new TestRequest());
7682

@@ -91,7 +97,10 @@ public void SQS_AddAttributes_MessageAttributesWithTraceParent_TraceStateNotInje
9197
new("traceparent", $"00-{TraceId}-{ParentId}-00"),
9298
};
9399

94-
var originalRequest = new SQS.SendMessageRequest();
100+
var originalRequest = new SQS.SendMessageRequest()
101+
{
102+
MessageAttributes = [],
103+
};
95104

96105
var context = new TestRequestContext(originalRequest, new TestRequest());
97106

@@ -112,7 +121,10 @@ public void SNS_AddAttributes_MessageAttributesWithTraceParent_TraceStateNotInje
112121
new("traceparent", $"00-{TraceId}-{ParentId}-00"),
113122
};
114123

115-
var originalRequest = new SNS.PublishRequest();
124+
var originalRequest = new SNS.PublishRequest()
125+
{
126+
MessageAttributes = [],
127+
};
116128

117129
var context = new TestRequestContext(originalRequest, new TestRequest());
118130

test/OpenTelemetry.Instrumentation.AWS.Tests/Implementation/TestsHelper.cs

Lines changed: 10 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -31,8 +31,14 @@ internal static class TestsHelper
3131
internal static AmazonWebServiceRequest CreateOriginalRequest(string serviceType, int attributesCount)
3232
{
3333
AmazonWebServiceRequest resultRequest;
34-
var sendRequest = new SQS::SendMessageRequest();
35-
var publishRequest = new SNS::PublishRequest();
34+
var sendRequest = new SQS::SendMessageRequest()
35+
{
36+
MessageAttributes = [],
37+
};
38+
var publishRequest = new SNS::PublishRequest()
39+
{
40+
MessageAttributes = [],
41+
};
3642
Action<int> addAttribute;
3743

3844
switch (serviceType)
@@ -101,6 +107,7 @@ internal static void AssertMessageParameters(List<KeyValuePair<string, string>>
101107
{
102108
foreach (var kvp in expectedParameters)
103109
{
110+
Assert.NotNull(request.MessageAttributes);
104111
Assert.True(request.MessageAttributes.ContainsKey(kvp.Key));
105112

106113
Assert.Equal(kvp.Value, request.MessageAttributes[kvp.Key].StringValue);
@@ -111,6 +118,7 @@ internal static void AssertMessageParameters(List<KeyValuePair<string, string>>
111118
{
112119
foreach (var kvp in expectedParameters)
113120
{
121+
Assert.NotNull(request.MessageAttributes);
114122
Assert.True(request.MessageAttributes.ContainsKey(kvp.Key));
115123

116124
Assert.Equal(kvp.Value, request.MessageAttributes[kvp.Key].StringValue);

test/OpenTelemetry.Instrumentation.AWS.Tests/OpenTelemetry.Instrumentation.AWS.Tests.csproj

Lines changed: 7 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1,19 +1,20 @@
11
<Project Sdk="Microsoft.NET.Sdk">
22

33
<PropertyGroup>
4+
<NetFrameworkMinimumSupportedVersion>net472</NetFrameworkMinimumSupportedVersion>
45
<!-- OmniSharp/VS Code requires TargetFrameworks to be in descending order for IntelliSense and analysis. -->
56
<TargetFrameworks>$(SupportedNetTargets)</TargetFrameworks>
67
<TargetFrameworks Condition="$(OS) == 'Windows_NT'">$(TargetFrameworks);$(NetFrameworkMinimumSupportedVersion)</TargetFrameworks>
78
<Description>Unit test project for AWS client instrumentation for OpenTelemetry.</Description>
89
</PropertyGroup>
910

1011
<ItemGroup>
11-
<PackageReference Include="AWSSDK.DynamoDBv2" Version="3.7.400" />
12-
<PackageReference Include="AWSSDK.S3" Version="3.7.400" />
13-
<PackageReference Include="AWSSDK.Bedrock" Version="3.7.400" />
14-
<PackageReference Include="AWSSDK.BedrockAgent" Version="3.7.400" />
15-
<PackageReference Include="AWSSDK.BedrockAgentRuntime" Version="3.7.400" />
16-
<PackageReference Include="AWSSDK.BedrockRuntime" Version="3.7.400" />
12+
<PackageReference Include="AWSSDK.DynamoDBv2" Version="4.0.0.2" />
13+
<PackageReference Include="AWSSDK.Bedrock" Version="4.0.0" />
14+
<PackageReference Include="AWSSDK.BedrockAgent" Version="4.0.0" />
15+
<PackageReference Include="AWSSDK.BedrockAgentRuntime" Version="4.0.0" />
16+
<PackageReference Include="AWSSDK.BedrockRuntime" Version="4.0.0" />
17+
<PackageReference Include="AWSSDK.S3" Version="4.0.0" />
1718
<PackageReference Include="OpenTelemetry.Exporter.InMemory" Version="$(OpenTelemetryCoreLatestVersion)" />
1819
</ItemGroup>
1920

test/OpenTelemetry.Instrumentation.AWS.Tests/TestAWSClientInstrumentation.cs

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -47,7 +47,7 @@ public async Task TestDDBScanSuccessful()
4747
.Build())
4848
{
4949
var ddb = new AmazonDynamoDBClient(new AnonymousAWSCredentials(), RegionEndpoint.USEast1);
50-
CustomResponses.SetResponse(ddb, null, requestId, true);
50+
CustomResponses.SetResponse(ddb, "{}", requestId, true);
5151
var scan_request = new ScanRequest
5252
{
5353
TableName = "SampleProduct",
@@ -95,7 +95,7 @@ public async Task TestDDBSubtypeScanSuccessful()
9595
.Build())
9696
{
9797
var ddb = new TestAmazonDynamoDBClient(new AnonymousAWSCredentials(), RegionEndpoint.USEast1);
98-
CustomResponses.SetResponse(ddb, null, requestId, true);
98+
CustomResponses.SetResponse(ddb, "{}", requestId, true);
9999
var scan_request = new ScanRequest
100100
{
101101
TableName = "SampleProduct",
@@ -214,6 +214,7 @@ public async Task TestSQSSendMessageSuccessfulSampled()
214214
{
215215
QueueUrl = "https://sqs.us-east-1.amazonaws.com/123456789/MyTestQueue",
216216
MessageBody = "Hello from OT",
217+
MessageAttributes = [],
217218
};
218219
send_msg_req.MessageAttributes.Add("Custom", new MessageAttributeValue { StringValue = "Value", DataType = "String" });
219220
#if NETFRAMEWORK
@@ -273,6 +274,7 @@ public async Task TestSQSSendMessageSuccessfulNotSampled()
273274
{
274275
QueueUrl = "https://sqs.us-east-1.amazonaws.com/123456789/MyTestQueue",
275276
MessageBody = "Hello from OT",
277+
MessageAttributes = [],
276278
};
277279
send_msg_req.MessageAttributes.Add("Custom", new MessageAttributeValue { StringValue = "Value", DataType = "String" });
278280
#if NETFRAMEWORK

test/OpenTelemetry.Instrumentation.AWS.Tests/TestRequest.cs

Lines changed: 9 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,7 @@
44
using Amazon;
55
using Amazon.Runtime;
66
using Amazon.Runtime.Endpoints;
7+
using Amazon.Runtime.EventStreams;
78
using Amazon.Runtime.Internal;
89
using Amazon.Runtime.Internal.Auth;
910
using Amazon.Runtime.Internal.Util;
@@ -69,8 +70,6 @@ public TestRequest(ParameterCollection? parameters = null)
6970

7071
public string CanonicalResourcePrefix { get => throw new NotImplementedException(); set => throw new NotImplementedException(); }
7172

72-
public bool UseSigV4 { get => throw new NotImplementedException(); set => throw new NotImplementedException(); }
73-
7473
public SignatureVersion SignatureVersion { get => throw new NotImplementedException(); set => throw new NotImplementedException(); }
7574

7675
public string AuthenticationRegion { get => throw new NotImplementedException(); set => throw new NotImplementedException(); }
@@ -89,6 +88,14 @@ public TestRequest(ParameterCollection? parameters = null)
8988

9089
public ChecksumData ChecksumData { get => throw new NotImplementedException(); set => throw new NotImplementedException(); }
9190

91+
public IEventStreamPublisher EventStreamPublisher { get => throw new NotImplementedException(); set => throw new NotImplementedException(); }
92+
93+
public IHttpRequestStreamPublisher HttpRequestStreamPublisher { get => throw new NotImplementedException(); set => throw new NotImplementedException(); }
94+
95+
public DateTime? SignedAt { get => throw new NotImplementedException(); set => throw new NotImplementedException(); }
96+
97+
public Version HttpProtocolVersion { get => throw new NotImplementedException(); set => throw new NotImplementedException(); }
98+
9299
public void AddPathResource(string key, string value)
93100
{
94101
throw new NotImplementedException();

test/OpenTelemetry.Instrumentation.AWS.Tests/TestRequestContext.cs

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2,9 +2,11 @@
22
// SPDX-License-Identifier: Apache-2.0
33

44
using Amazon.Runtime;
5+
using Amazon.Runtime.Identity;
56
using Amazon.Runtime.Internal;
67
using Amazon.Runtime.Internal.Auth;
78
using Amazon.Runtime.Internal.Transform;
9+
using Amazon.Runtime.Internal.UserAgent;
810
using Amazon.Runtime.Internal.Util;
911

1012
namespace OpenTelemetry.Instrumentation.AWS.Tests;
@@ -58,4 +60,12 @@ internal class TestRequestContext(AmazonWebServiceRequest originalRequest, IRequ
5860
public Guid InvocationId => throw new NotImplementedException();
5961

6062
public IDictionary<string, object> ContextAttributes { get; } = new Dictionary<string, object>();
63+
64+
public BaseIdentity Identity { get => throw new NotImplementedException(); set => throw new NotImplementedException(); }
65+
66+
public IHttpRequestStreamHandle RequestStreamHandle { get => throw new NotImplementedException(); set => throw new NotImplementedException(); }
67+
68+
public UserAgentDetails UserAgentDetails => throw new NotImplementedException();
69+
70+
ISigner IRequestContext.Signer { get => this.Signer; set => throw new NotImplementedException(); }
6171
}

test/OpenTelemetry.Instrumentation.AWS.Tests/Tools/MockHttpRequest.cs

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -18,6 +18,7 @@ public MockHttpRequest(Uri requestUri, Action? action, Func<MockHttpRequest, Htt
1818
this.RequestUri = requestUri;
1919
this.GetResponseAction = action;
2020
this.ResponseCreator = responseCreator ?? this.CreateResponse;
21+
this.HttpProtocolVersion = HttpVersion.Version11;
2122
}
2223

2324
public bool IsDisposed { get; set; }
@@ -38,6 +39,8 @@ public MockHttpRequest(Uri requestUri, Action? action, Func<MockHttpRequest, Htt
3839

3940
public Func<MockHttpRequest, HttpWebResponse?> ResponseCreator { get; set; }
4041

42+
public Version HttpProtocolVersion { get; set; }
43+
4144
public void ConfigureRequest(IRequestContext requestContext)
4245
{
4346
this.IsConfigureRequestCalled = true;
@@ -115,6 +118,8 @@ Task IHttpRequest<Stream>.WriteToRequestBodyAsync(Stream requestContent, byte[]
115118
throw new NotImplementedException();
116119
}
117120

121+
public IHttpRequestStreamHandle SetupHttpRequestStreamPublisher(IDictionary<string, string> contentHeaders, IHttpRequestStreamPublisher publisher) => throw new NotImplementedException();
122+
118123
private HttpWebResponse CreateResponse(MockHttpRequest request)
119124
{
120125
var resourceName = request.RequestUri.Host.Split('.').Last();
@@ -133,6 +138,7 @@ public MockHttpRequest(Uri requestUri, Action? action, Func<MockHttpRequest, Htt
133138
this.RequestUri = requestUri;
134139
this.GetResponseAction = action;
135140
this.ResponseCreator = responseCreator ?? this.CreateResponse;
141+
this.HttpProtocolVersion = HttpVersion.Version11;
136142
}
137143

138144
public bool IsDisposed { get; set; }
@@ -153,6 +159,8 @@ public MockHttpRequest(Uri requestUri, Action? action, Func<MockHttpRequest, Htt
153159

154160
public Func<MockHttpRequest, HttpResponseMessage> ResponseCreator { get; set; }
155161

162+
public Version HttpProtocolVersion { get; set; }
163+
156164
public void Abort()
157165
{
158166
this.IsAborted = true;
@@ -206,6 +214,8 @@ public void SetRequestHeaders(IDictionary<string, string> headers)
206214
this.IsSetRequestHeadersCalled = true;
207215
}
208216

217+
public IHttpRequestStreamHandle SetupHttpRequestStreamPublisher(IDictionary<string, string> contentHeaders, IHttpRequestStreamPublisher publisher) => throw new NotImplementedException();
218+
209219
public Stream SetupProgressListeners(Stream originalStream, long progressUpdateInterval, object sender, EventHandler<StreamTransferProgressArgs> callback)
210220
{
211221
return originalStream;

0 commit comments

Comments
 (0)