![]() |
VOOZH | about |
This package has been renamed to MinimalLambda.OpenTelemetry. Please migrate to the new package: MinimalLambda.OpenTelemetry
dotnet add package AwsLambda.Host.OpenTelemetry --version 1.3.1
NuGet\Install-Package AwsLambda.Host.OpenTelemetry -Version 1.3.1
<PackageReference Include="AwsLambda.Host.OpenTelemetry" Version="1.3.1" />
<PackageVersion Include="AwsLambda.Host.OpenTelemetry" Version="1.3.1" />Directory.Packages.props
<PackageReference Include="AwsLambda.Host.OpenTelemetry" />Project file
paket add AwsLambda.Host.OpenTelemetry --version 1.3.1
#r "nuget: AwsLambda.Host.OpenTelemetry, 1.3.1"
#:package AwsLambda.Host.OpenTelemetry@1.3.1
#addin nuget:?package=AwsLambda.Host.OpenTelemetry&version=1.3.1Install as a Cake Addin
#tool nuget:?package=AwsLambda.Host.OpenTelemetry&version=1.3.1Install as a Cake Tool
OpenTelemetry integration for distributed tracing and observability in AWS Lambda functions.
An extension package for the framework that provides comprehensive observability integration. This package enables:
Requires AwsLambda.Host β this package extends that framework and cannot be used standalone. Configure exporters to send traces and metrics to your observability backend (e.g., Datadog, New Relic, Jaeger, CloudWatch).
This package requires to be installed and working in your project. It is an extension package and cannot function standalone.
First, install the core framework:
dotnet add package AwsLambda.Host
Then install this OpenTelemetry extension:
dotnet add package AwsLambda.Host.OpenTelemetry
Ensure your project uses C# 11 or later:
<PropertyGroup>
<LangVersion>11</LangVersion>
</PropertyGroup>
You'll also need additional OpenTelemetry packages depending on your use case:
dotnet add package OpenTelemetry
dotnet add package OpenTelemetry.Exporter.OpenTelemetryProtocol
Additional packages may include exporters (e.g., Jaeger, Datadog, AWS X-Ray), instrumentation libraries (e.g., for HTTP, database calls), and other extensions. See the AWS OTel Lambda .NET guide and OpenTelemetry.io .NET documentation for your specific observability backend and instrumentation needs.
Set up OpenTelemetry with the AWS Lambda instrumentation:
using AwsLambda.Host.Builder;
using Microsoft.Extensions.DependencyInjection;
using Microsoft.Extensions.Hosting;
using OpenTelemetry.Instrumentation.AWSLambda;
using OpenTelemetry.Resources;
using OpenTelemetry.Trace;
var builder = LambdaApplication.CreateBuilder();
// Configure OpenTelemetry with tracing
builder
.Services.AddOpenTelemetry()
.WithTracing(configure =>
configure
.AddAWSLambdaConfigurations()
.SetResourceBuilder(
ResourceBuilder.CreateDefault().AddService("MyLambda", serviceVersion: "1.0.0")
)
.AddOtlpExporter(options =>
{
options.Endpoint = new Uri("http://localhost:4317");
})
);
var lambda = builder.Build();
// Enable automatic tracing for Lambda invocations
lambda.UseOpenTelemetryTracing();
lambda.MapHandler(([Event] string input) => $"Hello {input}!");
// Flush traces on Lambda shutdown
lambda.OnShutdownFlushTracer();
await lambda.RunAsync();
ActivitySource to create spans for your business logicWhen you call UseOpenTelemetryTracing(), the framework uses source generators and compile-time
interceptors to inject tracing middleware into your handler pipeline. This middleware delegates to
the OpenTelemetry.Instrumentation.AWSLambda
wrapper functions to create root spans for each Lambda invocation. These root spans capture
AWS Lambda context (request IDs, function name, etc.) and measure the entire invocation duration.
How it works:
TracerProvider from the dependency injection containerTracerProvider to create the root spanThis happens at compile time with zero runtime reflection overhead. The actual span creation is delegated to the AWS Lambda OpenTelemetry instrumentation package.
A TracerProvider must be registered in the dependency injection container
before calling UseOpenTelemetryTracing(). If it's missing, an InvalidOperationException is
thrown at startup. See the Quick Start section above for configuration details.
This package creates the root invocation span automatically via the AWS instrumentation.
If you want to instrument specific handlers, functions, or business logic within your Lambda, you
create and manage those spans yourself using a custom ActivitySource (see below).
To add traces for specific operations within your handler (database queries, API calls, business
logic), create a custom ActivitySource. See the
OpenTelemetry.io guide on setting up an ActivitySource
for detailed information.
using System.Diagnostics;
internal class Instrumentation : IDisposable
{
public const string ActivitySourceName = "MyLambda";
public const string ActivitySourceVersion = "1.0.0";
public ActivitySource ActivitySource { get; } =
new(ActivitySourceName, ActivitySourceVersion);
public void Dispose() => ActivitySource.Dispose();
}
Register it with the TracerProvider and inject it into your handler:
builder.Services.AddSingleton<Instrumentation>();
var lambda = builder.Build();
// In your handler:
lambda.MapHandler(([Event] Request request, Instrumentation instrumentation) =>
{
using var activity = instrumentation.ActivitySource.StartActivity("ProcessRequest");
activity?.SetAttribute("request.name", request.Name);
return ProcessRequest(request);
});
Custom spans created with your ActivitySource automatically link to the root Lambda invocation
span, creating a complete trace of your function's execution. This is your responsibilityβthis
package only provides the root invocation span.
Ensure all traces and metrics are exported before Lambda terminates:
lambda.OnShutdownFlushOpenTelemetry();
This registers shutdown handlers that force flush both the TracerProvider and MeterProvider
with a configurable timeout (default: infinite):
lambda.OnShutdownFlushOpenTelemetry(timeoutMilliseconds: 5000);
You can also flush individually:
lambda.OnShutdownFlushTracer();
lambda.OnShutdownFlushMeter();
A complete, runnable example with Docker Compose setup is available in .
The example demonstrates:
AWS OTel Lambda Guide β Official AWS documentation for OpenTelemetry on Lambda with .NET
OpenTelemetry.io β OpenTelemetry specification, APIs, and best practices
OpenTelemetry Instrumentation AWSLambda β Source for the AWSLambda instrumentation
Full Project Documentation β Comprehensive guides and patterns
Additional packages in the aws-lambda-host framework for abstractions, observability, and event source handling.
This project is licensed under the MIT License. See for details.
| Product | Versions Compatible and additional computed target framework versions. |
|---|---|
| .NET | net9.0 net9.0 is compatible. net9.0-android net9.0-android was computed. net9.0-browser net9.0-browser was computed. net9.0-ios net9.0-ios was computed. net9.0-maccatalyst net9.0-maccatalyst was computed. net9.0-macos net9.0-macos was computed. net9.0-tvos net9.0-tvos was computed. net9.0-windows net9.0-windows was computed. net10.0 net10.0 is compatible. net10.0-android net10.0-android was computed. net10.0-browser net10.0-browser was computed. net10.0-ios net10.0-ios was computed. net10.0-maccatalyst net10.0-maccatalyst was computed. net10.0-macos net10.0-macos was computed. net10.0-tvos net10.0-tvos was computed. net10.0-windows net10.0-windows was computed. |
This package is not used by any NuGet packages.
This package is not used by any popular GitHub repositories.
| Version | Downloads | Last Updated |
|---|