Skip to content

chore(native): enforce a single libdatadog release tag across cargo manifests - #21692

Closed
dd-apm-ecosystems[bot] wants to merge 3 commits into
mainfrom
automated/lint-libdatadog-release-pins-2026-11-11
Closed

dd-apm-ecosystems[bot] wants to merge 3 commits into
mainfrom
automated/lint-libdatadog-release-pins-2026-11-11

Conversation

@dd-apm-ecosystems

Copy link
Copy Markdown

Description

Adds a small CI check that every Cargo.toml dependency on libdatadog pins a release tag (rev = "vX.Y.Z") and that all of them pin the same tag.

Theme: libdatadog crates are released together, and reviewers repeatedly ask that revs stay in sync and that a commit SHA is replaced by a release tag before merge.

Recurrence (all-time, distinct PRs): 2, both raised by a human maintainer (brettlangdon) and accepted by the PR author:

Related, not counted as recurrence: #21522 had a human ask "I'm not sure about the hash here instead of a released version", and #21346 and #21618 have similar open threads. I did not record those as occurrences yet because the thread is unresolved or the PR is still open.

Why it is mechanically detectable: the rule is a line-level property of Cargo.toml (git URL is DataDog/libdatadog, rev is a vX.Y.Z tag, and all tags agree). There is no semantic judgement involved.

Tool added vs extended: nothing existing fits. The repo has no cargo-deny or other Cargo policy config, ruff/ast-grep do not parse TOML, and scripts/check-dependency-bounds only reads pyproject.toml. I added one ~50-line bash script rather than a Python dependency, and wired it into the existing native CI file .gitlab/native.yml, next to rust ci, instead of creating a new pipeline.

