OpenTelemetry.Instrumentation.AWSLambda 1.12.1

Prefix Reserved
dotnet add package OpenTelemetry.Instrumentation.AWSLambda --version 1.12.1
                    
NuGet\Install-Package OpenTelemetry.Instrumentation.AWSLambda -Version 1.12.1
                    
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="OpenTelemetry.Instrumentation.AWSLambda" Version="1.12.1" />
                    
For projects that support PackageReference, copy this XML node into the project file to reference the package.
<PackageVersion Include="OpenTelemetry.Instrumentation.AWSLambda" Version="1.12.1" />
                    
Directory.Packages.props
<PackageReference Include="OpenTelemetry.Instrumentation.AWSLambda" />
                    
Project file
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 OpenTelemetry.Instrumentation.AWSLambda --version 1.12.1
                    
#r "nuget: OpenTelemetry.Instrumentation.AWSLambda, 1.12.1"
                    
#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 OpenTelemetry.Instrumentation.AWSLambda@1.12.1
                    
#: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=OpenTelemetry.Instrumentation.AWSLambda&version=1.12.1
                    
Install as a Cake Addin
#tool nuget:?package=OpenTelemetry.Instrumentation.AWSLambda&version=1.12.1
                    
Install as a Cake Tool

AWS OTel .NET SDK for Lambda

Status
Stability Stable
Code Owners @rypdal, @Oberon00, @normj

NuGet version badge NuGet download count badge codecov.io

This repo contains SDK to instrument Lambda handler to create incoming span.

Installation

dotnet add package OpenTelemetry.Instrumentation.AWSLambda

Configuration

Add AddAWSLambdaConfigurations() to TracerProvider.

TracerProvider tracerProvider = Sdk.CreateTracerProviderBuilder()
        // add other instrumentations
        .AddAWSLambdaConfigurations(options => options.DisableAwsXRayContextExtraction = true)
        .Build();

AWSLambdaInstrumentationOptions

AWSLambdaInstrumentationOptions contains various properties to configure AWS lambda instrumentation:

Instrumentation

AWSLambdaWrapper contains tracing methods covering different types of function handler method signatures. AWSLambdaWrapper.Trace() and AWSLambdaWrapper.TraceAsync() are used for wrapping synchronous and asynchronous function handlers respectively. The ActivityContext parentContext parameter is optional and used to pass a custom parent context. If the parent is not passed explicitly then it's either extracted from the input parameter or uses AWS X-Ray headers if AWS X-Ray context extraction is enabled (see configuration property DisableAwsXRayContextExtraction).

If tracing is required when AWS X-Ray is disabled, the DisableAwsXRayContextExtraction property needs to be set to true. This will instruct the instrumentation to ignore the "not sampled" trace header automatically sent when AWS X-Ray is disabled.

The sequence of the parent extraction: explicit parentparent from input parameterAWS X-Ray headersdefault The parent extraction is supported for the input types listed in the table below:

Type Parent extraction source
APIGatewayProxyRequest, APIGatewayHttpApiV2ProxyRequest, ApplicationLoadBalancerRequest HTTP headers of the request
SQSEvent Attributes of the last SQSMessage (if SetParentFromMessageBatch is true)
SNSEvent Attributes of the last SNSRecord

Lambda Function

  1. Create a wrapper function with the same signature as the original Lambda function but an added ILambdaContext parameter if it was not already present. Call AWSLambdaWrapper.Trace() or AWSLambdaWrapper.TraceAsync() API and pass TracerProvider, original Lambda function and its parameters.

  2. Set the wrapper function as the Lambda handler input.

// new Lambda function handler passed in
public string TracingFunctionHandler(JObject input, ILambdaContext context)
=> AWSLambdaWrapper.Trace(tracerProvider, OriginalFunctionHandler, input, context);

public string OriginalFunctionHandler(JObject input, ILambdaContext context)
{
    var S3Client = new AmazonS3Client();
    var httpClient = new HttpClient();
    _ = S3Client.ListBucketsAsync().Result;
    _ = httpClient.GetAsync("https://aws.amazon.com").Result;
    return input?.ToString();
}

Lambda Function - Asp.Net Core

For using base classes from package Amazon.Lambda.AspNetCoreServer, override the FunctionHandlerAsync function in LambdaEntryPoint.cs file. Call AWSLambdaWrapper.TraceAsync() API and pass TracerProvider, original Lambda function and its inputs as parameters. Below is an example if using APIGatewayProxyFunction as base class.

public override async Task<APIGatewayProxyResponse> FunctionHandlerAsync(
    APIGatewayProxyRequest request, ILambdaContext lambdaContext)
=> await AWSLambdaWrapper.TraceAsync(tracerProvider, base.FunctionHandlerAsync,
    request, lambdaContext);

Example

A more detailed Lambda function example that takes a JObject and ILambdaContext as inputs.

public class Function
{
    public static TracerProvider tracerProvider;

