Setting up .NET tracing on Linux or Alpine Linux
You can set up .NET tracing on Linux by using Instana AutoTrace or by manually configuring the environment variables. On .NET Core sensor 1.0.56 and later, .NET Tracer supports host auto tracing on Linux systems except containers.
For details about the working of .NET monitoring, see How .NET monitoring works.
Before you begin
To set up .NET Core tracing on Linux, complete the following prerequisites:
- Ensure that the Instana agent is running on the host machine. See Prerequisites for .NET Core monitoring and Installing the host agent on Linux.
- Install .NET Core sensor 1.0.56 or later.
- Check support information.
Running .NET applications on Linux
If you are not familiar with deploying .NET applications on Linux, follow these steps to set up and run your application.
Step 1: Install .NET SDK
Depending on your requirements, you can install the .NET SDK in one of the following environments:
- WSL (Windows Subsystem for Linux): For development and debugging
- Linux machine: For production environments
To install .NET SDK 8.0 on Ubuntu 22.04, run the following command:
wget https://packages.microsoft.com/config/ubuntu/22.04/packages-microsoft-prod.deb -O packages-microsoft-prod.deb
sudo dpkg -i packages-microsoft-prod.deb
sudo apt-get update
sudo apt-get install -y dotnet-sdk-8.0
Step 2: Run the .NET application
You can run your .NET application by using one of the following methods:
-
Direct run:
dotnet run --project /home/username/Applications/WebAPI.Linux/WebAPI.Linux.csproj -
Run with Kestrel: Go to the
Publishfolder and run the DLL:cd /home/username/Publish/WebAPI.Linux dotnet WebAPI.Linux.dll
Enabling .NET tracing
Enable .NET tracing on Linux by using one of the following methods:
Method 1: Enabling auto-tracing
With Instana AutoTrace, Instana automatically detects and instruments your .NET application. You don't need to change any code.
To enable Instana AutoTrace, complete the following steps:
- After you install the host agent, start the agent.
- Start your .NET application.
During the discovery startup, the sensor automatically enables the tracing. You don't need to manually inject the NuGet package and compile the application.
During the discovery process, the instana_dotnet_global_env.sh file is created. This file contains the environment variables that are required for .NET Core tracing.
To verify whether tracing is working, log in to your Instana dashboard. You can see traces appearing.
Method 2: Enabling tracing manually
Use this method if you don't want to use auto-tracing or if you need more control over the setup. This approach involves adding NuGet packages to your application.
Tracing applications running on Linux (except Alpine Linux)
To enable tracing manually in a .NET Core application running on Linux, complete the following steps:
-
After you install the host agent, install the following packages in your application:
Instana.Tracing.Core- For x64 (AMD64) architecture:
Instana.Tracing.Core.Rewriter.Linux - For ARM64 architecture:
Instana.Tracing.Core.Rewriter.Glibc.Arm64
When the packages are distributed through NuGet.org, you can install them without recompiling the application. Use one of the following methods:
nuget.exeavailable: Restore the packages by usingnuget.exewithout compiling the project that is to be instrumented.nuget.exeunavailable: Download the packages directly, extract them, and then set the environment variables to point to the extracted files as described in the following step.
Note: Select the appropriate rewriter package based on your system architecture. You can add theInstana.Tracing.Core.Rewriter.Linuxpackage to your project or add it before publishing. -
Set the following environment variables in the
Web.configfile of your application before you start your process:DOTNET_STARTUP_HOOKS=[path-to-your-app]/Instana.Tracing.Core.dll CORECLR_ENABLE_PROFILING=1 CORECLR_PROFILER={cf0d821e-299b-5307-a3d8-b283c03916dd} CORECLR_PROFILER_PATH=[Path_to_your_app]/instana_tracing/CoreProfiler.soReplace
[path-to-your-app]with the actual path to your application directory. -
If your application is running inside a container, define the agent environment variables so that the .NET Tracer knows where to look for the agent and send spans at runtime:
INSTANA_AGENT_HOST=[address_where_the_agents_listens_and_is_reachable_from_inside_the_container] INSTANA_AGENT_PORT=42699Use a different port if configured differently.
Tracing applications running on Alpine Linux
To enable tracing for applications running on Alpine Linux, complete the following steps:
-
After you install the host agent, install the following packages in your application:
Instana.Tracing.Core- For x64 (AMD64) architecture:
Instana.Tracing.Core.Rewriter.Alpine - For ARM64 architecture:
Instana.Tracing.Core.Rewriter.Alpine.Arm64
Note:- If the packages are available on NuGet.org, you can download them by using the
nuget.exefile, if available, without compiling the project. Alternatively, you can manually download these packages, extract them, and then set the environment variables to point to the extracted files as described in the following step. - Select the appropriate rewriter package based on your system architecture. You can add the
Instana.Tracing.Core.Rewriter.Windowspackage to your project or add it before publishing.
-
Set the following environment variables before you start your process:
DOTNET_STARTUP_HOOKS=[path-to-your-app]/Instana.Tracing.Core.dll CORECLR_ENABLE_PROFILING=1 CORECLR_PROFILER={cf0d821e-299b-5307-a3d8-b283c03916dd} CORECLR_PROFILER_PATH=[Path_to_your_app]/instana_tracing/CoreProfiler.so -
If your application is running inside a container, define the agent environment variables:
INSTANA_AGENT_HOST=[address_where_the_agents_listens_and_is_reachable_from_inside_the_container] INSTANA_AGENT_PORT=42699