Per the maintainer-feedback memory on a previous automation PR (#21010, comments 4292422565 and 4292434731, recorded as feedback_ids rst-in-private-docstrings|pr21010|4292422565 and ...|4292434731, implement_differently=1), this change is deliberately wired into a blocking CI job in the same PR and I looked for an existing tool first. I am not claiming this is the same theme; I applied the guidance to this implementation.

Testing

  • bash scripts/check-libdatadog-pins.sh on current main: OK: 21 libdatadog dependencies pinned to v48.0.0. No existing code is flagged, so there is no mass breakage.
  • Negative fixtures in throwaway git repos (also encoded in tests/internal/test_check_libdatadog_pins.py, 11 cases): SHA pin fails, short SHA fails, branch = fails, tag = key fails, mixed tags in one or across two manifests fail, .git URL suffix still checked, commented-out lines and unrelated git deps ignored, the opt-out marker exempts only its own line, no libdatadog deps is a silent no-op.
  • I ran the test functions with a minimal harness because pytest could not be installed in my sandbox (no network); I have not run them under the repo's real pytest/suitespec. ruff format and ruff check pass on the new test file.
  • I validated .gitlab/native.yml as YAML (with the !reference tag) but could not run the GitLab job itself.

Risks

  • False positives: a commit-pinned libdatadog dep is rejected. This is intended, but it will block PRs that legitimately need an unreleased libdatadog fix (for example feat(litellm): add usage and cost metrics for proxy calls #20892's libdd-ai-usage while waiting on a release). They can opt out per line with a trailing # libdatadog-pin: allow, which shows up in review.
  • Scope: only git = ".../DataDog/libdatadog" dependencies in tracked Cargo.toml files. Registry or path deps are not touched. Cargo.lock is not parsed.
  • Enforcement location: it runs in the GitLab tests stage (libdatadog pins job, needs: [], no rules: so it runs on every pipeline). It is not in the GitHub Actions on: pull_request set because my token could not create a .github/workflows file (403 on contents API). If you prefer it as a GitHub Action, the job body is one line: bash scripts/check-libdatadog-pins.sh.
  • Not wired yet: I did not add the script to scripts/lint / the prechecks generator / tests/suitespec.yml, so the unit test file will not auto-trigger when only the script changes. Happy to follow up.
  • Rollback: revert this PR; the job and the script are self-contained.

Additional Notes

@dd-apm-ecosystems
dd-apm-ecosystems Bot requested a review from a team November 11, 2026 23:36
@dd-apm-ecosystems
dd-apm-ecosystems Bot requested a review from a team as a code owner November 11, 2026 23:36
@dd-apm-ecosystems
dd-apm-ecosystems Bot requested review from juanjux and wantsui and removed request for a team November 11, 2026 23:36
@chatgpt-codex-connector

chatgpt-codex-connector Bot commented Nov 11, 2026 •

Copy link
Copy Markdown
Codex Review Summary: ✅ Completed

This comment shows the latest Codex review activity on this pull request.

Review Status Commit Review trigger
📝 Code Review ✅ Completed 2026-11-11T23:39:38.114483Z 83a0af8 PR opened
ℹ️ About Codex in GitHub

Your team has set up Codex to 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" or "@codex security review".

Codex reacts with 👀 while any review is running, comments if it has suggestions, and reacts with 👍 once all reviews finish with no findings.

@cit-pr-commenter-54b7da

Copy link
Copy Markdown

Codeowners resolved as

Resolved from the full PR diff against main using the target branch CODEOWNERS file.
CODEOWNERS team requests not listed below are not required by the current file set.

.gitlab/native.yml                                                      @DataDog/python-guild @DataDog/apm-core-python
scripts/check-libdatadog-pins.sh                                        @DataDog/python-guild
tests/internal/test_check_libdatadog_pins.py                            @DataDog/apm-core-python

@cit-pr-commenter-54b7da

Copy link
Copy Markdown

Dependency direction analysis

⚠️ Existing dependency direction violations

There are 73 dependency direction violations that already exist on the base branch and have not been changed by this PR.

Show existing violations (showing 5 of 73 highest severity)
ddtrace.internal.tracemethods -×-> ddtrace.trace  (internal-core -> product:tracing, score=120)
ddtrace.llmobs._integrations.openai -×-> ddtrace.trace  (product:llmobs -> product:tracing, score=118)
ddtrace.llmobs._integrations.typesafe -×-> ddtrace.trace  (product:llmobs -> product:tracing, score=118)
ddtrace.llmobs._integrations.crewai -×-> ddtrace.trace  (product:llmobs -> product:tracing, score=118)
ddtrace.llmobs._integrations.vertexai -×-> ddtrace.trace  (product:llmobs -> product:tracing, score=118)

To see all violations, download the layers-base.json and layers-pr.json artifacts from this CI job and run:

uv run --script scripts/import-analysis/layers.py compare layers-base.json layers-pr.json

@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: 83a0af85f5

ℹ️ 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".

case "$line" in
*"libdatadog-pin: allow"*) continue ;;
esac
if [[ "$line" =~ $tag_re ]]; then

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

P2 Badge Handle table-form Cargo dependencies

Cargo accepts dependencies written as [dependencies.libdd-common] with git = ".../libdatadog" and rev = "v48.0.0" on separate lines, but this condition searches for rev only on the line containing git. Such a correctly pinned manifest therefore fails the new blocking CI check; associate the fields across the dependency table rather than requiring an inline-table layout.

Useful? React with 👍 / 👎.

Comment on lines +32 to +33
case "$line" in
*"libdatadog-pin: allow"*) continue ;;

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

P2 Badge Still compare opted-out release tags

The marker is documented as an escape hatch for a temporary non-release pin, but this unconditional skip also removes a valid release tag from the consistency check. If a temporary SHA is later changed to an older release tag while its marker remains, a manifest can combine (for example) v47.0.0 and v48.0.0 and this job exits successfully; skip validation only when the pin is actually non-release, while continuing to collect release tags for comparison.

Useful? React with 👍 / 👎.

done < <(git ls-files | grep -E '(^|/)Cargo\.toml$' || true)

if [ "${#tags[@]}" -gt 0 ]; then
distinct=$(printf '%s\n' "${tags[@]}" | sort -uV | paste -sd' ' -)

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

P2 Badge Avoid GNU-only version sorting

On macOS and other BSD-based development environments, the system sort does not support -V, so this command terminates the script under set -e whenever at least one matching dependency exists—even when every pin is valid. Since the script explicitly advertises itself as a local check and only needs to deduplicate tags here, use portable sorting (such as sort -u) or another cross-platform comparison.

Useful? React with 👍 / 👎.

@datadog-datadog-prod-us1-2

datadog-datadog-prod-us1-2 Bot commented Nov 11, 2026 •

Copy link
Copy Markdown
Contributor

Pipelines  Tests

❌ Errors

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

🚦 1 Pipeline job failed

Changelog | Validate changelog

