Instrument your .NET application for Splunk Observability Cloud (OpenTelemetry) π
The Splunk Distribution of OpenTelemetry .NET automatically instruments .NET applications, Windows services running .NET applications, and ASP.NET applications deployed on IIS.
To get started, use the guided setup, follow the instructions manually, or auto-instrument your application. See Splunk OpenTelemetry Zero Configuration Auto Instrumentation for .NET for more information.
Generate customized instructions using the guided setup π
To generate all the basic installation commands for your environment and application, use the .NET OpenTelemetry guided setup. To access the .NET OpenTelemetry guided setup, follow these steps:
Log in to Splunk Observability Cloud.
Open the .NET OpenTelemetry guided setup . Optionally, you can navigate to the guided setup on your own:
In the navigation menu, select
.Select Add Integration to open the Integrate Your Data page.
In the integration filter menu, select By Product.
Select the APM product.
Select the .NET (OpenTelemetry) tile to open the .NET OpenTelemetry guided setup.
Install the Splunk Distribution of OpenTelemetry .NET manually π
If you donβt use the guided setup, follow these instructions to manually install the Splunk Distribution of OpenTelemetry .NET:
To install the distribution using the official NuGet packages, see Install the OpenTelemetry .NET instrumentation using the NuGet packages.
Instrument your .NET application π
Follow these steps to automatically instrument your application:
Windows π
Check that you meet the requirements. See OpenTelemetry .NET instrumentation compatibility and requirements.
(Optional) If needed, uninstall the SignalFx Instrumentation for .NET. See Uninstall the SignalFx Instrumentation for .NET.
Download and install the Splunk Distribution of OpenTelemetry .NET from the Releases page on GitHub . For example:
# Download and import the PowerShell module $module_url = "https://github.com/signalfx/splunk-otel-dotnet/releases/latest/download/Splunk.OTel.DotNet.psm1" $download_path = Join-Path $env:temp "Splunk.OTel.DotNet.psm1" Invoke-WebRequest -Uri $module_url -OutFile $download_path Import-Module $download_path # Install the Splunk distribution using the PowerShell module Install-OpenTelemetryCore
Register the distribution:
# Set up environment to start instrumentation from the current PowerShell session Register-OpenTelemetryForCurrentSession -OTelServiceName "<your-service-name>"
# Set up IIS instrumentation # IIS is restarted as a result Register-OpenTelemetryForIIS
# Set up your Windows Service instrumentation Register-OpenTelemetryForWindowsService -WindowsServiceName "<your-windows-service-name>" -OTelServiceName "<your-OTel-service-name>"
Set the environment and service version resource attributes:
# Configure environment and service version for current PowerShell session $env:OTEL_RESOURCE_ATTRIBUTES='deployment.environment=<envtype>,service.version=<version>'
Run your application after setting the attribute.
For ASP.NET applications, configure the service name and resource attributes in the
appSettings
block of the web.config file:<appSettings> <add key="OTEL_SERVICE_NAME" value="my-service-name" /> <add key="OTEL_RESOURCE_ATTRIBUTES" value="deployment.environment=test,service.version=1.0.0" /> </appSettings>
Note
If
OTEL_SERVICE_NAME
is not set for a web application hosted in IIS, the inferred name based on the site name and virtual directory path is used.After modifying the web.config file, restart IIS:
Start-Process "iisreset.exe" -NoNewWindow -Wait
You can also set the resource attributes for specific application pools in the
environmentVariables
block of the applicationHost.config file . For example:<environmentVariables> <add name="OTEL_RESOURCE_ATTRIBUTES" value="deployment.environment=test,service.version=1.0.0" /> </environmentVariables>
Note
If the
OTEL_SERVICE_NAME
orOTEL_RESOURCE_ATTRIBUTES
environment variables are set for a process, settings with the same names fromappSettings
block of web.config are ignored.For ASP.NET Core applications hosted in IIS, the service name and resource attributes can be configured using the
environmentVariables
block of the web.config file . For example:<environmentVariables> <environmentVariable name="OTEL_SERVICE_NAME" value="my-service-name" /> <environmentVariable name="OTEL_RESOURCE_ATTRIBUTES" value="deployment.environment=test,service.version=1.0.0" /> </environmentVariables>
After modifying the
web.config
file, restart IIS:Start-Process "iisreset.exe" -NoNewWindow -Wait
For .NET Framework applications, you can configure resource attributes in the
appSettings
block of the app.config file.<appSettings> <add key="OTEL_RESOURCE_ATTRIBUTES" value="deployment.environment=test,service.version=1.0.0" /> </appSettings>
You can also modify the
Environment
key in the Windows Registry for each Windows service.After modifying the app.config file or the Windows Registry, restart the service:
Restart-Service -Name "<your-windows-service-name>" -Force
If no data appears in APM, see Troubleshoot .NET instrumentation for Splunk Observability Cloud.
Note
If you need to add custom attributes to spans or want to manually generate spans and metrics, instrument your .NET application or service manually. See Manually instrument .NET applications for Splunk Observability Cloud.
Linux π
Check that you meet the requirements. See OpenTelemetry .NET instrumentation compatibility and requirements.
(Optional) If needed, uninstall the SignalFx Instrumentation for .NET. See Uninstall the SignalFx Instrumentation for .NET.
Download and install the installation script of the Splunk Distribution of OpenTelemetry .NET from the Releases page on GitHub . For example:
curl -sSfL https://github.com/signalfx/splunk-otel-dotnet/releases/latest/download/splunk-otel-dotnet-install.sh -O # Install the distribution sh ./splunk-otel-dotnet-install.sh
Activate the automatic instrumentation:
# Activate the automatic instrumentation . $HOME/.splunk-otel-dotnet/instrument.sh
Set the environment and service version resource attributes:
export OTEL_RESOURCE_ATTRIBUTES='deployment.environment=<envtype>,service.version=<version>'
Run your application.
If no data appears in APM, see Troubleshoot .NET instrumentation for Splunk Observability Cloud.
Note
If you need to add custom attributes to spans or want to manually generate spans, instrument your .NET application or service manually. See Manually instrument .NET applications for Splunk Observability Cloud.
Activate AlwaysOn Profiling π
To activate AlwaysOn Profiling, set the SPLUNK_PROFILER_ENABLED
environment variable to true
.
To activate memory profiling, set the SPLUNK_PROFILER_MEMORY_ENABLED
environment variable to true
after activating AlwaysOn Profiling.
See Get data into Splunk APM AlwaysOn Profiling for more information. For more settings, see .NET OTel settings for AlwaysOn Profiling.
Configure the instrumentation π
For advanced configuration of the .NET automatic instrumentation, like changing trace propagation formats or changing the endpoint URLs, see Configure the Splunk Distribution of OpenTelemetry .NET.
Database Query Performance settings π
Starting from version 1.4.0, the .NET OTel instrumentation collects database queries for Database Query Performance. See Monitor Database Query Performance.
SQL statements might contain sensitive information. To configure this behavior, see OTEL_DOTNET_AUTO_SQLCLIENT_SET_DBSTATEMENT_FOR_TEXT
and OTEL_DOTNET_AUTO_ENTITYFRAMEWORKCORE_SET_DBSTATEMENT_FOR_TEXT
in Instrumentation settings.
Install the OpenTelemetry .NET instrumentation using the NuGet packages π
You can deploy the Splunk Distribution of OpenTelemetry .NET instrumentation automatically through the official NuGet packages. The project of your instrumented application must support NuGet packages.
Use the NuGet package in the following scenarios:
You control the application build but not the machine or container where the application is running.
Youβre instrumenting a self-contained application. See Publish self-contained in the .NET documentation.
You want to facilitate developer experimentation with automatic instrumentation through NuGet packages.
You need to solve version conflicts between the dependencies used by the application and the automatic instrumentation.
Instrument your application using the NuGet packages π
To automatically instrument your application using the NuGet packages, add the Splunk.OpenTelemetry.AutoInstrumentation
package to your project. For example:
dotnet add [<PROJECT>] package Splunk.OpenTelemetry.AutoInstrumentation --prerelease
If the build fails and prompts you to add missing instrumentation packages, add the instrumentation package or skip the instrumentation of the listed package by adding it to the SkippedInstrumentation
property. For example:
<PropertyGroup>
<SkippedInstrumentations>MongoDB.Driver.Core;StackExchange.Redis</SkippedInstrumentations>
</PropertyGroup>
You can also set the SkippedInstrumentation
property from the terminal. Rewrite the ;
separator as %3B
. For example:
dotnet build -p:SkippedInstrumentations=StackExchange.Redis%3BMongoDB.Driver.Core
To distribute the appropriate native runtime components with your .NET application, specify a Runtime Identifier (RID) to build the application using dotnet build
or dotnet publish
.
Both self-contained and framework-dependent applications are compatible with automatic instrumentation. See .NET application publishing overview in the .NET documentation for more information.
Run the instrumented application π
Use the script in the output folder of the build to run the application with automatic instrumentation activated.
On Windows, use
splunk-launch.cmd <application_executable>
.On Linux, use
splunk-launch.sh <application_executable>
.
If you run the application using the dotnet
CLI, add dotnet
after the script.
On Windows, use
splunk-launch.cmd dotnet <application>
.On Linux, use
splunk-launch.sh dotnet <application>
.
The script passes all the command-line parameters you provide to the application.
Instrument an application running within a Docker container π
An example of a Dockerfile that instruments a .NET application running inside a Docker container is available in the splunk/observability-content-contrib repository on GitHub.
Instrument Azure Web Apps π
To instrument applications or services running on Azure Web Apps, see Instrument .NET Azure Web App for Splunk Observability Cloud.
Offline installation for Windows π
To install the .NET automatic instrumentation on Windows hosts that are offline, follow these steps:
Download the following files from the Releases page on GitHub and copy them to the offline server:
Splunk.OTel.DotNet.psm1
splunk-opentelemetry-dotnet-windows.zip
Import the PowerShell script manually by running the following command:
# Make sure the Download path is correct Import-Module C:\Users\Administrator\Downloads\Splunk.OTel.DotNet.psm1
When prompted, enter
R
forRun Once
.Run the install command:
# Make sure the Download path is correct Install-OpenTelemetryCore -LocalPath "C:\Users\Administrator\Downloads\splunk-opentelemetry-dotnet-windows.zip"
Send data directly to Splunk Observability Cloud π
By default, all telemetry is sent to the local instance of the Splunk Distribution of OpenTelemetry Collector.
To bypass the OTel Collector and send data directly to Splunk Observability Cloud, set the following environment variables:
$env:SPLUNK_ACCESS_TOKEN=<access_token>
$env:SPLUNK_REALM=<realm>
export SPLUNK_ACCESS_TOKEN=<access_token>
export SPLUNK_REALM=<realm>
To obtain an access token, see Retrieve and manage user API access tokens using Splunk Observability Cloud.
To find your Splunk realm, see Note about realms.
Specify the source host π
To override the host used by the agent, use the environment variable OTEL_RESOURCE_ATTRIBUTES
to set your hostβs name to the desired source:
export OTEL_RESOURCE_ATTRIBUTES=host.name=<host_name>
$env:OTEL_RESOURCE_ATTRIBUTES=host.name=<host_name>
Uninstall the .NET instrumentation π
To deactivate and uninstall the .NET instrumentation, run the following commands:
# Run the unregister command for your situation
Unregister-OpenTelemetryForIIS
Unregister-OpenTelemetryForWindowsService
Unregister-OpenTelemetryForCurrentSession
# Uninstall OpenTelemetry for .NET
Uninstall-OpenTelemetryCore
rm -rf <path_of_otel_dotnet_install>