Skip to content

dtPaTh/AWSLambda.Net.Tracing

Repository files navigation

Trace .NET AWS Lambda Functions with Dynatrace

Distributed Tracing

Dynatrace offers an automatic instrumentation for AWS Lambda Python, Node.JS and Java via Dynatrace AWS Lambda Layer

For functions using the .NET runtime, Dynatrace provides distributed tracing for these types based on OpenTelemetry.

If you already use OpenTelemetry to instrument your functions you can ingest the telemetry either using the OpenTelemetry base functionality or using the Dynatrace (PurePath) exporter which adds additional benefits to fully leverage the automatic analysis capabilties of Dynatrace.

To make using OpenTelemetry easier, Dynatrace provides an enhanced library for AWS Lambda to reduce necessary OpenTelemetry boiler-plate code for trace-propagation, automatically applying resource attributes and initialization code as well to align with semantic conventions.

Eliminate the entry barrier

Whether you are new to OpenTelemetry or need to instrument thousands of functions or maybe just want to try out distributed tracing with minimal effort. The provided libary within this repository allows you to skip the need to fiddle around with OpenTelemetry or adding any additonal instrumentation code to your functions.

How-does it work?

The approach makes use of the aspect oriented programming (AOP) paradigm using Metalama Framework.

What is Metalama?

Metalama is a modern Roslyn-based meta-programming framework from the creators of Postsharp, which helps to improve code quality and productivity in C#. Metalama comes with a license model that can be used for free, up to 3 aspect classes per project, which allows the use of this project for no additional charge as the projects includes 1 aspect class. For more details see Metalama open source licensing

Features

The repository contains a ready-to-use nuget package, which includes an aspect to automatically instruments AWS Lambda handlers using the Dynarace AWS Lambda Instrumentation Package.

The aspect weaves distributed tracing into async as well as syncronous event handlers and supports tracecontext propagation for:

  • APIGatewayProxyRequest
  • APIGatewayHttpApiV2ProxyRequest
  • SQSEvent
  • SNSEvent

The aspect configures the OpenTelemetry trace-provider as described here and here to send the telemetry to Dynatrace and enabling built-in instrumentation for:

  • AWS SDK Instrumentation
  • and HTTPClient

How-To use

1. Add the nuget package to your project e.g. via command line.

NuGet

dotnet add package PaTh.AWSLambda.Tracing

2. Apply Dynatrace configuration

The Dynatrace package automatically reads the necessary configuration such as connection endpoints and authentication tokens, either from environment variables or a custom config file. To read more about configuration see Dynatrace Help

Examples / Testing / Debugging

In the /Examples folder you find various AWS Lambda sample functions, ready to test with e.g. The AWS .NET Mock Lambda Test Tool

Running the examples

To run the examples, you have to apply the necessary connection parameters in dtconfig.json as described in previous Step #2 - Apply Dynatrace configuration

Debugging transformed code

The provided Visual Studio solution is already prepared to debug the transformed code for the examples. For more details how to configure/debug your projects read here.

Troubleshooting

To get extensive log output to troubleshoot potential configuration issues, add the environment variable:

DT_LOGGING_DESTINATION=stdout

Troubleshooting issues when using the AWS .NET Mock Lambda Test Tool

The OpenTelemetry resource detector for AWS Lambda fails due to missing environment variables not set by the tool, which requires to set the following environment variables in the TestTool launch settings: AWS_LAMBDA_FUNCTION_VERSIONand AWS_REGION. See also the related github issue

Contribute

This is an open source project, and we gladly accept new contributions and contributors.

Support

This project is not an offical release of Dynatrace. If you have questions or any problems, open a github issue.

License

Licensed under Apache 2.0 license. See LICENSE for details.

About

Trace .NET AWS Lambda Functions with Dynatrace

Resources

License

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published

Languages