View more details · View in GitHub Actions

ℹ️ Info

No other issues found (see more)

🧪 All tests passed
❄️ No new flaky tests detected

Useful? React with 👍 / 👎

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

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

Bits Code Review: FAIL

Two distinct regex bugs exist in scripts/check-libdatadog-pins.sh: the URL-matching expression (line 26) does not recognise single-quoted TOML strings, silently bypassing pin validation, and the revision-extraction expression (line 35) matches version strings inside inline comments, allowing a non-release SHA pin to pass the CI gate when a release tag appears only in a comment.

Open Bits AI session

🤖 Bits Code Review · Commit 83a0af8

Comment on lines +25 to +26
dep_re='^[^#]*git[[:space:]]*=[[:space:]]*"[^"]*github\.com[/:]DataDog/libdatadog(\.git)?/?"'
tag_re='rev[[:space:]]*=[[:space:]]*"(v[0-9]+\.[0-9]+\.[0-9]+)"'

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.

P2 Recognize single-quoted TOML strings

A valid TOML dependency using git = 'https://github.com/DataDog/libdatadog', rev = 'deadbeef' is ignored entirely, allowing a non-release pin through CI. Conversely, a double-quoted URL with rev = 'v48.0.0' incorrectly fails. Both TOML string syntaxes need to participate in pin validation and release comparison.

Suggested change
dep_re='^[^#]*git[[:space:]]*=[[:space:]]*"[^"]*github\.com[/:]DataDog/libdatadog(\.git)?/?"'
tag_re='rev[[:space:]]*=[[:space:]]*"(v[0-9]+\.[0-9]+\.[0-9]+)"'
dep_re="^[^#]*git[[:space:]]*=[[:space:]]*[\"'][^\"']*github\.com[/:]DataDog/libdatadog(\.git)?/?[\"']"
tag_re="rev[[:space:]]*=[[:space:]]*[\"'](v[0-9]+\.[0-9]+\.[0-9]+)[\"']"

React: 👍 useful · 👎 wrong · 😕 unclear · 👀 right, but not acting on it

What each reaction means
  • 👍 Useful: correct, and you're fixing it or will.
  • 👎 Wrong: the finding is incorrect, for example the bug can't happen or the code was misread.
  • 😕 Unclear: you can't tell what it means or why it matters.
  • 👀 Right, not acting: correct, but intended, out of scope for this PR, a known risk, or too minor.

🤖 Bits Code Review · Open Bits AI session

case "$line" in
*"libdatadog-pin: allow"*) continue ;;
esac
if [[ "$line" =~ $tag_re ]]; then

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.

P2 Exclude inline comments when extracting revisions

With rev = "deadbeef" followed by an inline comment such as # previously rev = "v48.0.0", the regex extracts the release tag from the comment and reports success. Cargo still uses the SHA, so the new CI gate accepts precisely the unreleased dependency it should reject.

Suggested change
if [[ "$line" =~ $tag_re ]]; then
if [[ "${line%%#*}" =~ $tag_re ]]; then

React: 👍 useful · 👎 wrong · 😕 unclear · 👀 right, but not acting on it

What each reaction means
  • 👍 Useful: correct, and you're fixing it or will.
  • 👎 Wrong: the finding is incorrect, for example the bug can't happen or the code was misread.
  • 😕 Unclear: you can't tell what it means or why it matters.
  • 👀 Right, not acting: correct, but intended, out of scope for this PR, a known risk, or too minor.

🤖 Bits Code Review · Open Bits AI session

@pr-commenter

pr-commenter Bot commented Nov 12, 2026

Copy link
Copy Markdown

Benchmarks

Benchmark execution time: 2026-11-12 00:02:10

Comparing candidate commit 83a0af8 in PR branch automated/lint-libdatadog-release-pins-2026-11-11 with baseline commit e10161f in branch main.

📊 Benchmarking dashboard

Found 0 performance improvements and 0 performance regressions! Performance is the same for 615 metrics, 9 unstable metrics, 1 flaky benchmarks without significant changes.

Explanation

This is an A/B test comparing a candidate commit's performance against that of a baseline commit. Performance changes are noted in the tables below as:

  • 🟩 = significantly better candidate vs. baseline
  • 🟥 = significantly worse candidate vs. baseline

We compute a confidence interval (CI) over the relative difference of means between metrics from the candidate and baseline commits, considering the baseline as the reference.

