Kubernetes Auto-instrumentation

Introduction

The auto-instrumentation feature is built on top of the The OpenTelemetry (OTel) Kubernetes Operator. It enables the agent to automatically detect and instrument all .NET, Java, Node.js, Python, and Go services. The auto-instrumentation feature allows you to:

  1. Automatically collect metrics from all applications (regardless of the language) across your cluster.
  2. Enable/disable instrumentation per namespace or application.
  3. Manage instrumentation through a user-friendly UI.
  4. Apply changes without manual configuration.

Prerequisites

1 Kubernetes Version

Kubernetes version 1.21.0 or above. Check with the following command:

2 Middleware Kubernetes Agent

Install the Middleware Kubernetes agent using these instructions. Check that the agent is installed with the following command:

Setup auto-instrumentation

You must have installed the Middleware Middleware’s Kubernetes Agent before setting up auto-instrumentation.

Installation

You can enable auto-instrumentation using either helm or bash.

Helm
Bash

You must install the cert-manager alongside the Operator. This is not be compulsory if you already have the cert-manager installed, or have alternative methods of generating certificates in your Kubernetes cluster. Choose either option that suits you below.

With cert-manager
Without cert-manager

You can configure namespace inclusion/exclusion when installing the Helm chart:

a. Include specific namespaces:

Only the specified namespaces will be monitored for auto-instrumentation.

b. Exclude specific namespaces:

All namespaces except the specified ones will be monitored (system namespaces are automatically excluded).

In most of cases, you will need to install cert-manager along with the Operator, unless you already have cert-manager installed or have alternative methods of generating certificates in your Kubernetes cluster.

With cert-manager
Without cert-manager

You can configure namespace inclusion/exclusion using environment variables when installing script:

a. Include specific namespaces:

Only the specified namespaces will be monitored for auto-instrumentation.

b. Exclude specific namespaces:

All namespaces except the specified ones will be monitored (system namespaces are automatically excluded).

Also You can modify this auto-instrumentation file to customize OpenTelemetry settings.

Configuring Auto-instrumentation

Application Selection

  1. Go to the "Choose Target Application" section in the Kubernetes agent installation screen:

    • View automatically detected applications and their languages.
    • Enable or disable instrumentation for specific applications.
    • Use "Select All" to toggle instrumentation for all detected applications.
    AutoInstrumentation
  2. For each application, you can see:

    • Application name.
    • Workload type (Deployment, StatefulSet or Daemonset).
    • Programming language (automatically detected).
    • Current instrumentation status.

Applying Changes

Auto-instrumentation applies to Deployments, DaemonSets, and StatefulSets. Ensure your application uses one of these resource types.

After making changes to your instrumentation configuration:

  1. Click "Save Changes" to apply your configuration.

  2. Restart the affected applications for the changes to take effect. Example:-

Core Components

  1. OpenTelemetry Operator: The foundation of the auto-instrumentation system

    • Manages the lifecycle of OpenTelemetry instrumentation.
    • Handles the injection of instrumentation agents.
    • Integrated as a dependency in the Middleware Helm chart.
  2. Middleware-Specific Components:

    • Language Detector: Automatically identifies the programming language of your applications.
    • Auto-injector Webhook: Mutates pod specifications to add necessary instrumentation annotations.

These components work together to:

  • Detect application languages automatically.
  • Apply appropriate instrumentation configurations.
  • Manage the lifecycle of instrumentation agents.
  • Provide visibility through the Middleware UI.

Verification

To verify that auto-instrumentation is working:

  1. Check the auto-instrumentation pods:
  1. Check the detected applications in the Middleware UI. Verify that they are enabled and have been restarted.
  2. Check application logs for instrumentation messages.
  3. Monitor your applications in the Middleware APM section.

If your application has special requirements and you need custom instrumentation settings, or just want total control over the instrumentation of apps in your kubernetes clusters, it is best to use manual configuration. See the customization page for details on how to manually configure instrumentation.

Explore your data on Middleware

Once the auto-instrumentation setup is complete and the relevant Pods are restarted, the data should start flowing to Middleware for any new requests made to your applications. You can explore APM traces data by going to the APM section of your Middleware account.

Uninstall

Helm
Bash

Uninstall cert-manager and middleware autoinstrumentation setup

This will remove the mw resources , OTel Kubernetes Operator AND cert-manager (including one you installed previously) from your cluster. Ensure that this is what you want to do.

Uninstall only middleware autoinstrumentation setup

If you wish to keep cert-manager and only uninstall middleware autoinstrumentation setup, issue the command below

Uninstall cert-manager and middleware autoinstrumentation setup

This will remove the mw resources , OTel Kubernetes Operator AND cert-manager (including one you installed previously) from your cluster. Ensure that this is what you want to do.

Uninstall only middleware autoinstrumentation setup

If you wish to keep cert-manager and only uninstall OTel Kubernetes Operator, issue the command below

Using Google Kubernetes Engine

If you are using GKE private cluster, you must add a firewall rule that allows your GKE control plane CIDR block access to port 9443/tcp on worker nodes.

Use the command below to find out GKE control plane CIDR block

  • Replace <CLUSTER_NAME> with the name of your cluster.
  • Replace <REGION> with the region of your cluster.

For example,

Then you can add a firewall rule to allow ingress from this IP range and TCP port 9443 using command below

<GKE_CONTROL_PLANE_CIDR> and <GKE_CONTROL_PLANE_TAG> can be found by following the steps in the GKE firewall docs.

More information can be found in the Official GCP Documentation. See the GKE documentation on adding rules and the Kubernetes issue for more detail.

Any issues?

If you encounter any challenges, check our troubleshooting page for how to fix them.

If you encounter any problems not listed on our troubleshooting page, please contact Middleware support on Slack. Include your debug logs and config info (with sensitive information removed)

Additional Resources