Setting up .NET tracing on Kubernetes
You can set up .NET tracing on Kubernetes by using the Instana AutoTrace webhook or by manually configuring the environment variables. The Instana AutoTrace webhook automatically sets up everything that is required to monitor .NET applications across an entire Kubernetes cluster.
For details about the working of .NET monitoring, see How .NET monitoring works.
Before you begin
To set up .NET Core tracing on Kubernetes, complete the following prerequisites:
- Ensure that the Instana agent is installed on Kubernetes. See Installing the Instana agent on Kubernetes.
- If the .NET application and the Instana agent are managed by Kubernetes, see Kubernetes network access for information about the required configuration.
- Check support information.
Enabling .NET tracing
Enable .NET tracing on Kubernetes by using one of the following methods:
- AutoTrace webhook (suggested)
- Manual tracing
Method 1: Enabling auto-tracing with AutoTrace webhook
The Instana AutoTrace webhook is an implementation of a Kubernetes Mutating Webhook Admission Controller. It automatically sets up everything that is required to monitor .NET applications with Instana across an entire Kubernetes cluster.
If the Instana AutoTrace webhook is installed on the Kubernetes cluster, tracing is automatically enabled for the .NET applications that run in those clusters.
To enable the Instana AutoTrace webhook, complete the following steps:
- Install the Instana agent on Kubernetes. See Installing the Instana agent on Kubernetes.
-
Install the Instana AutoTrace webhook on Kubernetes clusters by using Helm. Ensure that .NET Core tracing is enabled during installation:
--set autotrace.instrumentation.manual.netcore=trueFor more information, see Installing AutoTrace webhook.
Note: If .NET Core tracing is enabled, do not disable the other tracers (Python, Node.js, and Ruby). Disabling these tracers might affect the .NET Core tracing function. -
If you want to selectively enable tracing for specific applications, you can use the opt-in mode:
-
Enable an opt-in mode during AutoTrace webhook installation:
--set autotrace.opt_in=true - Add the
instana-autotrace: "true"label to the resources that you want to instrument. You can add this label at the required pods, replica sets, stateful sets, daemon sets, and deployments. If you want to exclude it from instrumentation, setinstana-autotrace: "false".
-
- Deploy and run your application.
The AutoTrace webhook automatically injects the required environment variables and instrumentation into your .NET application pods.
Method 2: Enabling tracing manually
If you prefer not to use the AutoTrace webhook or need more control over the setup, you can manually configure tracing by adding environment variables to your deployment.
To enable tracing manually for a .NET Core application on Kubernetes, complete the following steps:
-
Install the following NuGet packages in your application:
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.
-
Add the following environment variables to your Kubernetes deployment YAML:
apiVersion: apps/v1 kind: Deployment metadata: name: my-dotnet-app spec: replicas: 1 selector: matchLabels: app: my-dotnet-app template: metadata: labels: app: my-dotnet-app spec: containers: - name: my-dotnet-app image: my-dotnet-app:latest env: - name: DOTNET_STARTUP_HOOKS value: "[path-to-your-app]/Instana.Tracing.Core.dll" - name: CORECLR_ENABLE_PROFILING value: "1" - name: CORECLR_PROFILER value: "{cf0d821e-299b-5307-a3d8-b283c03916dd}" - name: CORECLR_PROFILER_PATH value: "[Path_to_your_app]/instana_tracing/CoreProfiler.so" - name: INSTANA_AGENT_HOST valueFrom: fieldRef: fieldPath: status.hostIP - name: INSTANA_AGENT_PORT value: "42699"Replace
[path-to-your-app]with the actual paths to your application directory. - Deploy and run your application.