If the CI is entirely outside the configured SIGNIFICANT_IMPACT_THRESHOLD (or the deprecated UNCONFIDENCE_THRESHOLD), the change is considered significant.

Feel free to reach out to #apm-benchmarking-platform on Slack if you have any questions.

More details about the CI and significant changes

You can imagine this CI as a range of values that is likely to contain the true difference of means between the candidate and baseline commits.

CIs of the difference of means are often centered around 0%, because often changes are not that big:

---------------------------------(------|---^--------)-------------------------------->
                              -0.6%    0%  0.3%     +1.2%
                                 |          |        |
         lower bound of the CI --'          |        |
sample mean (center of the CI) -------------'        |
         upper bound of the CI ----------------------'

As described above, a change is considered significant if the CI is entirely outside the configured SIGNIFICANT_IMPACT_THRESHOLD (or the deprecated UNCONFIDENCE_THRESHOLD).

For instance, for an execution time metric, this confidence interval indicates a significantly worse performance:

----------------------------------------|---------|---(---------^---------)---------->
                                       0%        1%  1.3%      2.2%      3.1%
                                                  |   |         |         |
       significant impact threshold --------------'   |         |         |
                      lower bound of CI --------------'         |         |
       sample mean (center of the CI) --------------------------'         |
                      upper bound of CI ----------------------------------'

Unstable benchmarks

These benchmarks have a confidence interval too wide to call a change; treat them as noise rather than signal.

scenario:coreapiscenario-context_with_data_listeners

  • unstable execution_time [-727.459ns; +706.200ns] or [-6.691%; +6.495%]

scenario:coreapiscenario-core_dispatch_50_listeners

  • unstable execution_time [-1848.236ns; +1921.579ns] or [-9.105%; +9.467%]

scenario:coreapiscenario-core_dispatch_exception_listeners

  • unstable execution_time [-1768.682ns; +1769.657ns] or [-9.185%; +9.190%]

scenario:coreapiscenario-core_dispatch_listeners

  • unstable execution_time [-358.318ns; +376.635ns] or [-8.104%; +8.518%]

scenario:coreapiscenario-core_dispatch_no_args_listeners

  • unstable execution_time [-221.188ns; +216.584ns] or [-7.903%; +7.738%]

scenario:coreapiscenario-core_dispatch_with_results_1_listener

  • unstable execution_time [-99.305ns; +75.344ns] or [-6.634%; +5.033%]

scenario:coreapiscenario-core_dispatch_with_results_50_listeners

  • unstable execution_time [-4978.514ns; +4535.069ns] or [-9.611%; +8.755%]

scenario:coreapiscenario-core_dispatch_with_results_listeners

  • unstable execution_time [-1199.795ns; +786.422ns] or [-10.913%; +7.153%]

scenario:packagesupdateimporteddependencies-import_many_stdlib_cached

  • unstable execution_time [-55180.122ns; +56758.613ns] or [-9.461%; +9.732%]

Known flaky benchmarks

These benchmarks are marked as flaky and will not trigger a failure. Modify FLAKY_BENCHMARKS_REGEX to control which benchmarks are marked as flaky.

Known flaky benchmarks without significant changes:

  • scenario:packagespackageforrootmodulemapping-cache_off

@brettlangdon

Copy link
Copy Markdown
Member

A nice idea, but this implementation is flawed enough to consider re-writing.

gh-worker-dd-mergequeue-cf854d Bot pushed a commit that referenced this pull request Nov 18, 2026
<!-- dd-meta {"pullId":"74e89509-77c1-4c57-b00c-ab363be5abeb","source":"chat","resourceId":"8c626a5a-8c1b-489f-bd4d-302ed1d4a215","workflowId":"8c803024-e883-44c5-b25b-a76477bd46b0","codeChangeId":"8c803024-e883-44c5-b25b-a76477bd46b0","sourceType":"code_channel"} -->
## Description

The libdatadog project releases all its crates together. dd-trace-py must thus depend on libdatadog through exactly one release tag. A commit SHA, a branch, the default branch or a mix of releases can ship unreleased native code or put two copies of libdatadog into the native extension. Reviewers check this by hand at this time.

This PR adds a CI check for this rule. It replaces the approach in #21692 (Bash and regular expressions) with a small Python script that uses the `tomllib` TOML parser. There is no opt-out marker.

