|
| 1 | +--- |
| 2 | +id: dotnet |
| 3 | +title: AWS Lambda - .NET Function Instrumentation |
| 4 | +sidebar_label: .NET |
| 5 | +description: Learn how to install and configure OpenTelemetry distributed tracing for AWS .NET-based Lambda functions and send data to Sumo Logic. |
| 6 | +--- |
| 7 | + |
| 8 | +import useBaseUrl from '@docusaurus/useBaseUrl'; |
| 9 | +import ApmTrace from '../../../../../reuse/apm-traces-layer-order.md'; |
| 10 | + |
| 11 | +This document covers how to install and configure OpenTelemetry distributed tracing for AWS Lambda functions based on .NET and send the data to Sumo Logic. |
| 12 | + |
| 13 | +To obtain tracing data from AWS Lambda functions developed in .NET, you can use the following components |
| 14 | + |
| 15 | +### Provided SDK |
| 16 | + |
| 17 | +[OpenTelemetry Lambda SDK for .NET](https://github.com/open-telemetry/opentelemetry-dotnet-contrib/tree/main/src/OpenTelemetry.Instrumentation.AWSLambda) includes tracing APIs to instrument Lambda handlers and is provided on [NuGet](https://www.nuget.org/packages/OpenTelemetry.Instrumentation.AWSLambda). |
| 18 | + |
| 19 | +### OpenTelemetry Lambda layer |
| 20 | + |
| 21 | +[OpenTelemetry Lambda Layer for Collector](https://github.com/open-telemetry/opentelemetry-lambda/tree/main/collector#opentelemetry-collector-aws-lambda-extension-layer) includes OpenTelemetry Collector for Lambda components. Apply this layer to your Lambda handler that's already been instrumented with the OpenTelemetry Lambda .NET SDK to enable end-to-end tracing. |
| 22 | + |
| 23 | +#### .NET Lambda layer supports |
| 24 | + |
| 25 | +* .NET 6 SDK or later |
| 26 | +* x86_64 and arm64 architectures |
| 27 | + |
| 28 | +### Lambda function requirements |
| 29 | + |
| 30 | +You'll need the following: |
| 31 | + |
| 32 | +* .NET 6 SDK or later |
| 33 | +* Lambda layers add permissions |
| 34 | +* Sumo Logic OTLP/HTTP Source endpoint URL - To send spans from the instrumented Lambda function to Sumo Logic you need an endpoint URL from an existing or new [OTLP/HTTP source](/docs/send-data/hosted-collectors/http-source/otlp). |
| 35 | + |
| 36 | +## Quick Start |
| 37 | + |
| 38 | +### Overview |
| 39 | + |
| 40 | +<img src={useBaseUrl('img/apm/traces/lambda-dotnet-overview.png')} alt=".NET Lambda Overview" style={{border: '1px solid gray'}} width="800" /> |
| 41 | + |
| 42 | +### Prerequisites |
| 43 | + |
| 44 | +* AWS CLI configured with appropriate permissions |
| 45 | +* Configure the [AWS credential](https://docs.aws.amazon.com/cli/latest/userguide/cli-configure-files.html) |
| 46 | +* .NET 6 SDK |
| 47 | +* Sumo Logic OTLP endpoint URL |
| 48 | + |
| 49 | +### Configure the lambda function |
| 50 | + |
| 51 | +Navigate to [functions](https://console.aws.amazon.com/lambda/home#/functions) in the AWS Lambda Console and open the function you want to instrument. |
| 52 | + |
| 53 | +* Navigate to the **Layers** section and click **Add a layer**. |
| 54 | + Use the following upstream [collector lambda layer](https://github.com/open-telemetry/opentelemetry-lambda/tree/main?tab=readme-ov-file#latest-layer-versions) |
| 55 | + |
| 56 | + * `arn:aws:lambda:<region>:184161586896:layer:opentelemetry-collector-<amd64|arm64>-<version>:1` |
| 57 | + |
| 58 | +* In the **Choose a layer** menu, select **Specify an ARN** and paste the above ARN ID for your Lambda function |
| 59 | + :::note |
| 60 | + Lambda layers are a regionalized resource, meaning that they can only be used in the Region in which they are published. Make sure to use the layer in the same region as your Lambda functions. |
| 61 | + ::: |
| 62 | + |
| 63 | + By default, OpenTelemetry Collector Lambda layer exports telemetry data to AWS backends. To customize the collector configuration, add a collector.yaml to your function and specify its location via the `OPENTELEMETRY_COLLECTOR_CONFIG_URI` environment file. |
| 64 | + |
| 65 | +* Configure the collector layer to send data to SumoLogic: |
| 66 | + |
| 67 | + ```yaml |
| 68 | + receivers: |
| 69 | + otlp: |
| 70 | + protocols: |
| 71 | + grpc: |
| 72 | + endpoint: localhost:4317 |
| 73 | + http: |
| 74 | + endpoint: localhost:4318 |
| 75 | + |
| 76 | + exporters: |
| 77 | + otlphttp: |
| 78 | + endpoint: ${SUMO_LOGIC_OTLP_ENDPOINT} |
| 79 | + headers: |
| 80 | + Content-Type: application/x-protobuf |
| 81 | + encoding: proto |
| 82 | + |
| 83 | + service: |
| 84 | + pipelines: |
| 85 | + traces: |
| 86 | + receivers: [otlp] |
| 87 | + exporters: [otlphttp] |
| 88 | + ``` |
| 89 | +
|
| 90 | + Once the file has been deployed with a Lambda, configuring the `OPENTELEMETRY_COLLECTOR_CONFIG_URI` will tell the OpenTelemetry extension where to find the collector configuration: |
| 91 | + |
| 92 | + ```bash |
| 93 | + aws lambda update-function-configuration --function-name Function --environment Variables={OPENTELEMETRY_COLLECTOR_CONFIG_URI=/var/task/collector.yaml} |
| 94 | + ``` |
| 95 | + |
| 96 | +* Configure the following environment variables: |
| 97 | + |
| 98 | + Navigate to the **Configuration > Environment variables** section and ensure that the following environment variables are setup: |
| 99 | + |
| 100 | + | Variable | Value | Purpose | |
| 101 | + |:---------|:------|:--------| |
| 102 | + | `OTEL_EXPORTER_OTLP_ENDPOINT` | `localhost:4318` | Collector endpoint | |
| 103 | + | `OTEL_EXPORTER_OTLP_PROTOCOL` | `http/protobuf` | Export protocol | |
| 104 | + | `AWS_LAMBDA_EXEC_WRAPPER` | `/opt/otel-instrument` | Lambda wrapper | |
| 105 | + | `SUMO_LOGIC_OTLP_ENDPOINT` | `https://your-endpoint.sumologic.net/receiver/v1/otlp/YOUR_TOKEN` | Sumo Logic endpoint | |
| 106 | + | `OPENTELEMETRY_COLLECTOR_CONFIG_URI` | `/var/task/collector.yaml` | Collector configuration | |
| 107 | + |
| 108 | +Any other environment variables like `OTEL_RESOURCE_ATTRIBUTES` or `OTEL_SERVICE_NAME` could also be configured. |
| 109 | + |
| 110 | +Your function should be successfully instrumented. Invoke the function and find your traces in the [Sumo Logic Tracing screen](/docs/apm/traces/view-and-investigate-traces) |
| 111 | + |
| 112 | +## References |
| 113 | + |
| 114 | +* [OpenTelemetry Lambda Layer Documentation](https://github.com/open-telemetry/opentelemetry-lambda) |
| 115 | +* [Sumo Logic OTLP Integration](https://help.sumologic.com/docs/send-data/hosted-collectors/http-source/otlp/) |
0 commit comments