Automatic Instrumentation using the OpenTelemetry Operator for Applications in Kubernetes
Last updated on 07 November, 2024When 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
- Deploy OpenTelemetry’s Operator using Getting Started from OpenTelemetry.
- 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"
- 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"}}}} }'