`scripts/check_libdatadog_pins.py` finds all tracked `Cargo.toml` and `Cargo.lock` files with `git ls-files`, and makes sure that:

- Each libdatadog git dependency in a `Cargo.toml` sets `rev` or `tag` to a `vX.Y.Z` release tag. The script examines all tables, which includes `[dependencies]`, `[dev-dependencies]`, `[build-dependencies]`, `[target.*.dependencies]`, `[workspace.dependencies]` and `[patch.*]`.
- Each libdatadog `[[package]].source` in a `Cargo.lock` uses `rev=` or `tag=` with a `vX.Y.Z` release tag.
- All `Cargo.lock` files together have exactly one libdatadog source. This includes the commit hash, thus two lockfiles that resolve the same tag to different commits also fail.
- The release tag in the `Cargo.toml` files is the same as the release tag in the `Cargo.lock` files.

Other changes:

- `.gitlab/native.yml`: new `libdatadog pins` job. It extends `.ci_utils` (small image with Python 3.14) and runs `python3 scripts/check_libdatadog_pins.py`.
- `scripts/run-script-doctests.py`: runs the doctests of the new script. The `requires-python` value changes from `>=3.9` to `>=3.11` because the script uses `tomllib`.

The script uses a TOML parser, thus these edge cases from the #21692 review are not a problem:

- Table-form dependencies (`[dependencies.libdd-common]` with `git` and `rev` on different lines) are accepted.
- Single-quoted TOML strings are read correctly.
- A release tag in a comment (`rev = "deadbeef"  # rev = "v49.0.0"`) does not hide a SHA pin.
- `tag = "vX.Y.Z"` is accepted, and `rev = "vX.Y.Z"` is also accepted.
- There is no opt-out marker, thus an opted-out pin cannot skip the tag comparison.
- The script does not use GNU-only tools such as `sort -V`.
- The error output is plain text, not GitHub Actions annotations, because the job runs in GitLab.

## Testing

- `python3 scripts/check_libdatadog_pins.py` on this branch passes: `OK: libdatadog source is git+https://github.com/DataDog/libdatadog?rev=v49.0.0#34293ad2...`.
- Doctests in the script cover URL matching (`.git` suffix, trailing slash, case, `ssh://`, other repositories), table-form dependencies, single quotes, inline comments, `branch`, the default branch, `[target.*]` and `[patch.*]` tables, and `Cargo.lock` `rev=`/`tag=`/`branch=`/no query. They run in the `Run scripts/*.py tests` precheck.
- Manual checks in a temporary git repository with copies of the real Cargo files. Each of these fails: SHA pin in `Cargo.toml` and `Cargo.lock`, mixed `v48.0.0`/`v49.0.0` tags, stale `Cargo.lock` (`Cargo.toml` at `v50.0.0`, lock at `v49.0.0`), `branch` and default branch, a second lockfile with a different libdatadog source, a SHA hidden by a comment, a `[patch]` entry on a branch, and no libdatadog source. Table-form, single-quoted, commented and `tag =` dependencies (with a `?tag=` lock source) pass.
- `scripts/lint checks` passes.
- The GitLab job itself did not run locally.

## Risks

- A PR that needs an unreleased libdatadog commit for a short time fails this job until libdatadog makes a release. This is intended.
- The job fails if no libdatadog git source is found. If dd-trace-py stops using libdatadog through git (for example, it moves to crates.io), update or remove this check.
- crates.io dependencies on libdatadog crates (for example `libdd-profiling-heap-gotter` in `src/native_heap_gotter`) are not checked. They do not use a git tag.
- `scripts/run-script-doctests.py` now needs Python 3.11 or later.

## Additional Notes

- Replaces #21692.
- No release note: this is a CI-only change.

🤖 Generated with <span>Claude Code</span> (<span>https://claude.com/claude-code</span>)

---

PR by Bits - [View session in Datadog](https://app.datadoghq.com/code/8c626a5a-8c1b-489f-bd4d-302ed1d4a215) • [Open in Slack](https://app.slack.com/client/T024FSN2Y/C0CJA6RJGN7)

Comment @DataDog to request changes

Co-authored-by: datadog-bits <263423550+datadog-bits@users.noreply.github.com>
Co-authored-by: brett.langdon <brett.langdon@datadoghq.com>
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.

1 participant