    static Function()
    {
        tracerProvider = Sdk.CreateTracerProviderBuilder()
                .AddHttpClientInstrumentation()
                .AddAWSInstrumentation()
                .AddOtlpExporter()
                .AddAWSLambdaConfigurations(options => options.DisableAwsXRayContextExtraction = true)
                .Build();
    }

    public string TracingFunctionHandler(JObject input, ILambdaContext context)
    => AWSLambdaWrapper.Trace(tracerProvider, FunctionHandler, input, context);

    /// <summary>
    /// A simple function that takes a JObject input and sends downstream http
    /// request to aws.amazon.com and aws request to S3.
    /// </summary>
    public string FunctionHandler(JObject input, ILambdaContext context)
    {
        var S3Client = new AmazonS3Client();
        var httpClient = new HttpClient();
        _ = S3Client.ListBucketsAsync().Result;
        _ = httpClient.GetAsync("https://aws.amazon.com").Result;
        return input?.ToString();
    }
}

Semantic Conventions

For an overview on Semantic Conventions, see Open Telemetery - Semantic Conventions.

While this library is intended for production use, it relies on several Semantic Conventions that are still considered Experimental, meaning they may undergo additional changes before becoming Stable. This can impact the aggregation and analysis of telemetry signals in environments with multiple applications or microservices.

For example, a microservice using an older version of the Semantic Conventions for Http Attributes may emit "http.method" with a value of GET, while a different microservice, using a new version of Semantic Convention may instead emit the GET as "http.request.method".

Future versions of OpenTelemetry.Instrumentation.AWSLambda library will include updates to the Semantic Convention, which may break compatibility with a previous version.

The default will remain as V1_28_0 until the next major version bump.

To opt in to automatic upgrades, you can use SemanticConventionVersion.Latest or you can specify a specific version:

 using (var tracerProvider = Sdk.CreateTracerProviderBuilder()
    .AddAWSLambdaConfigurations(opt =>
    {
        // pin to a specific Semantic Convention version
        opt.SemanticConventionVersion = SemanticConventionVersion.V1_29_0;
    })
    .Build()!);

NOTE: Once a Semantic Convention becomes Stable, OpenTelemetry.Instrumentation.AWSLambda will remain on that version until the next major version bump.

Reference

Product Compatible and additional computed target framework versions.
.NET net5.0 was computed.  net5.0-windows was computed.  net6.0 was computed.  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 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 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. 
.NET Core netcoreapp2.0 was computed.  netcoreapp2.1 was computed.  netcoreapp2.2 was computed.  netcoreapp3.0 was computed.  netcoreapp3.1 was computed. 
.NET Standard netstandard2.0 is compatible.  netstandard2.1 was computed. 
.NET Framework net461 was computed.  net462 was computed.  net463 was computed.  net47 was computed.  net471 was computed.  net472 was computed.  net48 was computed.  net481 was computed. 
MonoAndroid monoandroid was computed. 
MonoMac monomac was computed. 
MonoTouch monotouch was computed. 
Tizen tizen40 was computed.  tizen60 was computed. 
Xamarin.iOS xamarinios was computed. 
Xamarin.Mac xamarinmac was computed. 
Xamarin.TVOS xamarintvos was computed. 
Xamarin.WatchOS xamarinwatchos was computed. 
Compatible target framework(s)
Included target framework(s) (in package)
Learn more about Target Frameworks and .NET Standard.

NuGet packages (3)

Showing the top 3 NuGet packages that depend on OpenTelemetry.Instrumentation.AWSLambda:

Package Downloads
Grafana.OpenTelemetry

Full Grafana distribution of OpenTelemetry .NET

AWS.Distro.OpenTelemetry.AutoInstrumentation

Package Description

PaTh.AWSLambda.Tracing

Metalama Aspect which adds distributed tracing for AWS Lambda using OpenTelemetry and Dynatrace.

GitHub repositories (1)

Showing the top 1 popular GitHub repositories that depend on OpenTelemetry.Instrumentation.AWSLambda:

Repository Stars
aws/integrations-on-dotnet-aspire-for-aws
This repositry contains the integrations with .NET Aspire for AWS.
Version Downloads Last Updated
1.12.1 1,576 9/3/2025
1.12.0 130,373 5/6/2025
1.11.3 10,260 5/1/2025
1.11.2 91,019 3/18/2025
1.11.1 20,044 3/6/2025
1.11.0 79,412 1/29/2025
1.10.0-rc.2 6,232 1/15/2025
1.10.0-rc.1 4,564 1/6/2025
1.10.0-beta.3 5,005 12/20/2024
1.10.0-beta.2 1,996 12/12/2024
1.10.0-beta.1 285,195 11/23/2024
1.3.0-beta.1 1,022,112 1/26/2024
1.2.0-beta.1 438,001 8/7/2023
1.1.0-beta.3 73,681 6/13/2023
1.1.0-beta.2 329,437 9/14/2022