/opentelemetry-dotnet-instrumentation

.NET instrumentation and auto-instrumentation

Primary LanguageC++Apache License 2.0Apache-2.0

PoC - Reuse OpenTelemetry .NET API and SDK

Vision

Use OpenTelemetry .NET API and SDK instead Datadog tracer model.

Use Case

Instrumented HTTP client and HTTP server applciations exporting traces to Jaeger. We may also try adding manual instrumentation.

Constraints

We may add additional requirements for the instrumented applications such us:

  • Add references to OpenTelemetry NuGet packages.
  • Concrete versions of OpenTelemetry NuGet packages must be used.
  • Must use newer versions of .NET.

Plan

Preparation

  1. Prepare the use case secenario and make sure it is working.
  2. Get rid of everything, but HTTP Client and HTTP Server instrumentation. Reason: quicker iterations (especially thanks to quicker build time). Make sure the use case is still working.

It would be good to have some automation here to test without doing to much stuff manually.

Remove Datadog Tracer

  1. Remove Datadog.Trace.Tracer and a lot of related code. We can just keep the AutoInstrumentation integration boilerplate for HTTP Client and ASP.NET.
  2. Change the OpenTelemetry.ClrProfiler.Instrumentation.Initialize() method so that it will be the place where the global OTel trace provider will be configured.

It would be good to have a checkpoint here where the instrumented application is NOOP-instrumented.

Experiments

  1. Hardcode the global OTel tracer configuration.
  2. Configure the OTel tracer based on env vars. SDK should handle it. question
  3. Add manual instrumentation to the applications.
  4. Try auto-instrumentation using ActivitySource e.g. in OpenTelemetry.ClrProfiler.AutoInstrumentation.Http.HttpClient.HttpMessageHandlerCommon.
  5. Test with different versions of OTel SDK in runtime.
  6. Try using AppDomain.CurrentDomain.AssemblyResolve += to add a fallback if the instrumented app does not reference the OTel SDK.

Helpful docs and samples

Testing

Additional setup for Windows

Add msbuild to your PATH. You can do it by adding to ~/.bashrc something more or less like bellow:

PATH="$PATH:/c/Program Files (x86)/Microsoft Visual Studio/2019/Professional/MSBuild/Current/Bin"

Additional setup for Linux and MacOS

sudo mkdir -p /var/log/opentelemetry/dotnet
sudo chmod a+rwx /var/log/opentelemetry/dotnet

Usage

Make sure to run dotnet nuke Clean BuildTracer before running the PoC smoke test.

For .NET Core 3.1 run:

./poc.sh

For .NET 5.0 run:

aspNetAppTargetFramework=net5.0 sampleAppTargetFramework=net5.0 ./poc.sh

For .NET Framework run:

sampleAppTargetFramework=net46 ./poc.sh

To instrument the .NET BindingRedirect sample application run:

sampleAppTargetFramework=net472 sampleApp=BindingRedirect ./poc.sh