Skip to content

APM: Fix pkg/trace log format-string bugs - #55049

Open
ajgajg1134 wants to merge 4 commits into
mainfrom
andrew.glaude/traceLogLint
Open

APM: Fix pkg/trace log format-string bugs#55049
ajgajg1134 wants to merge 4 commits into
mainfrom
andrew.glaude/traceLogLint

Conversation

@ajgajg1134

@ajgajg1134 ajgajg1134 commented Aug 18, 2026

Copy link
Copy Markdown
Contributor

What does this PR do?

Fix format-string bugs in pkg/trace and add github.com/DataDog/datadog-agent/pkg/trace/log to the govet printf funcs allowlist in .golangci.yml so this class of bug is caught by CI going forward.

Motivation

pkg/trace logger has printf style commands but the govet rule didn't know about this so there were a few spots where the printf directives were wrong

Describe how you validated your changes

  • dda inv linter.go --module=pkg/trace0 issues. / All linters passed (after all fixes; before the fixes it reported the 5 originally-known findings plus 2 additional %s-with-non-Stringer findings, all now fixed).
  • dda inv test --targets=./pkg/trace/agent,./pkg/trace/filters → all tests pass (403 tests, 3 pre-existing skips unrelated to this change).
  • git diff origin/main reviewed line-by-line to confirm the legacy *pb.Span code paths (normalize, Truncate) were left untouched — on pb.Span, Resource/Name are struct fields and the existing s.Resource/s.Name usages there are correct as-is.
  • dda inv linter.go --targets=./cmd/serverless-init,./comp/core/log/impl-trace,./comp/process/gpusubscriber/impl,./pkg/config/remote/uptane,./pkg/privateactionrunner/bundles/helm,./cmd/process-agent/subcommands/status0 issues. (sanity check that no other consumer of pkg/trace/log regressed).
  • Added a fixes: release note via reno new trace-log-printf-format-fixes.

Additional Notes

Why not DebugString()

*idx.InternalSpan does have a DebugString() helper, and it would satisfy the
verb — but it dumps every span attribute. Attributes are unbounded in size and can
carry request data (URLs, DB statements, custom tags), which makes them unsuitable
for a value interpolated into a log line that fires once per malformed span. Both
sites therefore log the identifying fields explicitly instead. DebugString()
remains available for interactive debugging.

@dd-octo-sts dd-octo-sts Bot added internal Identify a non-fork PR team/agent-apm trace-agent team/agent-devx labels Aug 18, 2026
@github-actions github-actions Bot added the medium review PR review might take time label Aug 18, 2026
chatgpt-codex-connector[bot]

This comment was marked as outdated.

@ajgajg1134
ajgajg1134 force-pushed the andrew.glaude/traceLogLint branch from 24eaac2 to 1501029 Compare August 18, 2026 14:29
@datadog-datadog-prod-us1

datadog-datadog-prod-us1 Bot commented Aug 18, 2026

Copy link
Copy Markdown
Contributor

🎯 Code Coverage (details)
Patch Coverage: 50.00%
Overall Coverage: 52.47% (+0.04%)

This comment will be updated automatically if new data arrives.
🔗 Commit SHA: e5743e2 | Docs | View more details | Give us feedback!

ajgajg1134 and others added 2 commits August 18, 2026 10:42
Five call sites passed the wrong argument to a printf-style
pkg/trace/log function: two passed a method value (s.Name, s.Resource)
instead of calling it (s.Name(), s.Resource()) on *idx.InternalSpan,
one passed a method value on the obfuscateSpan interface
(span.Resource), and two Errorf calls had a %v verb with no argument
at all, printing %!v(MISSING) instead of the unknown attribute type.

Enabling the govet check (next commit) also surfaced two sites in
normalizer.go where a %s verb was given a bare *idx.InternalSpan.
That type has no String() method, so the verb rendered the unexported
span pointer and string table as "%!s(*idx.Span=&{...})". Both now log
the identifying fields explicitly. DebugString() is deliberately not
used here: it dumps every span attribute, which is unbounded in size
and may carry request data, making it unsuitable for a log line.

These went undetected because pkg/trace/log was missing from the
govet printf funcs allowlist (fixed in the next commit).

Co-Authored-By: Claude Opus 5 (1M context) <[email protected]>
pkg/trace/log defines its own printf-style Tracef/Debugf/Infof/Warnf/
Errorf/Criticalf wrappers, separate from pkg/util/log, but was absent
from govet's printf funcs list. That meant govet never checked format
strings in any log.Xf call across the entire pkg/trace tree, letting
the bugs fixed in the previous commit go undetected in CI.

