VOOZH about

URL: https://www.nuget.org/packages/AwsLambda.Host.OpenTelemetry

⇱ NuGet Gallery | AwsLambda.Host.OpenTelemetry 1.3.1


ο»Ώ

AwsLambda.Host.OpenTelemetry 1.3.1

Suggested Alternatives

MinimalLambda.OpenTelemetry

Additional Details

This package has been renamed to MinimalLambda.OpenTelemetry. Please migrate to the new package: MinimalLambda.OpenTelemetry

The owner has unlisted this package. This could mean that the package is deprecated, has security vulnerabilities or shouldn't be used anymore.
dotnet add package AwsLambda.Host.OpenTelemetry --version 1.3.1
 
 
NuGet\Install-Package AwsLambda.Host.OpenTelemetry -Version 1.3.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="AwsLambda.Host.OpenTelemetry" Version="1.3.1" />
 
 
For projects that support PackageReference, copy this XML node into the project file to reference the package.
<PackageVersion Include="AwsLambda.Host.OpenTelemetry" Version="1.3.1" />
 
Directory.Packages.props
<PackageReference Include="AwsLambda.Host.OpenTelemetry" />
 
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 AwsLambda.Host.OpenTelemetry --version 1.3.1
 
 
The NuGet Team does not provide support for this client. Please contact its maintainers for support.
#r "nuget: AwsLambda.Host.OpenTelemetry, 1.3.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 AwsLambda.Host.OpenTelemetry@1.3.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=AwsLambda.Host.OpenTelemetry&version=1.3.1
 
Install as a Cake Addin
#tool nuget:?package=AwsLambda.Host.OpenTelemetry&version=1.3.1
 
Install as a Cake Tool
The NuGet Team does not provide support for this client. Please contact its maintainers for support.

AwsLambda.Host.OpenTelemetry

OpenTelemetry integration for distributed tracing and observability in AWS Lambda functions.

πŸ“š View Full Documentation

Overview

An extension package for the framework that provides comprehensive observability integration. This package enables:

  • Distributed Tracing: Automatic span creation and context propagation for Lambda invocations
  • Metrics Collection: Performance and business metrics exportable to standard observability backends
  • OpenTelemetry Integration: Built on the OpenTelemetry SDK for vendor-neutral instrumentation
  • AWS Lambda Instrumentation: Wraps OpenTelemetry.Instrumentation.AWSLambda for Lambda-specific insights
  • Lifecycle Integration: Seamless integration with Lambda cold starts, warm invocations, and error tracking

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).

Installation

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.

Quick Start

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();

Key Features

  • Automatic Root Span – Wraps Lambda invocations with OpenTelemetry spans via source generation and compile-time interceptors
  • AWS Lambda Context – Captures Lambda context information in spans (request IDs, function name, etc.)
  • Custom Instrumentation – Inject ActivitySource to create spans for your business logic
  • Multiple Exporters – OTLP, Jaeger, AWS X-Ray, Datadog, and more
  • AOT Compatible – Works with .NET Native AOT compilation
  • Graceful Shutdown – Ensures traces export before Lambda terminates

Core Concepts

Automatic Root Span Creation

When 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:

  • Compile Time: Source generators analyze your handler signature and create a compile-time interceptor that injects middleware into the pipeline
  • Startup: The middleware extracts a TracerProvider from the dependency injection container
  • Per Invocation: The middleware calls the appropriate AWS Lambda instrumentation wrapper function with the correct type information (event and response types), which uses the TracerProvider to create the root span

This 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).

Custom Instrumentation with ActivitySource

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.

Graceful Shutdown

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();

Example Project

A complete, runnable example with Docker Compose setup is available in .

The example demonstrates:

  • Full OpenTelemetry configuration with OTLP export
  • Custom instrumentation and metrics in a real handler
  • Jaeger tracing backend setup via Docker Compose
  • Running locally with AWS Lambda Test Tool
  • Viewing traces and metrics in the Jaeger UI

Documentation

Other Packages

Additional packages in the aws-lambda-host framework for abstractions, observability, and event source handling.

Package NuGet Downloads
πŸ‘ NuGet
πŸ‘ Downloads
πŸ‘ NuGet
πŸ‘ Downloads
πŸ‘ NuGet
πŸ‘ Downloads
πŸ‘ NuGet
πŸ‘ Downloads
πŸ‘ NuGet
πŸ‘ Downloads
πŸ‘ NuGet
πŸ‘ Downloads
πŸ‘ NuGet
πŸ‘ Downloads
πŸ‘ NuGet
πŸ‘ Downloads
πŸ‘ NuGet
πŸ‘ Downloads
πŸ‘ NuGet
πŸ‘ Downloads
πŸ‘ NuGet
πŸ‘ Downloads

License

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. 
Compatible target framework(s)
Included target framework(s) (in package)
Learn more about Target Frameworks and .NET Standard.

NuGet packages

This package is not used by any NuGet packages.

GitHub repositories

This package is not used by any popular GitHub repositories.

Version Downloads Last Updated
Loading failed