Setting up native tracing for .NET or .NET Core-based AWS Lambda functions

You can set up Instana AutoTrace for AWS Lambda functions that are written in .NET or .NET Core. To set up native tracing for .NET-based AWS Lambda functions, you need to add the Instana Lambda layer to your Lambda functions. After you enable tracing, you can view the tracing data of your Lambda functions in the Instana UI.

Supported runtimes

Instana supports monitoring applications that run on .NET 6 and later.

Configuring AWS Lambda functions for tracing

Ensure that you set up the AWS agent for Lambda monitoring to collect versions and runtime metrics that Instana cannot collect from inside the AWS Lambda runtime.

You can enable tracing of Lambda functions through the AWS web console or any of the following AWS management tools:

Enabling tracing through the AWS web console

To enable tracing of .NET or .NET Core Lambda functions, complete the following steps in the AWS Lambda UI:

  1. Add the Instana Lambda layer to your function as shown in the following steps:

    1. In the Configuration tab of your Lambda function, click Layers > Add a layer.

      layer

    2. In the "Add layer" window, select Specify an ARN.

    3. Copy and paste the Amazon Resource Name (ARN) for the Instana Lambda layer that matches your region in the Specify an ARN field. You can find the right ARN for the Instana Lambda layer in the Instana Lambda layers section. Then, click Verify.

    4. Click Add.

  2. Configure the following environment variables to connect to the Instana backend:

    Environment variables Value
    CORECLR_ENABLE_PROFILING 1
    CORECLR_PROFILER {cf0d821e-299b-5307-a3d8-b283c03916dd}
    CORECLR_PROFILER_PATH /opt/instana_tracing/CoreProfiler.co
    DOTNET_STARTUP_HOOKS /opt/Instana.Tracing.Core.dll
    INSTANA_AGENT_KEY <your_instana_agent_key>
    INSTANA_ENDPOINT_URL <serverless_instana_endpoint>
    INSTANA_AWS_ACCOUNT_ID <your_aws_account_id>
    LAMBDA_HANDLER <Assembly::Namespace.ClassName::MethodName>

    Make sure that you use the correct Instana endpoint URL for your region that starts with https://serverless-. For more information, see Endpoints for serverless monitoring.

    If your default handler doesn't use the Assembly::Namespace.ClassName::MethodName format, then set your default handler in the LAMBDA_HANDLER format. Otherwise, don't set the variable or leave it empty. If the correlation data, which shows connection between traces and infrastructure entities, is missing in the Instana UI, use LAMBDA_HANDLER to set the correct format.

    You can also obtain the correct values for these environment variables from your Instana UI. To obtain the correct values for these environment variables, click More > Agents > Install Agents > Platform: AWS > Technology: AWS Lambda in the Instana UI.

Enabling tracing through AWS command-line interface

If you want to automate the Instana integration of your AWS Lambdas, see the following AWS CLI command example:

# Do not copy and paste this verbatim!
# It will overwrite any previously defined collection of layers and
# environment variables.
aws --region $YOUR_REGION lambda update-function-configuration \
   --function-name $YOUR_LAMBDA_FUNCTION_NAME \
   --layers $INSTANA_LAYER_ARN \
   --environment "Variables={CORECLR_ENABLE_PROFILING=1, CORECLR_PROFILER=\"{cf0d821e-299b-5307-a3d8-b283c03916dd}\", CORECLR_PROFILER_PATH=/opt/instana_tracing/CoreProfiler.so, DOTNET_STARTUP_HOOKS=/opt/Instana.Tracing.Core.dll, INSTANA_ENDPOINT_URL=... , INSTANA_AGENT_KEY=... , ...}"

Instana Lambda layers

The ARNs of the latest version of the AWS Lambda layers for .NET according to the region are as follows:

