Skip to content

.NET

Before using OTEL to send traces to DataKit, make sure you have already configured the collector.

Version Support

.NET Version Related Instrumentation Release Release notes / official compatibility notes Inferred Support
.NET 10 v1.13.0 "Support for .NET 10" Explicitly adds .NET 10 support (GitHub)
.NET 9 v1.13.0 "Fixed rule engine check for .NET 9 to reflect longer support for STS channel" .NET 9 is covered in the rule engine support check (GitHub)
.NET 8 v1.2.0 "Add support for .NET 8" Explicitly adds .NET 8 support (GitHub)
.NET 7 v0.6.0-beta.2, v1.0.1, v1.4.0 v0.6.0-beta.2: "Updated the shared store to correctly support framework roll-forward from net6.0 to net7.0"
v1.0.1: "Fixed Rule checking System.Diagnostics.DiagnosticSource version for net7.0 failing on correct configuration"
v1.4.0: "Fix ASP.NET Core traces instrumentation for .NET7"
Multiple .NET 7 adaptation and fix records are available. It can be inferred that .NET 7 scenarios were supported, and v1.4.0 explicitly fixed ASP.NET Core traces instrumentation for .NET7 (GitHub) (GitHub)
.NET Framework 4.6.2+ General compatibility note "The minimal supported version of .NET Framework is 4.6.2." Supports .NET Framework 4.6.2 and later. Versions earlier than 4.6.2 are not supported (GitHub)

Installation

$module_url = "https://github.com/open-telemetry/opentelemetry-dotnet-instrumentation/releases/download/v1.2.0/OpenTelemetry.DotNet.Auto.psm1"
$download_path = Join-Path $env:temp "OpenTelemetry.DotNet.Auto.psm1"
Invoke-WebRequest -Uri $module_url -OutFile $download_path -UseBasicParsing

Import-Module $download_path -Force
Install-OpenTelemetryCore

Configuration Parameters

Parameters can be configured in multiple ways.

Global Environment Variable Configuration

Run the following commands in Administrator PowerShell:

[Environment]::SetEnvironmentVariable("OTEL_SERVICE_NAME", "yishaweb2", "Machine")
[Environment]::SetEnvironmentVariable("OTEL_TRACES_EXPORTER", "otlp", "Machine")
[Environment]::SetEnvironmentVariable("OTEL_METRICS_EXPORTER", "none", "Machine")
[Environment]::SetEnvironmentVariable("OTEL_LOGS_EXPORTER", "none", "Machine")
[Environment]::SetEnvironmentVariable("OTEL_EXPORTER_OTLP_PROTOCOL", "http/protobuf", "Machine")
[Environment]::SetEnvironmentVariable("OTEL_LOG_LEVEL", "debug", "Machine")
[Environment]::SetEnvironmentVariable("OTEL_DOTNET_AUTO_LOGGER", "file", "Machine")
[Environment]::SetEnvironmentVariable("OTEL_DOTNET_AUTO_LOG_DIRECTORY", "C:\ProgramData\OpenTelemetry .NET AutoInstrumentation\logs", "Machine")
[Environment]::SetEnvironmentVariable("OTEL_EXPORTER_OTLP_ENDPOINT", "http://127.0.0.1:9529/otel", "Machine")

After running the commands, check whether the variables were written successfully:

$names = @(
  "OTEL_SERVICE_NAME",
  "OTEL_TRACES_EXPORTER",
  "OTEL_METRICS_EXPORTER",
  "OTEL_LOGS_EXPORTER",
  "OTEL_EXPORTER_OTLP_PROTOCOL",
  "OTEL_LOG_LEVEL",
  "OTEL_DOTNET_AUTO_LOGGER",
  "OTEL_DOTNET_AUTO_LOG_DIRECTORY",
  "OTEL_EXPORTER_OTLP_ENDPOINT"
)

foreach ($name in $names) {
  "{0} = {1}" -f $name, [Environment]::GetEnvironmentVariable($name, "Machine")
}

For IIS applications, restart the application pool or IIS before the new global variables can be read:

Restart-WebAppPool -Name "yishaweb2"

Or:

iisreset

IIS Direct Configuration

powershell notepad C:\Windows\System32\inetsrv\config\applicationHost.config

Add the following under the corresponding website node. This method is suitable for configuring trace collection for selected sites.

xml <add name="ys" /> <add name="yishaweb2"> <environmentVariables> <add name="OTEL_SERVICE_NAME" value="yishaweb2" /> <add name="OTEL_TRACES_EXPORTER" value="otlp" /> <add name="OTEL_METRICS_EXPORTER" value="none" /> <add name="OTEL_LOGS_EXPORTER" value="none" /> <add name="OTEL_EXPORTER_OTLP_PROTOCOL" value="http/protobuf" /> <add name="OTEL_LOG_LEVEL" value="debug" /> <add name="OTEL_DOTNET_AUTO_LOGGER" value="file" /> <add name="OTEL_DOTNET_AUTO_LOG_DIRECTORY" value="C:\ProgramData\OpenTelemetry .NET AutoInstrumentation\logs" /> <add name="OTEL_EXPORTER_OTLP_ENDPOINT" value="http://127.0.0.1:9529/otel" /> </environmentVariables> </add>

Note: If the same environment variables are also configured in applicationHost.config or AppPool, application pool level variables usually override Machine-level variables. If you want to use the global configuration uniformly, delete or modify the same OTEL_* configuration in AppPool.

Feedback

Is this page helpful? ×