AWS.Lambda.Powertools.Tracing
3.3.0
Prefix Reserved
dotnet add package AWS.Lambda.Powertools.Tracing --version 3.3.0
NuGet\Install-Package AWS.Lambda.Powertools.Tracing -Version 3.3.0
This command is intended to be used within the Package Manager Console in Visual Studio, as it uses the NuGet module's version of Install-Package.
<PackageReference Include="AWS.Lambda.Powertools.Tracing" Version="3.3.0" />
For projects that support PackageReference, copy this XML node into the project file to reference the package.
<PackageVersion Include="AWS.Lambda.Powertools.Tracing" Version="3.3.0" />
<PackageReference Include="AWS.Lambda.Powertools.Tracing" />
For projects that support Central Package Management (CPM), copy this XML node into the solution Directory.Packages.props file to version the package.
paket add AWS.Lambda.Powertools.Tracing --version 3.3.0
The NuGet Team does not provide support for this client. Please contact its maintainers for support.
#r "nuget: AWS.Lambda.Powertools.Tracing, 3.3.0"
#r directive can be used in F# Interactive and Polyglot Notebooks. Copy this into the interactive tool or source code of the script to reference the package.
#:package AWS.Lambda.Powertools.Tracing@3.3.0
#:package directive can be used in C# file-based apps starting in .NET 10 preview 4. Copy this into a .cs file before any lines of code to reference the package.
#addin nuget:?package=AWS.Lambda.Powertools.Tracing&version=3.3.0
#tool nuget:?package=AWS.Lambda.Powertools.Tracing&version=3.3.0
The NuGet Team does not provide support for this client. Please contact its maintainers for support.
AWS.Lambda.Powertools.Tracing
Powertools for AWS Lambda (.NET) tracing is an opinionated thin wrapper for AWS X-Ray .NET SDK a provides functionality to reduce the overhead of performing common tracing tasks.
Key Features
- Helper methods to improve the developer experience for creating custom AWS X-Ray subsegments.
- Capture cold start as annotation.
- Capture function responses and full exceptions as metadata.
- Better experience when developing with multiple threads.
- Auto-patch supported modules by AWS X-Ray
Read the docs
For a full list of features go to docs.aws.amazon.com/powertools/dotnet/core/tracing/
GitHub: https://github.com/aws-powertools/powertools-lambda-dotnet/
Sample Function
public class Function
{
/// <summary>
/// Lambda Handler
/// </summary>
/// <param name="apigwProxyEvent">API Gateway Proxy event</param>
/// <param name="context">AWS Lambda context</param>
/// <returns>API Gateway Proxy response</returns>
[Logging(LogEvent = true)]
[Tracing(CaptureMode = TracingCaptureMode.ResponseAndError)]
public async Task<APIGatewayProxyResponse> FunctionHandler(APIGatewayProxyRequest apigwProxyEvent,
ILambdaContext context)
{
var requestContextRequestId = apigwProxyEvent.RequestContext.RequestId;
Logger.LogInformation("Getting ip address from external service");
var location = await GetCallingIp().ConfigureAwait(false);
var lookupRecord = new LookupRecord(lookupId: requestContextRequestId,
greeting: "Hello Powertools for AWS Lambda (.NET)", ipAddress: location);
// Trace Fluent API
Tracing.WithSubsegment("LoggingResponse",
subsegment =>
{
subsegment.AddAnnotation("AccountId", apigwProxyEvent.RequestContext.AccountId);
subsegment.AddMetadata("LookupRecord", lookupRecord);
});
try
{
await SaveRecordInDynamo(lookupRecord);
return new APIGatewayProxyResponse
{
Body = JsonSerializer.Serialize(lookupRecord),
StatusCode = 200,
Headers = new Dictionary<string, string> { { "Content-Type", "application/json" } }
};
}
catch (Exception e)
{
Logger.LogError(e.Message);
return new APIGatewayProxyResponse
{
Body = e.Message,
StatusCode = 500,
Headers = new Dictionary<string, string> { { "Content-Type", "application/json" } }
};
}
}
/// <summary>
/// Calls location api to return IP address
/// </summary>
/// <returns>IP address string</returns>
[Tracing(SegmentName = "Location service")]
private static async Task<string?> GetCallingIp()
{
if (_httpClient == null) return "0.0.0.0";
_httpClient.DefaultRequestHeaders.Accept.Clear();
_httpClient.DefaultRequestHeaders.Add("User-Agent", "AWS Lambda .Net Client");
try
{
Logger.LogInformation("Calling Check IP API");
var response = await _httpClient.GetStringAsync("https://checkip.amazonaws.com/").ConfigureAwait(false);
var ip = response.Replace("\n", "");
Logger.LogInformation($"API response returned {ip}");
return ip;
}
catch (Exception ex)
{
Logger.LogError(ex);
throw;
}
}
/// <summary>
/// Saves the lookup record in DynamoDB
/// </summary>
/// <param name="lookupRecord">Instance of LookupRecord</param>
/// <returns>A Task that can be used to poll or wait for results, or both.</returns>
[Tracing(SegmentName = "DynamoDB")]
private static async Task SaveRecordInDynamo(LookupRecord lookupRecord)
{
try
{
Logger.LogInformation($"Saving record with id {lookupRecord.LookupId}");
await _dynamoDbContext?.SaveAsync(lookupRecord)!;
}
catch (AmazonDynamoDBException e)
{
Logger.LogCritical(e.Message);
throw;
}
}
}
Sample output
| Product | Versions Compatible and additional computed target framework versions. |
|---|---|
| .NET | net8.0 is compatible. net8.0-android was computed. net8.0-browser was computed. net8.0-ios was computed. net8.0-maccatalyst was computed. net8.0-macos was computed. net8.0-tvos was computed. net8.0-windows was computed. net9.0 was computed. net9.0-android was computed. net9.0-browser was computed. net9.0-ios was computed. net9.0-maccatalyst was computed. net9.0-macos was computed. net9.0-tvos was computed. net9.0-windows was computed. net10.0 is compatible. net10.0-android was computed. net10.0-browser was computed. net10.0-ios was computed. net10.0-maccatalyst was computed. net10.0-macos was computed. net10.0-tvos was computed. net10.0-windows was computed. |
Compatible target framework(s)
Included target framework(s) (in package)
Learn more about Target Frameworks and .NET Standard.
-
net10.0
- Amazon.Lambda.Core (>= 2.8.0)
- Amazon.Lambda.Serialization.SystemTextJson (>= 2.4.4)
- AspectInjector (>= 2.8.1)
- AWSSDK.XRay (>= 4.0.3.7)
- AWSXRayRecorder.Core (>= 2.15.0)
- AWSXRayRecorder.Handlers.AwsSdk (>= 2.13.0)
-
net8.0
- Amazon.Lambda.Core (>= 2.8.0)
- Amazon.Lambda.Serialization.SystemTextJson (>= 2.4.4)
- AspectInjector (>= 2.8.1)
- AWSSDK.XRay (>= 4.0.3.7)
- AWSXRayRecorder.Core (>= 2.15.0)
- AWSXRayRecorder.Handlers.AwsSdk (>= 2.13.0)
NuGet packages (1)
Showing the top 1 NuGet packages that depend on AWS.Lambda.Powertools.Tracing:
| Package | Downloads |
|---|---|
|
Lambifast
Package Description |
GitHub repositories (2)
Showing the top 2 popular GitHub repositories that depend on AWS.Lambda.Powertools.Tracing:
| Repository | Stars |
|---|---|
|
aws/aws-lambda-dotnet
Libraries, samples and tools to help .NET Core developers develop AWS Lambda functions.
|
|
|
aws-samples/serverless-dotnet-demo
|
| Version | Downloads | Last Updated |
|---|---|---|
| 3.3.0 | 3,161 | 11/25/2026 |
| 3.2.2 | 77,329 | 5/25/2026 |
| 3.2.1 | 76,224 | 3/19/2026 |
| 3.2.0 | 18,358 | 3/12/2026 |
| 3.1.0 | 32,825 | 1/6/2026 |
| 3.0.2 | 35,756 | 11/5/2025 |
| 3.0.1 | 12,674 | 10/21/2025 |
| 3.0.1-alpha | 254 | 10/15/2025 |
| 3.0.0 | 10,393 | 10/8/2025 |
| 1.6.1 | 214,782 | 2/11/2025 |
| 1.6.0 | 120,080 | 11/12/2024 |
| 1.5.2 | 288,510 | 10/8/2024 |
| 1.5.1 | 41,836 | 8/29/2024 |
| 1.5.0 | 18,674 | 7/25/2024 |
| 1.4.2 | 156,487 | 3/21/2024 |
| 1.4.1 | 44,589 | 3/10/2024 |
| 1.4.0 | 30,293 | 2/16/2024 |
| 1.3.2 | 115,125 | 9/19/2023 |
Loading failed