Skip to content

Conversation

@morrisonlevi
Copy link
Collaborator

@morrisonlevi morrisonlevi commented Jan 16, 2026

Description

This PR:

  • Moves initialization of SystemSettings to minit.
  • Re-initializes SystemSettings on first request to pick up env vars sent by php-fpm/apache (legacy behavior, IMO, kept to preserve behavior).
  • Plumbs through NonZeroU32/NonZeroU64 so that it's easier to see that the sampling distance cannot be <= 0.
  • Adds a .phpt test to prevent future regressions.

Builds on #3578.

Motivation

This fixes a recent regression where datadog.profiling.allocation_sampling_distance wasn't being applied. This occurred because we moved the initialization of the profiling stats to ginit, and at that point, SystemSettings are not initialized, so it picked up the default value.

I hit this regression in my work on PR #3559.

Reviewer checklist

  • Test coverage seems ok.
  • Appropriate labels assigned.

@datadog-datadog-prod-us1
Copy link

datadog-datadog-prod-us1 bot commented Jan 16, 2026

⚠️ Tests

Fix all issues with Cursor

⚠️ Warnings

🧪 25 Tests failed

    testSearchPhpBinaries from integration.DDTrace\Tests\Integration\PHPInstallerTest (Fix with Cursor)

testSimplePushAndProcess from laravel-58-test.DDTrace\Tests\Integrations\Laravel\V5_8\QueueTest (Datadog) (Fix with Cursor)
Risky Test
phpvfscomposer://tests/vendor/phpunit/phpunit/phpunit:60
testSimplePushAndProcess from laravel-8x-test.DDTrace\Tests\Integrations\Laravel\V8_x\QueueTest (Datadog) (Fix with Cursor)
DDTrace\Tests\Integrations\Laravel\V8_x\QueueTest::testSimplePushAndProcess
Test code or tested code printed unexpected output: spanLinksTraceId: 696ab03700000000303259a7a4f539fa
tid: 696ab03700000000
hexProcessTraceId: 303259a7a4f539fa
hexProcessSpanId: 466e4c8ffcc7674f
processTraceId: 3472936839218018810
processSpanId: 5075078011398088527
View all

ℹ️ Info

❄️ No new flaky tests detected

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

@github-actions github-actions bot added profiling Relates to the Continuous Profiler tracing labels Jan 16, 2026
@realFlowControl
Copy link
Member

I've played with this PR and it works 🎉
We should add a .phpt file with DD_PROFILING_LOG_LEVEL=trace and DD_PROFILING_ALLOCATION_SAMPLING_DISTANCE=1 and validate that we see a an allocation being sampled in a PHP script that allocates just few bytes so that we can be sure to not have a regression on this in the future.

Also adding a heads up: this PR might conflict with #3550

@morrisonlevi
Copy link
Collaborator Author

I've added the .phpt which was a bit tricky. Thanks for pairing with me to investigate why the engine didn't come up with the correct number of bytes allocated like it should have!

@morrisonlevi morrisonlevi marked this pull request as ready for review January 16, 2026 16:59
@morrisonlevi morrisonlevi requested a review from a team as a code owner January 16, 2026 16:59
@morrisonlevi morrisonlevi force-pushed the levi/minit-system-settings branch from d75b2d0 to f57cdf7 Compare January 16, 2026 17:03
@codecov-commenter
Copy link

codecov-commenter commented Jan 16, 2026

Codecov Report

✅ All modified and coverable lines are covered by tests.
✅ Project coverage is 62.01%. Comparing base (48c4254) to head (c9706f3).

Additional details and impacted files

Impacted file tree graph

@@            Coverage Diff             @@
##           master    #3579      +/-   ##
==========================================
+ Coverage   61.93%   62.01%   +0.07%     
==========================================
  Files         140      140              
  Lines       13309    13309              
  Branches     1762     1762              
==========================================
+ Hits         8243     8253      +10     
+ Misses       4275     4268       -7     
+ Partials      791      788       -3     

see 3 files with indirect coverage changes


Continue to review full report in Codecov by Sentry.

Legend - Click here to learn more
Δ = absolute <relative> (impact), ø = not affected, ? = missing data
Powered by Codecov. Last update 48c4254...c9706f3. Read the comment docs.

🚀 New features to boost your workflow:
  • ❄️ Test Analytics: Detect flaky tests, report on failures, and find test suite problems.
  • 📦 JS Bundle Analysis: Save yourself from yourself by tracking and limiting bundle sizes in JS merges.

@pr-commenter
Copy link

pr-commenter bot commented Jan 16, 2026

Benchmarks [ profiler ]

Benchmark execution time: 2026-01-16 21:43:30

Comparing candidate commit c9706f3 in PR branch levi/minit-system-settings with baseline commit 48c4254 in branch master.

Found 0 performance improvements and 0 performance regressions! Performance is the same for 29 metrics, 7 unstable metrics.

@morrisonlevi morrisonlevi changed the title fix(profiling): SystemSettings initialization Profiling: fix SystemSettings initialization Jan 16, 2026
datadog.profiling.allocation_enabled=1
datadog.profiling.allocation_sampling_distance=1
datadog.profiling.log_level=trace
datadog.profiling.output_pprof=/tmp/profiling-data/pprof
Copy link
Member

Choose a reason for hiding this comment

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

I think this should not be set in the test. CI sets this as an ENV variable to make sure tests run faster and not upload.

Suggested change
datadog.profiling.output_pprof=/tmp/profiling-data/pprof

Copy link
Member

@realFlowControl realFlowControl left a comment

Choose a reason for hiding this comment

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

Looks good, I left a comment 🎉

Base automatically changed from levi/const-system-settings to master January 16, 2026 21:07
Comment on lines +34 to +41
// ... except that the engine does the rounding in the wrong place for
// str_repeat, so it with our inputs it ends up doing this, with `f` being the
// function which determines the rounded amount:
// 1 * 87 + f(24 + 0 + 1)
// 87 + f(25)
// 87 + 32 = 119
// So it over-allocates by 7 bytes, and the log will have 119 bytes.
// Our regex allows for 112 (correct) and 119 (observed).
Copy link
Collaborator Author

Choose a reason for hiding this comment

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

@danielsn This little detail cost 1.5 hours of my day. Not now, but it's something we can fix in php-src some day.

@morrisonlevi morrisonlevi merged commit 7ae15a5 into master Jan 16, 2026
1883 of 2009 checks passed
@morrisonlevi morrisonlevi deleted the levi/minit-system-settings branch January 16, 2026 21:59
@github-actions github-actions bot added this to the 1.16.0 milestone Jan 16, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

profiling Relates to the Continuous Profiler tracing

Projects

None yet

Development

Successfully merging this pull request may close these issues.

4 participants