How do you instrument a Kubernetes cluster so every new pod gets tracing automatically?
IntermediateScenarioTracing and OpenTelemetry
Answer
Situation read → You want platform-level defaults, not per-team effort.
What I'd do →
- Install the OpenTelemetry Operator (needs cert-manager).
- Create an
Instrumentationresource with exporter endpoint, propagators and sampler. - Teams opt in with an annotation such as
instrumentation.opentelemetry.io/inject-java: "true"(also-python,-nodejs,-dotnet,-go). - Use the
k8sattributesprocessor in the Collector to add pod, namespace and deployment metadata.
apiVersion: opentelemetry.io/v1alpha1
kind: Instrumentation
metadata: {name: default}
spec:
exporter: {endpoint: http://otel-collector.observability:4317}
propagators: [tracecontext, baggage]
sampler: {type: parentbased_traceidratio, argument: "0.1"}
Why → Annotation-based injection gives tracing without image or code changes.
Interview tip → Mention that Go injection uses eBPF and needs elevated privileges.
More on Tracing and OpenTelemetry
Your company has 30 microservices and no tracing. How do you roll out distributed tracing?IntermediateTraces stop at service B: you see spans from A, but B's spans start new traces. What is wrong?BeginnerTracing every request costs too much. How do you design sampling?IntermediateYou set up tail sampling with 4 Collector replicas, but traces are fragmented and error traces are missing. Why?AdvancedA checkout request takes 4 seconds. Walk through how you use a trace to find the cause.BeginnerYour OpenTelemetry Collector is getting OOMKilled under load. How do you stabilise it?Intermediate