Skip to content

Commit a8e8fb4

Browse files
Verify AWS instrumentation in OATS
Extend the OATS tests to assert on AWS SDK traces using LocalStack.
1 parent 2fb4db6 commit a8e8fb4

File tree

8 files changed

+80
-0
lines changed

8 files changed

+80
-0
lines changed

.github/renovate.json

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -42,6 +42,17 @@
4242
"matchCurrentValue": "^\\[[^,]+,\\)$",
4343
"enabled": false
4444
},
45+
{
46+
"extends": ["monorepo:aws-sdk-net"],
47+
"description": ["Only update the AWS SDK once a week"],
48+
"schedule": ["* 5-21 * * MON"]
49+
},
50+
{
51+
"extends": ["monorepo:aws-sdk-net"],
52+
"description": ["Disable major version updates for the AWS SDK"],
53+
"matchUpdateTypes": ["major"],
54+
"enabled": false
55+
},
4556
{
4657
"extends": ["monorepo:dotnet"],
4758
"description": "Disable major version updates for .NET",

docker/docker-compose-aspnetcore/docker-compose.oats.yml

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,10 @@ services:
55
context: ../..
66
dockerfile: examples/net8.0/aspnetcore/Dockerfile
77
environment:
8+
- AWS_ACCESS_KEY_ID=localstack
9+
- AWS_SECRET_ACCESS_KEY=localstack
10+
- AWS_REGION=us-east-1
11+
- AWS_ENDPOINT_URL_S3=http://localstack:4566
812
- OTEL_EXPORTER_OTLP_ENDPOINT=http://lgtm:4317
913
ports:
1014
- "5000:8080"
@@ -28,3 +32,8 @@ services:
2832
environment:
2933
- ACCEPT_EULA=Y
3034
- MSSQL_SA_PASSWORD=Password12345%%
35+
localstack:
36+
image: localstack/localstack:4.5.0@sha256:9d4253786e0effe974d77fe3c390358391a56090a4fff83b4600d8a64404d95d
37+
ports:
38+
- "4510-4559:4510-4559"
39+
- "4566:4566"

docker/docker-compose-aspnetcore/docker-compose.self-contained.oats.yml

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,10 @@ services:
88
DOTNET_PUBLISH_ARGS: "--self-contained true /p:PublishSingleFile=true"
99
entrypoint: ./aspnetcore
1010
environment:
11+
- AWS_ACCESS_KEY_ID=localstack
12+
- AWS_SECRET_ACCESS_KEY=localstack
13+
- AWS_REGION=us-east-1
14+
- AWS_ENDPOINT_URL_S3=http://localstack:4566
1115
- OTEL_EXPORTER_OTLP_ENDPOINT=http://lgtm:4317
1216
ports:
1317
- "5000:8080"
@@ -31,3 +35,8 @@ services:
3135
environment:
3236
- ACCEPT_EULA=Y
3337
- MSSQL_SA_PASSWORD=Password12345%%
38+
localstack:
39+
image: localstack/localstack:4.5.0@sha256:9d4253786e0effe974d77fe3c390358391a56090a4fff83b4600d8a64404d95d
40+
ports:
41+
- "4510-4559:4510-4559"
42+
- "4566:4566"

docker/docker-compose-aspnetcore/docker-compose.yml

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -9,6 +9,11 @@ services:
99
- mssql
1010
ports:
1111
- "8080:8080" # for OATs
12+
environment:
13+
- AWS_ACCESS_KEY_ID=localstack
14+
- AWS_SECRET_ACCESS_KEY=localstack
15+
- AWS_REGION=us-east-1
16+
- AWS_ENDPOINT_URL_S3=http://localstack:4566
1217
redis:
1318
image: redis:8.0@sha256:1b835e5a8d5db58e8b718850bf43a68ef5a576fc68301fd08a789b20b4eecb61
1419
ports:
@@ -20,3 +25,8 @@ services:
2025
environment:
2126
- ACCEPT_EULA=Y
2227
- MSSQL_SA_PASSWORD=Password12345%%
28+
localstack:
29+
image: localstack/localstack:4.5.0@sha256:9d4253786e0effe974d77fe3c390358391a56090a4fff83b4600d8a64404d95d
30+
ports:
31+
- "4510-4559:4510-4559"
32+
- "4566:4566"

docker/docker-compose-aspnetcore/oats.yaml

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,7 @@
11
include:
22
- ./oats-template.yml
33
input:
4+
- path: /api/Aws/ListFiles
45
- path: /api/HttpClient/Get
56
- path: /api/HttpClient/GetError
67
- path: /api/MsSql/ServerInfo
@@ -80,3 +81,12 @@ expected:
8081
db.name: main
8182
peer.service: /app/App_Data/TodoApp.db
8283
otel.library.name: OpenTelemetry.Instrumentation.EntityFrameworkCore
84+
- traceql: '{ span.http.route =~ "api/Aws/ListBuckets" }'
85+
spans:
86+
- name: 'S3.ListBuckets'
87+
attributes:
88+
aws.request_id: regex:.+
89+
otel.library.name: AWSSDK.S3
90+
rpc.method: ListBuckets
91+
rpc.service: S3
92+
rpc.system: aws-api
Lines changed: 26 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,26 @@
1+
//
2+
// Copyright Grafana Labs
3+
// SPDX-License-Identifier: Apache-2.0
4+
//
5+
6+
using Amazon.S3;
7+
using Microsoft.AspNetCore.Mvc;
8+
9+
namespace aspnetcore.Controllers;
10+
11+
[Route("api/[controller]/[action]")]
12+
[ApiController]
13+
public class AwsController(AmazonS3Client client, ILogger<AwsController> logger) : ControllerBase
14+
{
15+
[HttpGet]
16+
public async Task<ActionResult<string[]>> ListBuckets()
17+
{
18+
var response = await client.ListBucketsAsync();
19+
20+
var buckets = response.Buckets.Select(o => o.BucketName).ToArray();
21+
22+
logger.LogInformation("Found {Count} buckets.", buckets);
23+
24+
return this.Ok(buckets);
25+
}
26+
}

examples/net8.0/aspnetcore/Program.cs

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,7 @@
33
// SPDX-License-Identifier: Apache-2.0
44
//
55

6+
using Amazon.S3;
67
using aspnetcore;
78
using Grafana.OpenTelemetry;
89
using Microsoft.Data.SqlClient;
@@ -29,6 +30,9 @@
2930
return new SqlConnection(connectionString);
3031
});
3132

33+
// AWS SDKs
34+
builder.Services.AddSingleton((_) => new AmazonS3Client(new AmazonS3Config() { ForcePathStyle = true }));
35+
3236
builder.Services.AddHttpClient();
3337

3438
builder.Services.AddControllers();

examples/net8.0/aspnetcore/aspnetcore.csproj

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -10,6 +10,7 @@
1010
</PropertyGroup>
1111

1212
<ItemGroup>
13+
<PackageReference Include="AWSSDK.S3" Version="3.7.418.2" />
1314
<PackageReference Include="Microsoft.Data.SqlClient" Version="6.0.2" />
1415
<PackageReference Include="Microsoft.EntityFrameworkCore.Sqlite" Version="8.0.17" />
1516
<PackageReference Include="Microsoft.VisualStudio.Azure.Containers.Tools.Targets" Version="1.20.1" />

0 commit comments

Comments
 (0)