OpenTelemetry .NET Automatic Instrumentation
Go to file
dependabot[bot] f8f991442b
Bump Google.Protobuf from 3.21.12 to 3.22.0 in /src (#2222)
Bumps [Google.Protobuf](https://github.com/protocolbuffers/protobuf) from 3.21.12 to 3.22.0.
- [Release notes](https://github.com/protocolbuffers/protobuf/releases)
- [Changelog](https://github.com/protocolbuffers/protobuf/blob/main/generate_changelog.py)
- [Commits](https://github.com/protocolbuffers/protobuf/compare/v3.21.12...v3.22.0)

---
updated-dependencies:
- dependency-name: Google.Protobuf
  dependency-type: direct:production
  update-type: version-update:semver-minor
...

Signed-off-by: dependabot[bot] <support@github.com>
Co-authored-by: dependabot[bot] <49699333+dependabot[bot]@users.noreply.github.com>
2023-02-20 09:38:46 +00:00
.config Bump Nuke.Common from 6.2.1 to 6.3.0 in /build (#1837) 2022-12-20 09:54:28 -08:00
.cspell Add host tracing to troubleshooting doc (#2186) 2023-02-10 10:37:31 +01:00
.github [CI] Publish binaries built on CentOS (#2203) 2023-02-14 13:51:59 +01:00
.nuke [POC] Add native tests (#201) 2021-07-20 10:46:07 -07:00
.vscode Recommend C/C++ Extension Pack VS Code extension (#1734) 2022-12-08 11:56:51 +00:00
build Only embed and use the Loader for .NET Fx (#2216) 2023-02-16 07:13:17 +01:00
dev Reuse instrument.sh for development (#2161) 2023-02-03 13:07:32 +00:00
docker [CI] Centos build in ci (#2193) 2023-02-14 07:16:03 +00:00
docs Release 0.6.0-beta.2 (#2205) 2023-02-15 07:00:02 +01:00
examples Reuse instrument.sh for development (#2161) 2023-02-03 13:07:32 +00:00
nuget Release 0.6.0-beta.2 (#2205) 2023-02-15 07:00:02 +01:00
scripts Format native code using clang-format (#2101) 2023-02-02 12:10:26 +00:00
src Bump Google.Protobuf from 3.21.12 to 3.22.0 in /src (#2222) 2023-02-20 09:38:46 +00:00
test Bump Google.Protobuf from 3.21.12 to 3.22.0 in /test (#2221) 2023-02-17 13:33:59 +00:00
tools Install netfx dlls to GAC for tests (#2164) 2023-02-07 12:47:54 -08:00
.clang-format Format native code using clang-format (#2101) 2023-02-02 12:10:26 +00:00
.cspell.json Spellcheck documentation (#627) 2022-04-25 10:04:54 -07:00
.editorconfig dotnet-format check step (#1121) 2022-08-24 22:41:18 -07:00
.gitattributes Verify whole distribution structure (#1156) 2022-09-06 12:15:06 -07:00
.gitignore Add diagnostic messages and hang dumps for IntegrationTests (#1298) 2022-09-28 16:31:29 -07:00
.lycheeignore Add AspNetCoreMvc as playground example (#1877) 2023-01-02 16:05:12 +01:00
.markdownlint.yaml Update Changelog and MongoDB docs (#635) 2022-04-28 22:54:51 +00:00
.markdownlintignore Improve local documentation validation (#1028) 2022-08-02 16:20:28 -07:00
CHANGELOG.md Release 0.6.0-beta.2 (#2205) 2023-02-15 07:00:02 +01:00
Common.props Manage dependencies with Central Package Management (#2004) 2023-01-23 11:46:12 +00:00
Common.targets Enable implicit usings (#1966) 2023-01-10 10:03:46 -08:00
Directory.Build.props Enable nullable for main project (#1861) 2022-12-21 20:45:28 +00:00
Directory.Packages.props Bump OTel to 1.4.0-rc.4 (#2202) 2023-02-14 07:47:36 +01:00
GlobalSuppressions.cs Add copyright header in C# files and improve Stylecop.Analyzer usage (#415) 2022-03-18 08:25:23 +01:00
LICENSE Bump OTel to 1.4.0-rc.3 (#2157) 2023-02-03 06:39:48 +01:00
OpenTelemetry.AutoInstrumentation.DotSettings Rename assemblies to OpenTelemetry.AutoInstrumentation (#363) 2022-02-15 11:49:09 -08:00
OpenTelemetry.AutoInstrumentation.sln Install netfx dlls to GAC for tests (#2164) 2023-02-07 12:47:54 -08:00
OpenTelemetry.DotNet.Auto.psm1 Release 0.6.0-beta.2 (#2205) 2023-02-15 07:00:02 +01:00
build.cmd [POC] Add OTEL_DOTNET_TRACER_INSTRUMENTATIONS and bump dependencies (#204) 2021-07-29 08:54:30 +02:00
build.ps1 Replace current with STS in build scripts (#1891) 2023-01-04 12:00:47 +01:00
build.sh Replace current with STS in build scripts (#1891) 2023-01-04 12:00:47 +01:00
instrument.sh Reuse instrument.sh for development (#2161) 2023-02-03 13:07:32 +00:00
integrations.json Get rid of wrapper.action in bytecode instrumentation (#1889) 2023-01-04 11:14:56 +01:00
nuget.config Create nuget.config (#120) 2021-04-08 09:21:33 -07:00
opentelemetry-logo-64x64.png
opentelemetry-logo-256x256.png
otel-dotnet-auto-install.sh Release 0.6.0-beta.2 (#2205) 2023-02-15 07:00:02 +01:00
package-lock.json Bump cspell-cli from 6.22.0 to 6.24.0 (#2212) 2023-02-15 14:46:50 +01:00
package.json Bump cspell-cli from 6.22.0 to 6.24.0 (#2212) 2023-02-15 14:46:50 +01:00
stylecop.json Add copyright header in C# files and improve Stylecop.Analyzer usage (#415) 2022-03-18 08:25:23 +01:00

docs/README.md

OpenTelemetry .NET Automatic Instrumentation

Slack

This project adds OpenTelemetry instrumentation to .NET applications without having to modify their source code.


⚠️ The following documentation refers to the in-development version of OpenTelemetry .NET Automatic Instrumentation. Docs for the latest version (0.5.0) can be found here.


OpenTelemetry .NET Automatic Instrumentation is built on top of OpenTelemetry .NET:

You can find all references in OpenTelemetry.AutoInstrumentation.csproj and OpenTelemetry.AutoInstrumentation.AdditionalDeps/Directory.Build.props.

To automatically instrument applications, the OpenTelemetry .NET Automatic Instrumentation does the following:

  1. Injects and configures the OpenTelemetry .NET SDK into the application.
  2. Adds OpenTelemetry Instrumentation to key packages and APIs used by the application.

You can enable the OpenTelemetry .NET Automatic Instrumentation as a .NET Profiler to inject additional instrumentations of this project at runtime, using a technique known as monkey-patching. When enabled, the OpenTelemetry .NET Automatic Instrumentation generates traces for libraries that don't already generate traces using the OpenTelemetry .NET SDK.

See design.md for an architectural overview.

Status

The versioning information and stability guarantees can be found in the versioning documentation.

Compatibility

OpenTelemetry .NET Automatic Instrumentation attempts to work with all officially supported operating systems and versions of .NET, and .NET Framework.

Versions lower than .NET Framework 4.6.2 are not supported.

.NET Core 3.1 is not supported. 0.4.0-beta.1 is the latest version supporting it.

Red Hat Enterprise Linux lower than 9 are not supported. See (#2083).

CI tests run against the following operating systems:

Instrumented libraries and frameworks

See config.md#instrumented-libraries-and-frameworks.

Get started

Considerations on scope

Currently, instrumenting self-contained applications is not supported. Note that a self-contained applications is automatically generated in .NET 7.0 whenever the dotnet publish or dotnet build command is used with a Runtime Identifier (RID) parameter, for example when -r or --runtime is used when running the command.

Until version v0.6.0-beta.1 (inclusive) there were issues instrumenting the dotnet CLI. To build and launch an instrumented application, take the following into account if you are using one of the affected versions:

  • Don't set the automatic instrumentation environment variables in the same session used to run the dotnet tool.
  • Don't launch the application to be instrumented using dotnet run or dotnet <dll>. Build the application in an isolated shell, without the automatic instrumentation environment variables set, and use a separate session with the automatic instrumentation variables to directly launch the executable.

Install

Download and extract the appropriate binaries from the latest release.

The path where you put the binaries is referenced as $INSTALL_DIR

Instrument a .NET application

When running your application, make sure to:

  1. Set the resources.
  2. Set the environment variables from the table below.
Environment variable .NET version Value
COR_ENABLE_PROFILING .NET Framework 1
COR_PROFILER .NET Framework {918728DD-259F-4A6A-AC2B-B85E1B658318}
COR_PROFILER_PATH_32 .NET Framework $INSTALL_DIR/win-x86/OpenTelemetry.AutoInstrumentation.Native.dll
COR_PROFILER_PATH_64 .NET Framework $INSTALL_DIR/win-x64/OpenTelemetry.AutoInstrumentation.Native.dll
CORECLR_ENABLE_PROFILING .NET 1
CORECLR_PROFILER .NET {918728DD-259F-4A6A-AC2B-B85E1B658318}
CORECLR_PROFILER_PATH .NET on Linux glibc $INSTALL_DIR/linux-x64/OpenTelemetry.AutoInstrumentation.Native.so
CORECLR_PROFILER_PATH .NET on Linux musl $INSTALL_DIR/linux-musl-x64/OpenTelemetry.AutoInstrumentation.Native.so
CORECLR_PROFILER_PATH .NET on macOS $INSTALL_DIR/osx-x64/OpenTelemetry.AutoInstrumentation.Native.dylib
CORECLR_PROFILER_PATH_32 .NET on Windows $INSTALL_DIR/win-x86/OpenTelemetry.AutoInstrumentation.Native.dll
CORECLR_PROFILER_PATH_64 .NET on Windows $INSTALL_DIR/win-x64/OpenTelemetry.AutoInstrumentation.Native.dll
DOTNET_ADDITIONAL_DEPS .NET $INSTALL_DIR/AdditionalDeps
DOTNET_SHARED_STORE .NET $INSTALL_DIR/store
DOTNET_STARTUP_HOOKS .NET $INSTALL_DIR/net/OpenTelemetry.AutoInstrumentation.StartupHook.dll
OTEL_DOTNET_AUTO_HOME All versions $INSTALL_DIR
OTEL_DOTNET_AUTO_INTEGRATIONS_FILE All versions $INSTALL_DIR/integrations.json

Some settings can be omitted on .NET. For more information, see config.md.

Shell scripts

You can install OpenTelemetry .NET Automatic Instrumentation and instrument your .NET application using the provided Shell scripts. Example usage:

# Download the bash script
curl -sSfL https://raw.githubusercontent.com/open-telemetry/opentelemetry-dotnet-instrumentation/v0.6.0-beta.2/otel-dotnet-auto-install.sh -O

# Install core files
sh ./otel-dotnet-auto-install.sh

# Setup the instrumentation for the current shell session
. $HOME/.otel-dotnet-auto/instrument.sh

# Run your application with instrumentation
OTEL_SERVICE_NAME=myapp OTEL_RESOURCE_ATTRIBUTES=deployment.environment=staging,service.version=1.0.0 ./MyNetApp

otel-dotnet-auto-install.sh script uses environment variables as parameters:

Parameter Description Required Default value
OTEL_DOTNET_AUTO_HOME Location where binaries are to be installed No $HOME/.otel-dotnet-auto
OS_TYPE Possible values: linux-glibc, linux-musl, macos, windows No Calculated
TMPDIR Temporary directory used when downloading the files No $(mktemp -d)
VERSION Version to download No v0.6.0-beta.2

instrument.sh script uses environment variables as parameters:

Parameter Description Required Default value
ENABLE_PROFILING Whether to set the .NET CLR Profiler, possible values: true, false No true
OTEL_DOTNET_AUTO_HOME Location where binaries are to be installed No $HOME/.otel-dotnet-auto
OS_TYPE Possible values: linux-glibc, linux-musl, macos, windows No Calculated

On macOS coreutils is required.

PowerShell module (Windows)

On Windows, you should install OpenTelemetry .NET Automatic Instrumentation and instrument your .NET application using the provided PowerShell module. Example usage (run as administrator):

# Download the module
$module_url = "https://raw.githubusercontent.com/open-telemetry/opentelemetry-dotnet-instrumentation/v0.6.0-beta.2/OpenTelemetry.DotNet.Auto.psm1"
$download_path = Join-Path $env:temp "OpenTelemetry.DotNet.Auto.psm1"
Invoke-WebRequest -Uri $module_url -OutFile $download_path

# Import the module to use its functions
Import-Module $download_path

# Install core files (online vs offline method)
Install-OpenTelemetryCore
Install-OpenTelemetryCore -LocalPath "C:\Path\To\OpenTelemetry.zip" 

# Set up the instrumentation for the current PowerShell session
Register-OpenTelemetryForCurrentSession -OTelServiceName "MyServiceDisplayName"

# Run your application with instrumentation
.\MyNetApp.exe

You can get usage information by calling:

# List all available commands
Get-Command -Module OpenTelemetry.DotNet.Auto

# Get command's usage information
Get-Help Install-OpenTelemetryCore -Detailed

⚠️ The PowerShell module works only on PowerShell 5.1 which is the one installed by default on Windows.

Instrument a container

You can find our demonstrative example that uses Docker Compose here.

You can also consider using the Kubernetes Operator for OpenTelemetry Collector.

Instrument a Windows Service running a .NET application

See windows-service-instrumentation.md.

Instrument an ASP.NET application deployed on IIS

See iis-instrumentation.md.

Configuration

See config.md.

Manual instrumentation

See manual-instrumentation.md.

Troubleshooting

See troubleshooting.md.

Contact

See CONTRIBUTING.md.

Contributing

See CONTRIBUTING.md.

Community Roles

Maintainers (@open-telemetry/dotnet-instrumentation-maintainers):

Approvers (@open-telemetry/dotnet-instrumentation-approvers):

Emeritus Maintainer/Approver/Triager:

Learn more about roles in the community repository.