Skip to content

fix(tracing): clear empty sampling rules without logging an error - #20872

Open
ebar0n wants to merge 5 commits into
DataDog:mainfrom
ebar0n:fix/apm-tracing-rc-keep-active-configs
Open

ebar0n wants to merge 5 commits into
DataDog:mainfrom
ebar0n:fix/apm-tracing-rc-keep-active-configs

Conversation

@ebar0n

@ebar0n ebar0n commented Oct 8, 2026 •

Copy link
Copy Markdown

Description

When Remote Configuration removes trace sampling rules and no local rules are configured, the sampler receives an empty string and logs Failed to apply all sampling rules while clearing the rules.

Treat the empty string as an empty rule list before the existing processing loop. This skips JSON decoding for an unset value and keeps the shared validation and sorting path. Addresses the remaining error-log case in #20871.

Customer impact

Removing remote trace sampling rules restores default sampling without an erroneous JSON parsing error in application logs.

Testing

  • One parameterized regression test checks that both an empty string and an empty JSON list clear existing rules without logging an error.
  • Confirmed the empty-string case fails without the fix.
  • All 234 sampler tests pass on Python 3.12.13 through scripts/run-tests.
  • scripts/lint checks passes.

Tests ran locally on macOS using released native dependencies and a local APM test Agent. The Docker run was blocked by storage I/O errors.

Risks

Low. Nonempty input retains its existing JSON validation, partial-rule handling, and precedence ordering.

Additional Notes

Active remote configuration retention is already fixed by #21208. This update keeps that implementation and its tests, and focuses on the remaining empty-rule error.

Closes: #22417

The remote config client dispatches only the configs that changed since
the last poll, but APMTracingCallback rebuilt its config map from each
call's payloads alone. Any dispatch that did not include the config
carrying tracing_sampling_rules (another service's config, a removal)
merged to a lib_config without rules, which reset the remote sampling
rules to the default "" and logged
"Failed to apply all sampling rules. Rules=, Applied=[]".

Keep the active configs on the callback instance, drop configs that are
removed or retargeted away from this service/env, and treat an empty
sampling rules value as "no rules" instead of invalid JSON.

Fixes DataDog#20871

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
@ebar0n
ebar0n requested review from a team as code owners October 8, 2026 06:14
@ebar0n
ebar0n requested review from juanjux and mabdinur and removed request for a team October 8, 2026 06:14
@chatgpt-codex-connector

Copy link
Copy Markdown

Codex usage limits have been reached for code reviews. Please check with the admins of this repo to increase the limits by adding credits.
Credits must be used to enable repository wide code reviews.

Comment thread ddtrace/_trace/sampler.py Outdated
sampling_rules = []
if not rules or not rules.strip():
# An empty value means no rules, e.g. after remote configuration unsets them.
self.rules = sampling_rules

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

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

Why not apply the same sorting logic used on L170?

Copy link
Copy Markdown
Author

Choose a reason for hiding this comment

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

Good point, done in e0d1ed5: the empty value now skips only the JSON parsing and falls through to the same sorted(...) assignment as every other path, so there's no separate early return. Behavior is unchanged (an empty value still yields self.rules == [] without logging an error), and the existing test covers it.

@ebar0n
ebar0n requested a review from a team as a code owner October 14, 2026 21:59
@gh-worker-ownership-write-b05516
gh-worker-ownership-write-b05516 Bot removed the request for review from a team December 4, 2026 18:27
@mabdinur mabdinur changed the title fix(tracing): keep active APM_TRACING configs across remote config dispatches fix(tracing): clear empty sampling rules without logging an error Dec 4, 2026

@datadog-datadog-us1-prod datadog-datadog-us1-prod 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.

Bits Code Review: PASS

More details

Empty sampling-rule values clear the rules without attempting JSON parsing and retain the shared sorting and assignment path. The static specialist reported no actionable regressions in the supplied diff.

Was this helpful? React 👍 or 👎

Open Bits AI session

🤖 Bits Code Review · Commit e88365a

@mabdinur mabdinur left a comment

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

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

Reviewed the current revision. Empty values use the shared rule-processing path, and the regression test covers clearing existing rules without logging errors. All 234 sampler tests and lint checks pass locally.

@datadog-datadog-us1-prod

datadog-datadog-us1-prod Bot commented Dec 4, 2026 •

Copy link
Copy Markdown

Pipelines

❌ Errors

Your PR has failed checks. Please review the issues below and take necessary action before merging.

🚦 2 Pipeline jobs failed

System Tests | tracer-release / End-to-end #1 / anthropic-py@0.84.0 1 — 🔧 Needs a code fix, caused by this PR

View more details · View in GitHub Actions

System Tests | system-tests finished

View more details · View in GitHub Actions

Useful? React with 👍 / 👎

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

@mabdinur
mabdinur enabled auto-merge (squash) December 4, 2026 18:41
Skip JSON decoding when remote sampling rules are unset. Reuse the existing rule processing path and cover empty strings and empty JSON lists with a parameterized regression test. Keep the active remote configuration handling already present on main.
Describe the remaining sampling rule removal error in a separate commit so changelog history can be scanned correctly.
@mabdinur
mabdinur force-pushed the fix/apm-tracing-rc-keep-active-configs branch from e88365a to a5fff67 Compare December 4, 2026 18:47

@datadog-datadog-us1-prod datadog-datadog-us1-prod 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.

Bits Code Review: PASS

More details

Empty sampling-rule values now bypass JSON decoding and use the shared rule-processing path, clearing existing rules without the erroneous parsing log. The completed static review found no actionable defects.

Was this helpful? React 👍 or 👎

Open Bits AI session

🤖 Bits Code Review · Commit a5fff67

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

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

4 participants