LogicMonitor seeks to disrupt AI landscape with $800M strategic investment at $2.4B valuation to revolutionize data centers.

Learn More

Automatic Instrumentation using the OpenTelemetry Operator for Applications in Kubernetes

Last updated on 07 November, 2024

When instrumenting an application in your Kubernetes infrastructure, you can leverage OpenTelemetry’s operator for Kubernetes. This allows you to automatically instrument your application by deploying the operator, defining an instrumentation resource, and then using an annotation to inject that instrumentation for your application containers.

Use OpenTelemetry Operator for Kubernetes from OpenTelemetry along with the following information to use OpenTelemetry’s operator.

Automatically Instrumenting an Application using the OpenTelemetry Operator

  1. Deploy OpenTelemetry’s Operator using Getting Started from OpenTelemetry.
  2. Define a custom instrumentation resource by providing sampling preferences, the LM OTEL Collector endpoint, and resource attributes to map traces to the correct monitored infrastructure in LogicMonitor to create a custom instrumentation resource similar to the following:
kind: Instrumentation

metadata:

  name: my-instrumentation

spec:

  env:

  - name: OTEL_POD_IP

    valueFrom:

      fieldRef:

        fieldPath: status.podIP

  exporter:

    endpoint: http://mylmotelcollector.endpoint/

  resource:

    addK8sUIDAttributes: true

    resourceAttributes:

{     "resource.type" : "kubernetes-pod",     "ip" : "$(OTEL_POD_ID)"     }

  propagators:

    - tracecontext

    - baggage

    - b3

  sampler:

    type: parentbased_traceidratio

    argument: "0.25"
  1. Apply the pod annotation to pods running applications for automatic instrumentation. This injects the auto instrumentation agent as an init container that downloads the JAR and makes it accessible to the application at startup. For example, you can patch your application deployment using the following:
kubectl patch deployment my-deployment -p '{"spec": {"template":{"metadata":{"annotations":{"instrumentation.opentelemetry.io/inject-java":"my-instrumentation"}}}} }'
In This Article