Co-Authored-By: Claude Opus 5 (1M context) <[email protected]>
@ajgajg1134
ajgajg1134 force-pushed the andrew.glaude/traceLogLint branch from 1501029 to 76470ac Compare August 18, 2026 14:42
@ajgajg1134 ajgajg1134 changed the title Fix pkg/trace log format-string bugs and add pkg/trace/log to govet allowlist APM: Fix pkg/trace log format-string bugs Aug 18, 2026
@ajgajg1134
ajgajg1134 marked this pull request as ready for review August 18, 2026 14:48
@ajgajg1134
ajgajg1134 requested review from a team as code owners August 18, 2026 14:49
@ajgajg1134 ajgajg1134 added the qa/done QA done before merge and regressions are covered by tests label Aug 18, 2026

@chatgpt-codex-connector chatgpt-codex-connector Bot left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

💡 Codex Review

Here are some automated review suggestions for this pull request.

Reviewed commit: 69c585bb22

ℹ️ About Codex in GitHub

Codex has been enabled to automatically review pull requests in this repo. Reviews are triggered when you

  • Open a pull request for review
  • Mark a draft as ready
  • Comment "@codex review".

If Codex has suggestions, it will comment; otherwise it will react with 👍.

When you sign up for Codex through ChatGPT, Codex can also answer questions or update the PR, like "@codex address that feedback".

Comment thread pkg/trace/agent/truncator.go

@anais-raison anais-raison left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

LGTM 👍

@dd-octo-sts

dd-octo-sts Bot commented Aug 18, 2026

Copy link
Copy Markdown
Contributor

Files inventory check summary

File checks results against ancestor 9f2fd1cb:

Results for datadog-agent_7.84.0~devel.git.273.e5743e2.pipeline.131653797-1_amd64.deb:

No change detected

Results for datadog-iot-agent_7.84.0~devel.git.273.e5743e2.pipeline.131653797-1_amd64.deb:

No change detected

@dd-octo-sts

dd-octo-sts Bot commented Aug 18, 2026

Copy link
Copy Markdown
Contributor

Static quality checks

✅ Please find below the results from static quality gates
Comparison made with ancestor 9f2fd1c
📊 Static Quality Gates Dashboard
🔗 SQG Job
SOME SIZE DELTAS ARE N/A (ANCESTOR METRICS NOT YET AVAILABLE). RETRY JOB

Successful checks

Info

Quality gate Change Size (prev → curr → max)
agent_deb_amd64 N/A N/A → 760.347 → 764.600
agent_deb_amd64_fips N/A N/A → 713.239 → 715.840
agent_heroku_amd64 N/A N/A → 312.522 → 319.080
agent_rpm_amd64 N/A N/A → 760.331 → 764.570
agent_rpm_amd64_fips N/A N/A → 713.223 → 715.840
agent_rpm_arm64 N/A N/A → 736.130 → 737.130
agent_rpm_arm64_fips N/A N/A → 692.351 → 693.820
agent_suse_amd64 N/A N/A → 760.331 → 764.570
agent_suse_amd64_fips N/A N/A → 713.223 → 715.840
agent_suse_arm64 N/A N/A → 736.130 → 737.130
agent_suse_arm64_fips N/A N/A → 692.351 → 693.820
docker_agent_amd64 N/A N/A → 818.986 → 820.140
docker_agent_arm64 N/A N/A → 819.868 → 820.890
docker_agent_jmx_amd64 N/A N/A → 1009.884 → 1010.900
docker_agent_jmx_arm64 N/A N/A → 999.418 → 1000.570
docker_cluster_agent_amd64 N/A N/A → 211.151 → 212.130
docker_cluster_agent_arm64 N/A N/A → 224.206 → 225.220
docker_cws_instrumentation_amd64 N/A N/A → 7.443 → 8.400
docker_cws_instrumentation_arm64 N/A N/A → 6.877 → 7.110
docker_dogstatsd_amd64 N/A N/A → 39.463 → 40.440
docker_dogstatsd_arm64 N/A N/A → 37.560 → 38.580
docker_host_profiler_amd64 N/A N/A → 305.795 → 317.700
docker_host_profiler_arm64 N/A N/A → 317.104 → 328.970
dogstatsd_deb_amd64 N/A N/A → 30.204 → 31.210
dogstatsd_deb_arm64 N/A N/A → 28.236 → 29.590
dogstatsd_rpm_amd64 N/A N/A → 30.204 → 31.210
dogstatsd_suse_amd64 N/A N/A → 30.204 → 31.210
iot_agent_deb_amd64 N/A N/A → 46.467 → 47.550
iot_agent_deb_arm64 N/A N/A → 43.128 → 44.220
iot_agent_deb_armhf N/A N/A → 43.922 → 45.020
iot_agent_rpm_amd64 N/A N/A → 46.468 → 47.550
iot_agent_suse_amd64 N/A N/A → 46.467 → 47.550

