Automatic
Instrumenting Go

Auto-Instrumentation for Go

Signals

By default, you will get traces from many Go packages without any additional configuration. To also export logs and custom metrics, see Go semi-automatic instrumentation.

Go uses a privileged sidecar container to implement auto-instrumentation. This may be a restriction in some Kubernetes environments. The instrumentation container must run in a privileged mode to monitor your Go application. If this is restricted in your environment, manual instrumentation is the best practice. While the pod must be privileged, your application containers can still run in a more restricted manner.

Additionally, the shareProcessNamespace: true setting must be included to ensure that the containers all share a single operating system namespace, allowing one container to monitor the other.

Two annotations required are shown below, as well as the additional permission settings.

Note: It is important that the attribute is applied to the pod template, and not the Deployment, StatefulSet, or DaemonSet.

apiVersion: apps/v1
kind: Deployment
metadata:
  name: your-go-app-name
  labels:
    ...
spec:
  selector:
    matchLabels:
      ...
  template:
    shareProcessNamespace: true
    securityContext:
      runAsNonRoot: false
    metadata:
      labels:
        ...
      annotations:
        instrumentation.opentelemetry.io/inject-go: opentelemetry-operator/auto-instrumentation
        instrumentation.opentelemetry.io/otel-go-auto-target-exe: /app/bin/your-go-app-binary
...

For more information, see the opentelemetry-go-instrumentation (opens in a new tab) documentation.