OpenTelemetry .NET Automatic Instrumentation
Go to file
Paulo Janotti e34e3c9b41
PoC: Add support to testing OpenTracing integration (#186)
* Add OpenTracingShim to SDK initialization

* Add OpenTracingShim as option to ConsoleApp

* Change wrapper method to async

* Match casing of other poc variables

* Change log message to "tracer initialized"

* Make OT span default on ConsoleApp

* Fixes .vcxproj file for latest msbuild version. (#1495)

Co-authored-by: Tony Redondo <tony.redondo@datadoghq.com>
2021-06-01 12:41:42 -07:00
.devcontainer.example Add development environment setup (#68) 2021-03-17 11:34:44 -07:00
.github PoC: Cleanup (#175) 2021-05-22 08:25:02 -07:00
.vscode.example Add docs and configs for VS Code (#60) 2021-02-24 07:07:16 -08:00
dev OTEL_TRACE_CALLTARGET_ENABLED=true by default and truncate integrations.json (#181) 2021-05-27 23:53:05 +02:00
docs Add sample app that does tracer initialization on its own (#179) 2021-05-28 07:59:24 -07:00
samples PoC: Add support to testing OpenTracing integration (#186) 2021-06-01 12:41:42 -07:00
src PoC: Add support to testing OpenTracing integration (#186) 2021-06-01 12:41:42 -07:00
.clang-format Forking the DataDog .NET Tracer to seed the OTel .NET Auto-Instrumentation-Agent. 2020-08-20 13:35:02 -07:00
.dockerignore Directory Restructuring (#973) (#27) 2020-11-03 11:04:25 -08:00
.editorconfig Forking the DataDog .NET Tracer to seed the OTel .NET Auto-Instrumentation-Agent. 2020-08-20 13:35:02 -07:00
.env Enable azure pipelines (#12) 2020-09-01 16:37:11 -07:00
.gitattributes Forking the DataDog .NET Tracer to seed the OTel .NET Auto-Instrumentation-Agent. 2020-08-20 13:35:02 -07:00
.gitignore Catchup to upstream (#70) 2021-03-04 14:07:43 -08:00
Datadog.Trace.proj PoC: Cleanup (#175) 2021-05-22 08:25:02 -07:00
Datadog.Trace.sln PoC: Add support to testing OpenTracing integration (#186) 2021-06-01 12:41:42 -07:00
Datadog.Trace.sln.DotSettings Catchup to upstream (#38) 2021-01-28 09:18:14 -08:00
Directory.Build.props Upstream 26.04.21 (#142) 2021-04-26 21:38:29 -07:00
GlobalSuppressions.cs Catchup to upstream (#70) 2021-03-04 14:07:43 -08:00
LICENSE Initial commit 2020-07-14 20:50:30 -04:00
LICENSE-3rdparty.csv Upstream sync 2021-03-31 (#99) 2021-04-02 16:19:50 -07:00
NOTICE Forking the DataDog .NET Tracer to seed the OTel .NET Auto-Instrumentation-Agent. 2020-08-20 13:35:02 -07:00
OpenTelemetry.AutoInstrumentation.snk Replace snk with a new one (#62) 2021-03-03 07:10:31 -08:00
README.md Add sample app that does tracer initialization on its own (#179) 2021-05-28 07:59:24 -07:00
build.sh PoC: Add env var for tracer init (#177) 2021-05-26 16:41:15 +02:00
defaults.env Change env vars prefixes; rename profiler native dll (#61) 2021-03-02 14:51:19 -08:00
devenv.bat Change env vars prefixes; rename profiler native dll (#61) 2021-03-02 14:51:19 -08:00
git-clean.cmd Forking the DataDog .NET Tracer to seed the OTel .NET Auto-Instrumentation-Agent. 2020-08-20 13:35:02 -07:00
integrations.json OTEL_TRACE_CALLTARGET_ENABLED=true by default and truncate integrations.json (#181) 2021-05-27 23:53:05 +02:00
nuget.config Create nuget.config (#120) 2021-04-08 09:21:33 -07:00
opentelemetry-logo-64x64.png Exchange datadog logo files with opentelemetry ones (#64) 2021-03-02 21:02:41 -08:00
opentelemetry-logo-256x256.png Exchange datadog logo files with opentelemetry ones (#64) 2021-03-02 21:02:41 -08:00
poc.sh PoC: Add env var for tracer init (#177) 2021-05-26 16:41:15 +02:00
pre-build-events-cpp.bat Forking the DataDog .NET Tracer to seed the OTel .NET Auto-Instrumentation-Agent. 2020-08-20 13:35:02 -07:00
stylecop.json Catchup to upstream (#70) 2021-03-04 14:07:43 -08:00

README.md

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 Datadog.Trace.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 Datadog.Trace.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

Findings

Required reference to System.Diagnostics.DiagnosticSource

The instrumented application has to include:

<PackageReference Include="System.Diagnostics.DiagnosticSource" Version="5.0.1" />

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

For .NET Core 3.1 run:

./poc.sh

For .NET 5.0 run:

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

For .NET Framework run:

consoleAppTargetFramework=net46 ./poc.sh