@cit-pr-commenter-54b7da

cit-pr-commenter-54b7da Bot commented Aug 18, 2026

Copy link
Copy Markdown

Regression Detector

Regression Detector Results

Metrics dashboard
Target profiles
Job ID: c8d75e48-b5c2-4b0e-8e65-f8ddb9b3e102

Baseline: 3067dd1
Comparison: e5743e2
Diff

Optimization Goals: ✅ No significant changes detected

Fine details of change detection per experiment

perf experiment goal Δ mean % Δ mean % CI trials links
quality_gate_metrics_logs memory utilization +0.97 [+0.72, +1.23] 1 Logs bounds checks dashboard
quality_gate_logs % cpu utilization +0.84 [-0.05, +1.72] 1 Logs bounds checks dashboard
quality_gate_idle memory utilization +0.35 [+0.23, +0.47] 1 Logs bounds checks dashboard
quality_gate_security_idle memory utilization +0.23 [+0.13, +0.34] 1 Logs bounds checks dashboard
quality_gate_security_mean_fs_load memory utilization +0.06 [-0.01, +0.13] 1 Logs bounds checks dashboard
quality_gate_security_no_fs_load memory utilization -0.01 [-0.15, +0.13] 1 Logs bounds checks dashboard
quality_gate_idle_all_features memory utilization -0.13 [-0.17, -0.09] 1 Logs bounds checks dashboard
quality_gate_private_action_runner memory utilization -0.26 [-0.38, -0.13] 1 Logs bounds checks dashboard

Bounds Checks: ✅ Passed

perf experiment bounds_check_name replicates_passed observed_value links
quality_gate_idle intake_connections 10/10 4 = 4 bounds checks dashboard
quality_gate_idle memory_usage 10/10 172.34MiB ≤ 178MiB bounds checks dashboard
quality_gate_idle total_bytes_received 10/10 739.77KiB ≤ 819.20KiB bounds checks dashboard
quality_gate_idle_all_features intake_connections 10/10 4 = 4 bounds checks dashboard
quality_gate_idle_all_features memory_usage 10/10 515.50MiB ≤ 538MiB bounds checks dashboard
quality_gate_idle_all_features total_bytes_received 10/10 1.14MiB ≤ 1.25MiB bounds checks dashboard
quality_gate_logs intake_connections 10/10 18 ≤ 40 bounds checks dashboard
quality_gate_logs memory_usage 10/10 210.78MiB ≤ 229MiB bounds checks dashboard
quality_gate_logs missed_bytes 10/10 0B = 0B bounds checks dashboard
quality_gate_logs total_bytes_received 10/10 264.19MiB ≤ 292MiB bounds checks dashboard
quality_gate_metrics_logs cpu_usage 10/10 376.45 ≤ 2000 bounds checks dashboard
quality_gate_metrics_logs intake_connections 10/10 18 ≤ 40 bounds checks dashboard
quality_gate_metrics_logs memory_usage 10/10 404.72MiB ≤ 439MiB bounds checks dashboard
quality_gate_metrics_logs missed_bytes 10/10 0B = 0B bounds checks dashboard
quality_gate_metrics_logs total_bytes_received 10/10 0.94GiB ≤ 1.04GiB bounds checks dashboard
quality_gate_private_action_runner memory_usage 10/10 71.40MiB ≤ 76MiB bounds checks dashboard
quality_gate_security_idle cpu_usage 10/10 26.83 ≤ 100 bounds checks dashboard
quality_gate_security_idle memory_usage 10/10 327.19MiB ≤ 335MiB bounds checks dashboard
quality_gate_security_mean_fs_load cpu_usage 10/10 60.30 ≤ 200 bounds checks dashboard
quality_gate_security_mean_fs_load memory_usage 10/10 304.50MiB ≤ 314MiB bounds checks dashboard
quality_gate_security_no_fs_load cpu_usage 10/10 20.94 ≤ 100 bounds checks dashboard
quality_gate_security_no_fs_load memory_usage 10/10 313.55MiB ≤ 343MiB bounds checks dashboard

