[CONTP-2125] Add opt-in APM tracing for DDA and DDAI reconciles #3537
All Vouch review confidence checks passed
Residual risk 0.21 = Change Risk (0.52) × (1 − Review Confidence (0.60)).
Review depth and reviewer attention state are adequate.
Model 1 · Change Risk (XGBoost)
Score: 0.52 · 650 lines diff across 8 files
Model 2 · Review Depth (DistilBERT)
Depth Score: 0.17 · 1 substantive comment(s)
Model 3 · Review Timing & Attention
Session adequacy: 100% · Reviewer familiarity: 35%
Bedrock Claude 3 · Risk Narration
(disconnected)
Groq Risk Narration
AWS Bedrock is currently disconnected. Generate high-confidence PR triage narration on-demand using Groq.
Model 1 · Change Risk Attribution
SHAP Weights
Diff Size
diff_size
0.388
Shallow Review Depth
shallow_review_depth
0.289
Real PR Conversation Timeline
1 comments
"Review active on #3537"
general
weight: 0.35
khewonc
What does this PR do?
Adds opt-in APM tracing (dd-trace-go v2) to the DDA and DDAI reconcile loops.
--tracing-enabledorDD_TRACING_ENABLED=true. Off by default.datadogagent.reconcile/datadogagentinternal.reconcile, tagged withkind,name,namespaceandreconcileID.- DDA:
manageExperiment,manageRevision,reconcileProfiles,manageDDADependenciesWithDDAI,createOrUpdateDDAI,updateStatusIfNeeded- DDAI:
applyAndCleanupDependencies,reconcileComponent/Cleanup(taggedagent.component),reconcileV2Agent,cleanupExtraneousResources,updateStatusIfNeededDD_TRACE_HTTP_CLIENT_ERROR_STATUSES).ctrl.LoggerFrom(ctx)) includedd.trace_idand the current span'sdd.span_id, in dd-trace-go's trace ID format so they link to traces. Logs still written through the base logger (r.log) don't; moving them is tracked in CONTP-2142.managerunlessDD_SERVICEis set).Motivation
CONTP-2125. Existing metrics show total reconcile duration and error counts, but not which step inside a reconcile is slow or failing. Tracing breaks each reconcile into spans, including the Kubernetes API calls, so a slow or failed step can be found for a specific reconcile. This builds on the prototype in #2744.
Kubernetes audit IDs
The apiserver uses a client-supplied
Audit-IDheader verbatim as the request's audit ID, and generates a UUID per request when it is absent. The dd-trace-go client-go integration sets that header to the trace ID, which is fine when a trace makes one API call but not here: a reconcile is one trace making dozens, so every one of them would land in the audit log under a single ID, and a request's audit events could no longer be paired with its response.This PR wraps the transport directly instead and sets the header to
<trace ID>-<span ID>. The ID stays unique per request, and still identifies the reconcile that issued it, so the audit-log correlation the integration was built for is kept. The span keeps the integration'skubernetes.audit_idtag, set to the same value, for the reverse lookup. Verified on a kind cluster with audit logging: 23 API calls produced 23 distinct audit IDs with two audit events each, against 4 IDs covering up to 8 events before the change.Worth raising upstream separately, since it affects any dd-trace-go user making more than one API call per trace.
DatadogAgent log fields
Moving the reconcile logs onto the context logger is what carries the trace IDs, but it also pulls in controller-runtime's default fields, so the object is now reported three times on each line: nested
DatadogAgent, flatnamespace/name, and ourdatadogagent.Deduplicating means dropping one of those three names, and each option removes a log attribute that may be in use today — flat
namespace/nameon one side,@datadogagent.on the other. Renaming a shipped log attribute is out of scope here, so this PR leaves the duplication in place. CONTP-2162 covers picking one shape and applying it across all controllers, which today use three different ones (DDA, DDAI andDatadogGenericResourceall differ).The one thing this PR does fix is the
controllers.DatadogAgentlogger name, which the switch to the context logger had dropped, breakinglogger:controllers.DatadogAgentqueries. It is set inReconcilethe same wayDatadogAgentInternaldoes it.No log field is renamed or removed relative to
main. Reconcile lines gainreconcileID, the trace IDs when tracing is on, and controller-runtime's duplicate object fields.Additional Notes
DD_AGENT_HOST(e.g. fromstatus.hostIP),DD_TRACE_AGENT_URL, or the APM socket at/var/run/datadog/apm.socket. The Helm chart sets none of these.kube_cluster_namereaches spans as a host tag via the node Agent, so APM search by cluster works without the tracer duplicating it.Audit-IDheader is sent. The main cost is binary size.DD_TRACE_ENABLED=falseis set alongside--tracing-enabled, no spans are created and logs aren't tagged with trace IDs.DD_TRACE_128_BIT_TRACEID_LOGGING_ENABLEDis on (the default) and the ID has upper bits set. Otherwise they are 64-bit decimal, so pipelines that only parse decimal IDs still correlate.Minimum Agent Versions
Agent: N/A
Describe your test plan
pkg/tracecover spans, tags, errors, log fields, the transport, and a tracer that isn't running.TestWrapTransportasserts audit IDs are unique per request, prefixed with the trace ID, within the apiserver's 64-character limit, and absent on untraced requests; it fails against the previous transport wrapper.TestReconcileTracingruns a DDA → DDAI reconcile and checks the span tree.main, this branch, and tracing off. Confirmed no trace IDs or modified audit IDs with the flag off, and one audit ID per request with it on.datadog-operator.Checklist
bug,enhancement,refactoring,documentation,tooling, and/ordependenciesqa/skip-qalabel[1]: https://docs.github.com/en/authentication/managing-commit-signature-verification/signing-commits