Trace AWS Lambda .NET functions
Add the Lumigo Tracer to your application
Add the Lumigo tracer package via NuGet by running:
dotnet add package Lumigo.DotNET
Wrapping Your Lambda
Wrap your lambda function by implementing a supplier which contains your code:
sync handler:
using Lumigo.DotNET;
...
public class Function : LumigoRequestHandler
{
public Response FunctionHandler(string input, ILambdaContext context)
{
return Handle(input, context, () =>
{
//Your lambda code
//return <result>; - For void functions remove the return statements
});
}
}
async handler:
using Lumigo.DotNET;
...
public class Function : LumigoRequestHandler
{
public async Task<Response> FunctionHandler(string input, ILambdaContext context)
{
return await Handle(input, context, async () =>
{
//Your lambda code
//return <result>; - For void functions remove the return statements
});
}
}
Connect Your Lumigo Account
Set your Lumigo token as the LUMIGO_TRACER_TOKEN
environment variable of your Lambda function; refer to the Using AWS Lambda environment variables documentation for more information. Your Lumigo token is available in Settings -> Tracing -> Manual tracing
, see the Lumigo Tokens documentation.
We advise you to use the most secure available to you to store secrets such as your LUMIGO_TRACER_TOKEN
; refer to AWS Lambda's Securing environment variables documentation for guidance on keeping the values of your Lambda environment variables secure.
Track HTTP Requests
To track HTTP requests add UseLumigo to the HTTP client:
using Amazon.Lambda.Core;
using Lumigo.DotNET;
using Lumigo.DotNET.Instrumentation;
using Lumigo.DotNET.Utilities.Extensions;
using System.Net.Http;
[assembly: LambdaSerializer(typeof(Amazon.Lambda.Serialization.Json.JsonSerializer))]
namespace HelloDotNet6 {
public class Function : LumigoRequestHandler
{
public async Task<string> Handler(string input, ILambdaContext context)
{
return await Handle(input, context, async () =>
{
HttpResponseMessage response = await new HttpClient().UseLumigo().GetAsync("https://httpbin.org/status/200");
response.EnsureSuccessStatusCode();
return "\"Hello world\"";
}
);
}
}
}
Supported runtimes
- .NET Core 3.1
- .NET 6
- .NET 8
Updated about 1 month ago