Explanation

Confidence level: 90.00%
Effect size tolerance: |Δ mean %| ≥ 5.00%

Performance changes are noted in the perf column of each table:

  • ✅ = significantly better comparison variant performance
  • ❌ = significantly worse comparison variant performance
  • ➖ = no significant change in performance

A regression test is an A/B test of target performance in a repeatable rig, where "performance" is measured as "comparison variant minus baseline variant" for an optimization goal (e.g., ingress throughput). Due to intrinsic variability in measuring that goal, we can only estimate its mean value for each experiment; we report uncertainty in that value as a 90.00% confidence interval denoted "Δ mean % CI".

For each experiment, we decide whether a change in performance is a "regression" -- a change worth investigating further -- if all of the following criteria are true:

  1. Its estimated |Δ mean %| ≥ 5.00%, indicating the change is big enough to merit a closer look.

  2. Its 90.00% confidence interval "Δ mean % CI" does not contain zero, indicating that if our statistical model is accurate, there is at least a 90.00% chance there is a difference in performance between baseline and comparison variants.

  3. Its configuration does not mark it "erratic".

CI Pass/Fail Decision

Passed. All Quality Gates passed.

  • quality_gate_logs, bounds check total_bytes_received: 10/10 replicas passed. Gate passed.
  • quality_gate_logs, bounds check missed_bytes: 10/10 replicas passed. Gate passed.
  • quality_gate_logs, bounds check intake_connections: 10/10 replicas passed. Gate passed.
  • quality_gate_logs, bounds check memory_usage: 10/10 replicas passed. Gate passed.
  • quality_gate_security_mean_fs_load, bounds check memory_usage: 10/10 replicas passed. Gate passed.
  • quality_gate_security_mean_fs_load, bounds check cpu_usage: 10/10 replicas passed. Gate passed.
  • quality_gate_security_no_fs_load, bounds check memory_usage: 10/10 replicas passed. Gate passed.
  • quality_gate_security_no_fs_load, bounds check cpu_usage: 10/10 replicas passed. Gate passed.
  • quality_gate_security_idle, bounds check memory_usage: 10/10 replicas passed. Gate passed.
  • quality_gate_security_idle, bounds check cpu_usage: 10/10 replicas passed. Gate passed.
  • quality_gate_idle, bounds check memory_usage: 10/10 replicas passed. Gate passed.
  • quality_gate_idle, bounds check intake_connections: 10/10 replicas passed. Gate passed.
  • quality_gate_idle, bounds check total_bytes_received: 10/10 replicas passed. Gate passed.
  • quality_gate_private_action_runner, bounds check memory_usage: 10/10 replicas passed. Gate passed.
  • quality_gate_metrics_logs, bounds check total_bytes_received: 10/10 replicas passed. Gate passed.
  • quality_gate_metrics_logs, bounds check intake_connections: 10/10 replicas passed. Gate passed.
  • quality_gate_metrics_logs, bounds check missed_bytes: 10/10 replicas passed. Gate passed.
  • quality_gate_metrics_logs, bounds check memory_usage: 10/10 replicas passed. Gate passed.
  • quality_gate_metrics_logs, bounds check cpu_usage: 10/10 replicas passed. Gate passed.
  • quality_gate_idle_all_features, bounds check total_bytes_received: 10/10 replicas passed. Gate passed.
  • quality_gate_idle_all_features, bounds check memory_usage: 10/10 replicas passed. Gate passed.
  • quality_gate_idle_all_features, bounds check intake_connections: 10/10 replicas passed. Gate passed.

@ajgajg1134

Copy link
Copy Markdown
Contributor Author

/merge

@gh-worker-devflow-routing-ef8351

gh-worker-devflow-routing-ef8351 Bot commented Aug 18, 2026

Copy link
Copy Markdown

View all feedbacks in Devflow UI.

2026-08-18 17:14:14 UTC ℹ️ Start processing command /merge


2026-08-18 17:14:21 UTC ℹ️ MergeQueue: Pull request is not mergeable yet

It will be processed automatically as soon as GitHub reports it as mergeable. View in MergeQueue UI.

  • Run /code blockers to see what is blocking it.
  • Run /remove to cancel it.

2026-08-18 21:42:06 UTC ⚠️ MergeQueue: This merge request was unqueued

devflow unqueued this merge request: It did not become mergeable within the expected time

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

internal Identify a non-fork PR medium review PR review might take time qa/done QA done before merge and regressions are covered by tests team/agent-apm trace-agent team/agent-devx

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants