Skip to content

feat: added environment capability [APMSP-3780]#2239

Open
Aaalibaba42 wants to merge 2 commits into
mainfrom
jwiriath/env-caps
Open

feat: added environment capability [APMSP-3780]#2239
Aaalibaba42 wants to merge 2 commits into
mainfrom
jwiriath/env-caps

Conversation

@Aaalibaba42

Copy link
Copy Markdown
Contributor

What does this PR do?

Added capability to read and write environment variables

Motivation

dd-trace-js needing to add info from the env in their requests, it's better to have libdatadog drive the call

Additional Notes

Nop

How to test the change?

check, tests, check for wasm32

@Aaalibaba42 Aaalibaba42 requested review from a team as code owners July 15, 2026 09:57
@github-actions

github-actions Bot commented Jul 15, 2026

Copy link
Copy Markdown
Contributor

📚 Documentation Check Results

⚠️ 209 documentation warning(s) found

📦 libdd-capabilities-impl - 191 warning(s)

📦 libdd-capabilities - 18 warning(s)


Updated: 2026-07-15 13:00:36 UTC | Commit: 65c7ce0 | missing-docs job results

@github-actions

github-actions Bot commented Jul 15, 2026

Copy link
Copy Markdown
Contributor

🔒 Cargo Deny Results

⚠️ 1 issue(s) found, showing only errors (advisories, bans, sources)

📦 libdd-capabilities-impl - 1 error(s)

Show output
error[unsound]: Rand is unsound with a custom logger using `rand::rng()`
   ┌─ /home/runner/work/libdatadog/libdatadog/Cargo.lock:68:1
   │
68 │ rand 0.8.5 registry+https://github.com/rust-lang/crates.io-index
   │ ━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━ unsound advisory detected
   │
   ├ ID: RUSTSEC-2026-0097
   ├ Advisory: https://rustsec.org/advisories/RUSTSEC-2026-0097
   ├ It has been reported (by @lopopolo) that the `rand` library is [unsound](https://rust-lang.github.io/unsafe-code-guidelines/glossary.html#soundness-of-code--of-a-library) (i.e. that safe code using the public API can cause Undefined Behaviour) when all the following conditions are met:
     
     - The `log` and `thread_rng` features are enabled
     - A [custom logger](https://docs.rs/log/latest/log/#implementing-a-logger) is defined
     - The custom logger accesses `rand::rng()` (previously `rand::thread_rng()`) and calls any `TryRng` (previously `RngCore`) methods on `ThreadRng`
     - The `ThreadRng` (attempts to) reseed while called from the custom logger (this happens every 64 kB of generated data)
     - Trace-level logging is enabled or warn-level logging is enabled and the random source (the `getrandom` crate) is unable to provide a new seed
     
     `TryRng` (previously `RngCore`) methods for `ThreadRng` use `unsafe` code to cast `*mut BlockRng<ReseedingCore>` to `&mut BlockRng<ReseedingCore>`. When all the above conditions are met this results in an aliased mutable reference, violating the Stacked Borrows rules. Miri is able to detect this violation in sample code. Since construction of [aliased mutable references is Undefined Behaviour](https://doc.rust-lang.org/stable/nomicon/references.html), the behaviour of optimized builds is hard to predict.
   ├ Announcement: https://github.com/rust-random/rand/pull/1763
   ├ Solution: Upgrade to >=0.10.1 OR <0.10.0, >=0.9.3 OR <0.9.0, >=0.8.6 (try `cargo update -p rand`)
   ├ rand v0.8.5
     └── (dev) libdd-common v5.1.0
         └── libdd-capabilities-impl v3.0.0

advisories FAILED, bans ok, sources ok

📦 libdd-capabilities - ✅ No issues


Updated: 2026-07-15 13:02:03 UTC | Commit: 65c7ce0 | dependency-check job results

@datadog-official

datadog-official Bot commented Jul 15, 2026

Copy link
Copy Markdown

Tests

🎉 All green!

🧪 All tests passed
❄️ No new flaky tests detected

🎯 Code Coverage (details)
Patch Coverage: 82.42%
Overall Coverage: 74.46% (-0.00%)

This comment will be updated automatically if new data arrives.
🔗 Commit SHA: bed4965 | Docs | Datadog PR Page | Give us feedback!

@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: a1dfa1a88f

ℹ️ 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 libdd-capabilities-impl/src/env.rs Outdated
Comment thread libdd-capabilities/Cargo.toml Outdated
@dd-octo-sts

dd-octo-sts Bot commented Jul 15, 2026

Copy link
Copy Markdown
Contributor

Artifact Size Benchmark Report

aarch64-alpine-linux-musl
Artifact Baseline Commit Change
/aarch64-alpine-linux-musl/lib/libdatadog_profiling.so 7.88 MB 7.88 MB 0% (0 B) 👌
/aarch64-alpine-linux-musl/lib/libdatadog_profiling.a 86.32 MB 86.32 MB -0% (-1.11 KB) 👌
aarch64-unknown-linux-gnu
Artifact Baseline Commit Change
/aarch64-unknown-linux-gnu/lib/libdatadog_profiling.a 97.54 MB 97.54 MB -0% (-872 B) 👌
/aarch64-unknown-linux-gnu/lib/libdatadog_profiling.so 10.62 MB 10.62 MB +0% (+120 B) 👌
libdatadog-x64-windows
Artifact Baseline Commit Change
/libdatadog-x64-windows/debug/dynamic/datadog_profiling_ffi.dll 25.58 MB 25.58 MB 0% (0 B) 👌
/libdatadog-x64-windows/debug/dynamic/datadog_profiling_ffi.lib 89.18 KB 89.18 KB 0% (0 B) 👌
/libdatadog-x64-windows/debug/dynamic/datadog_profiling_ffi.pdb 185.48 MB 185.58 MB +.05% (+96.00 KB) 🔍
/libdatadog-x64-windows/debug/static/datadog_profiling_ffi.lib 957.69 MB 958.58 MB +.09% (+906.18 KB) 🔍
/libdatadog-x64-windows/release/dynamic/datadog_profiling_ffi.dll 8.37 MB 8.37 MB --.01% (-1.50 KB) 💪
/libdatadog-x64-windows/release/dynamic/datadog_profiling_ffi.lib 89.18 KB 89.18 KB 0% (0 B) 👌
/libdatadog-x64-windows/release/dynamic/datadog_profiling_ffi.pdb 24.76 MB 24.76 MB --.03% (-8.00 KB) 💪
/libdatadog-x64-windows/release/static/datadog_profiling_ffi.lib 49.28 MB 49.28 MB --.01% (-8.09 KB) 💪
libdatadog-x86-windows
Artifact Baseline Commit Change
/libdatadog-x86-windows/debug/dynamic/datadog_profiling_ffi.dll 22.23 MB 22.22 MB --.03% (-8.50 KB) 💪
/libdatadog-x86-windows/debug/dynamic/datadog_profiling_ffi.lib 90.58 KB 90.58 KB 0% (0 B) 👌
/libdatadog-x86-windows/debug/dynamic/datadog_profiling_ffi.pdb 189.94 MB 189.98 MB +.01% (+32.00 KB) 🔍
/libdatadog-x86-windows/debug/static/datadog_profiling_ffi.lib 946.33 MB 946.24 MB -0% (-86.09 KB) 👌
/libdatadog-x86-windows/release/dynamic/datadog_profiling_ffi.dll 6.47 MB 6.47 MB 0% (0 B) 👌
/libdatadog-x86-windows/release/dynamic/datadog_profiling_ffi.lib 90.58 KB 90.58 KB 0% (0 B) 👌
/libdatadog-x86-windows/release/dynamic/datadog_profiling_ffi.pdb 26.58 MB 26.58 MB 0% (0 B) 👌
/libdatadog-x86-windows/release/static/datadog_profiling_ffi.lib 46.89 MB 46.89 MB +0% (+1.06 KB) 👌
x86_64-alpine-linux-musl
Artifact Baseline Commit Change
/x86_64-alpine-linux-musl/lib/libdatadog_profiling.a 77.09 MB 77.07 MB --.01% (-12.26 KB) 💪
/x86_64-alpine-linux-musl/lib/libdatadog_profiling.so 8.83 MB 8.83 MB --.04% (-4.00 KB) 💪
x86_64-unknown-linux-gnu
Artifact Baseline Commit Change
/x86_64-unknown-linux-gnu/lib/libdatadog_profiling.a 92.50 MB 92.50 MB +0% (+5.22 KB) 👌
/x86_64-unknown-linux-gnu/lib/libdatadog_profiling.so 10.74 MB 10.74 MB +0% (+224 B) 👌

@pr-commenter

pr-commenter Bot commented Jul 15, 2026

Copy link
Copy Markdown

Benchmarks

Comparison

Benchmark execution time: 2026-07-15 13:31:11

Comparing candidate commit bed4965 in PR branch jwiriath/env-caps with baseline commit a10f667 in branch main.

Found 4 performance improvements and 27 performance regressions! Performance is the same for 111 metrics, 0 unstable metrics.

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 ----------------------------------'

scenario:normalization/normalize_name/normalize_name/good

  • 🟥 execution_time [+468.486ns; +562.914ns] or [+4.302%; +5.169%]
  • 🟥 throughput [-4620812.321op/s; -3847910.463op/s] or [-5.028%; -4.187%]

scenario:otlp/e2e_json/1x1000

  • 🟥 execution_time [+424.290µs; +425.397µs] or [+10.378%; +10.405%]

scenario:otlp/encode_json/1x1000

  • 🟥 execution_time [+464.850µs; +465.490µs] or [+26.375%; +26.412%]

scenario:vec_map/contains_key/128

  • 🟥 execution_time [+736.939ns; +744.649ns] or [+4.925%; +4.976%]
  • 🟥 throughput [-405589.456op/s; -401325.735op/s] or [-4.742%; -4.692%]

scenario:vec_map/contains_key/16

  • 🟥 execution_time [+31.061ns; +31.353ns] or [+13.444%; +13.570%]
  • 🟥 throughput [-8281955.098op/s; -8201237.270op/s] or [-11.959%; -11.842%]

scenario:vec_map/contains_key/64

  • 🟥 execution_time [+195.657ns; +198.347ns] or [+4.903%; +4.971%]
  • 🟥 throughput [-759601.424op/s; -749479.521op/s] or [-4.736%; -4.673%]

scenario:vec_map/contains_key/8

  • 🟥 execution_time [+12.364ns; +12.617ns] or [+17.517%; +17.875%]
  • 🟥 throughput [-17196553.574op/s; -16873760.181op/s] or [-15.172%; -14.887%]

scenario:vec_map/get_hit/16

  • 🟩 execution_time [-35.603ns; -35.348ns] or [-15.088%; -14.980%]
  • 🟩 throughput [+11958050.801op/s; +12036873.630op/s] or [+17.635%; +17.752%]

scenario:vec_map/get_hit/8

  • 🟩 execution_time [-10.890ns; -10.852ns] or [-16.799%; -16.741%]
  • 🟩 throughput [+24820764.970op/s; +24911520.422op/s] or [+20.113%; +20.186%]

scenario:vec_map/get_miss/8

  • 🟥 execution_time [+1.831ns; +1.843ns] or [+32.275%; +32.496%]

scenario:vec_map/get_mut/128

  • 🟥 execution_time [+1.991µs; +2.094µs] or [+14.377%; +15.120%]
  • 🟥 throughput [-1217313.453op/s; -1156694.822op/s] or [-13.165%; -12.510%]

scenario:vec_map/get_mut/16

  • 🟥 execution_time [+26.404ns; +36.895ns] or [+9.697%; +13.550%]
  • 🟥 throughput [-7415951.060op/s; -5201386.331op/s] or [-12.490%; -8.760%]

scenario:vec_map/get_mut/64

  • 🟥 execution_time [+448.695ns; +488.576ns] or [+11.517%; +12.541%]
  • 🟥 throughput [-1841002.270op/s; -1689991.255op/s] or [-11.200%; -10.281%]

scenario:vec_map/get_mut/8

  • 🟥 execution_time [+4.969ns; +9.741ns] or [+5.824%; +11.417%]
  • 🟥 throughput [-10256957.251op/s; -5056173.228op/s] or [-10.724%; -5.287%]

scenario:vec_map/iter/128

  • 🟥 execution_time [+7.454ns; +7.556ns] or [+7.174%; +7.272%]
  • 🟥 throughput [-83509585.738op/s; -82443418.374op/s] or [-6.779%; -6.692%]

scenario:vec_map/iter/16

  • 🟥 execution_time [+0.582ns; +0.621ns] or [+4.456%; +4.753%]
  • 🟥 throughput [-55605970.893op/s; -52421235.127op/s] or [-4.541%; -4.281%]

scenario:vec_map/iter/8

  • 🟥 execution_time [+0.539ns; +0.546ns] or [+8.055%; +8.150%]
  • 🟥 throughput [-90111484.198op/s; -89010182.288op/s] or [-7.542%; -7.449%]

Candidate

Omitted due to size.

Baseline

Omitted due to size.

@Aaalibaba42

Copy link
Copy Markdown
Contributor Author

@codex review

@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: bed4965e07

ℹ️ 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 libdd-capabilities-impl/src/env.rs
fn get(&self, name: &str) -> Result<Option<String>, EnvError> {
match std::env::var(name) {
Ok(v) => Ok(Some(v)),
Err(VarError::NotPresent) => Ok(None),

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

P3 Badge Reject invalid names on env reads

When get is called with an invalid variable name containing = or NUL, std::env::var reports that as VarError::NotPresent, so this branch returns Ok(None) even though the trait docs say that means the variable is unset. Because set and unset already validate these names, reads should do the same and return EnvError::Invalid rather than silently treating caller input errors as missing environment variables.

Useful? React with 👍 / 👎.

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

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

I don't necessarily agree but I'm leaving it open for a future reviewer's opinion on this.

@Aaalibaba42 Aaalibaba42 changed the title feat: added environment capability feat: added environment capability [APMSP-3780] Jul 15, 2026
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