Region ARN
af-south-1 arn:aws:lambda:af-south-1:410797082306:layer:instana-dotnetcore:9
ap-east-1 arn:aws:lambda:ap-east-1:410797082306:layer:instana-dotnetcore:9
ap-northeast-1 arn:aws:lambda:ap-northeast-1:410797082306:layer:instana-dotnetcore:9
ap-northeast-2 arn:aws:lambda:ap-northeast-2:410797082306:layer:instana-dotnetcore:9
ap-northeast-3 arn:aws:lambda:ap-northeast-3:410797082306:layer:instana-dotnetcore:9
ap-south-1 arn:aws:lambda:ap-south-1:410797082306:layer:instana-dotnetcore:9
ap-south-2 arn:aws:lambda:ap-south-2:410797082306:layer:instana-dotnetcore:9
ap-southeast-1 arn:aws:lambda:ap-southeast-1:410797082306:layer:instana-dotnetcore:9
ap-southeast-2 arn:aws:lambda:ap-southeast-2:410797082306:layer:instana-dotnetcore:9
ap-southeast-3 arn:aws:lambda:ap-southeast-3:410797082306:layer:instana-dotnetcore:9
ap-southeast-4 arn:aws:lambda:ap-southeast-4:410797082306:layer:instana-dotnetcore:9
ca-central-1 arn:aws:lambda:ca-central-1:410797082306:layer:instana-dotnetcore:9
`cn-north-1' arn:aws-cn:lambda:cn-north-1:107998019096:layer:instana-dotnetcore:7
`cn-northwest-1' arn:aws-cn:lambda:cn-northwest-1:107998019096:layer:instana-dotnetcore:7
eu-central-1 arn:aws:lambda:eu-central-1:410797082306:layer:instana-dotnetcore:8
eu-central-2 arn:aws:lambda:eu-central-2:410797082306:layer:instana-dotnetcore:9
eu-north-1 arn:aws:lambda:eu-north-1:410797082306:layer:instana-dotnetcore:9
eu-south-1 arn:aws:lambda:eu-south-1:410797082306:layer:instana-dotnetcore:9
eu-south-2 arn:aws:lambda:eu-south-2:410797082306:layer:instana-dotnetcore:9
eu-west-1 arn:aws:lambda:eu-west-1:410797082306:layer:instana-dotnetcore:8
eu-west-2 arn:aws:lambda:eu-west-2:410797082306:layer:instana-dotnetcore:9
eu-west-3 arn:aws:lambda:eu-west-3:410797082306:layer:instana-dotnetcore:8
il-central-1 arn:aws:lambda:il-central-1:410797082306:layer:instana-dotnetcore:9
me-central-1 arn:aws:lambda:me-central-1:410797082306:layer:instana-dotnetcore:9
me-south-1 arn:aws:lambda:me-south-1:410797082306:layer:instana-dotnetcore:9
sa-east-1 arn:aws:lambda:sa-east-1:410797082306:layer:instana-dotnetcore:8
us-east-1 arn:aws:lambda:us-east-1:410797082306:layer:instana-dotnetcore:9
us-east-2 arn:aws:lambda:us-east-2:410797082306:layer:instana-dotnetcore:9
us-west-1 arn:aws:lambda:us-west-1:410797082306:layer:instana-dotnetcore:8
us-west-2 arn:aws:lambda:us-west-2:410797082306:layer:instana-dotnetcore:8

For example, the ARN pattern is arn:aws:lambda:${region}:410797082306:layer:instana-dotnetcore:${layer-version}. For AWS regions in China the ARN pattern is arn:aws-cn:lambda:${region}:107998019096:layer:instana-dotnetcore:${layer-version}.

Make sure that you always use the latest version of the Instana Lambda layer. Update the layer version that you use at regular intervals to benefit from the features and fixes that the new version of the layer provides.

Known issues

During the AWS Lambda function execution, the following error can appear in the logs. This error is Instana's internal error and doesn't mean that the Lambda function stopped working or resulted in error. If traces can be located in the Instana UI, you can ignore this message.

Error sending traces. Exception: System.Threading.Tasks.TaskCanceledException, Message:The request was canceled due to the configured HttpClient.Timeout of 2 seconds elapsing. (calling https://serverless.instana.io/bundle), Original exception: A task was canceled., CallStack:   at System.Net.Http.HttpClient.HandleFailure(Exception e, Boolean telemetryStarted, HttpResponseMessage response, CancellationTokenSource cts, CancellationToken cancellationToken, CancellationTokenSource pendingRequestsCts)