Skip to content

Latest commit

 

History

History
48 lines (34 loc) · 1.32 KB

windows-service-instrumentation.md

File metadata and controls

48 lines (34 loc) · 1.32 KB

Instrument a Windows Service running a .NET application

Setup

Use the OpenTelemetry.DotNet.Auto.psm1 PowerShell module to set up automatic instrumentation for a Windows Service:

# Import the module
Import-Module "OpenTelemetry.DotNet.Auto.psm1"

# Install core files
Install-OpenTelemetryCore

# Set up your Windows Service instrumentation
Register-OpenTelemetryForWindowsService -WindowsServiceName "WindowsServiceName" -OTelServiceName "MyServiceDisplayName"

Warning Register-OpenTelemetryForWindowsService performs a service restart.

Configuration

Note Remember to restart the Windows Service after making configuration changes. You can do it by executing Restart-Service -Name $WindowsServiceName -Force in PowerShell.

For .NET Framework applications you can configure the most common OTEL_ settings (like OTEL_RESOURCE_ATTRIBUTES) via appSettings in App.config.

The alternative is to set environment variables for the Windows Service in the Windows Registry.

The registry key of a given Windows Service (named $svcName) is located under:

HKLM\SYSTEM\CurrentControlSet\Services\$svcName

The environment variables are defined in a REG_MULTI_SZ (multiline registry value) called Environment in the following format:

Var1=Value1
Var2=Value2