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.

Enabling .NET tracing

Enable .NET tracing on Kubernetes by using one of the following methods:

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:

  1. Install the Instana agent on Kubernetes. See Installing the Instana agent on Kubernetes.
  2. 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=true

    For 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.
  3. If you want to selectively enable tracing for specific applications, you can use the opt-in mode:

    1. Enable an opt-in mode during AutoTrace webhook installation:

      --set autotrace.opt_in=true
    2. 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, set instana-autotrace: "false".
  4. Deploy and run your application.

The AutoTrace webhook automatically injects the required environment variables and instrumentation into your .NET application pods.

Note: The Instana AutoTrace webhook cannot automatically update the instrumentation. Therefore, you must manually update it by uninstalling the previous instrumentation and then reinstalling the webhook by using Helm deployment for any updates in the instrumentation. For more information, see Updating AutoTrace webhook.

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:

  1. 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.exe available: Restore the packages by using nuget.exe without compiling the project that is to be instrumented.
    • nuget.exe unavailable: Download the packages directly, extract them, and then set the environment variables to point to the extracted files as described in the following step.
  2. 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.

  3. Deploy and run your application.