AWS.Lambda.Powertools.Tracing
                               
                            
                                0.0.2-preview
                            
                        
                            
                                
                                
                                    Prefix Reserved
                                
                            
                    See the version list below for details.
dotnet add package AWS.Lambda.Powertools.Tracing --version 0.0.2-preview
NuGet\Install-Package AWS.Lambda.Powertools.Tracing -Version 0.0.2-preview
<PackageReference Include="AWS.Lambda.Powertools.Tracing" Version="0.0.2-preview" />
<PackageVersion Include="AWS.Lambda.Powertools.Tracing" Version="0.0.2-preview" />
<PackageReference Include="AWS.Lambda.Powertools.Tracing" />
paket add AWS.Lambda.Powertools.Tracing --version 0.0.2-preview
#r "nuget: AWS.Lambda.Powertools.Tracing, 0.0.2-preview"
#:package AWS.Lambda.Powertools.Tracing@0.0.2-preview
#addin nuget:?package=AWS.Lambda.Powertools.Tracing&version=0.0.2-preview&prerelease
#tool nuget:?package=AWS.Lambda.Powertools.Tracing&version=0.0.2-preview&prerelease
AWS.Lambda.Powertools.Tracing
Powertools 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 awslabs.github.io/aws-lambda-powertools-dotnet/core/tracing/
GitHub: https://github.com/awslabs/aws-lambda-powertools-dotnet/
Sample Function
View the full example here: https://github.com/awslabs/aws-lambda-powertools-dotnet/tree/develop/examples/Tracing
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 AWS Lambda Powertools for .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 | net6.0 is compatible. net6.0-android was computed. net6.0-ios was computed. net6.0-maccatalyst was computed. net6.0-macos was computed. net6.0-tvos was computed. net6.0-windows was computed. net7.0 was computed. net7.0-android was computed. net7.0-ios was computed. net7.0-maccatalyst was computed. net7.0-macos was computed. net7.0-tvos was computed. net7.0-windows was computed. net8.0 was computed. 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 was computed. 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. | 
- 
                                                    net6.0- AWS.Lambda.Powertools.Common (>= 0.0.2-preview)
- AWSSDK.XRay (>= 3.7.102.25)
- AWSXRayRecorder.Core (>= 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 (4)
Showing the top 4 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-test-samples 
                                                            This repository is designed to provide guidance for implementing comprehensive test suites for serverless applications.
                                                         | |
| aws-powertools/powertools-lambda-dotnet 
                                                            Powertools is a developer toolkit to implement Serverless best practices and increase developer velocity.
                                                         | |
| aws-samples/serverless-dotnet-demo | 
| Version | Downloads | Last Updated | 
|---|---|---|
| 3.0.1 | 550 | 10/21/2025 | 
| 3.0.1-alpha | 157 | 10/15/2025 | 
| 3.0.0 | 943 | 10/8/2025 | 
| 1.6.1 | 77,226 | 2/11/2025 | 
| 1.6.0 | 69,057 | 11/12/2024 | 
| 1.5.2 | 213,505 | 10/8/2024 | 
| 1.5.1 | 33,279 | 8/29/2024 | 
| 1.5.0 | 16,575 | 7/25/2024 | 
| 1.4.2 | 121,182 | 3/21/2024 | 
| 1.4.1 | 34,583 | 3/10/2024 | 
| 1.4.0 | 25,540 | 2/16/2024 | 
| 1.3.2 | 94,325 | 9/19/2023 | 
| 1.2.0 | 17,264 | 9/7/2023 | 
| 1.1.2 | 12,393 | 8/22/2023 | 
| 1.1.1 | 28,128 | 6/21/2023 | 
| 1.1.0 | 22,585 | 5/5/2023 | 
| 1.0.1 | 16,321 | 4/6/2023 | 
| 1.0.0 | 5,187 | 2/24/2023 | 
| 0.0.2-preview | 351 | 1/18/2023 | 
| 0.0.1-preview.1 | 4,120 | 8/1/2022 |