feat(php): Add /ffe endpoint and OTel SDK to PHP weblog#6475
Draft
leoromanovsky wants to merge 1 commit intomainfrom
Draft
feat(php): Add /ffe endpoint and OTel SDK to PHP weblog#6475leoromanovsky wants to merge 1 commit intomainfrom
leoromanovsky wants to merge 1 commit intomainfrom
Conversation
- Add /ffe handler (ffe.php): evaluates feature flags via DDTrace\FeatureFlags\Provider, includes retry loop for PHP-FPM first-request timing (SIGVTALRM delay), and flushes OTel meter provider after each evaluation so metrics reach the agent synchronously - Add /ffe/start + /ffe/evaluate to parametric server.php - Add Apache RewriteRule for /ffe -> /ffe.php in apache-mod config - Add open-telemetry/sdk + exporter-otlp to composer.json (both PHP variants) so the OTel counter in FlagEvalMetrics can export when DD_METRICS_OTEL_ENABLED=true - Update install_ddtrace.sh and php-fpm.conf to support the FFE scenario - Add OTEL_PHP_AUTOLOAD_ENABLED=true and OTEL_METRICS_EXPORTER=otlp to the FFE scenario env so the OTel PHP SDK autoloads and routes metrics to the OTLP exporter
Contributor
|
|
|
✨ Fix all issues with BitsAI or with Cursor
|
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Motivation
The PHP weblog needs a
/ffeendpoint to participate in FFE system tests (feature flag evaluation + OTel metrics). This PR adds the endpoint handler, wires up Apache routing, installs the OTel PHP SDK, and configures PHP-FPM so the FFE scenario works end-to-end.Companion to DataDog/dd-trace-php#3630 (FFE +
FlagEvalMetricsimplementation) and DataDog/system-tests#6410 (test enablement).Changes
utils/build/docker/php/common/ffe.php: New PHP handler for/ffe. Evaluates feature flags viaDDTrace\FeatureFlags\Provider, includes a retry loop (usleep(100ms)× 5) for PHP-FPM first-request timing whereFFE_STATE.configisNoneuntilSIGVTALRMfires, and callsforceFlush()on the OTel meter provider so metrics are exported to the agent synchronously within the request.utils/build/docker/php/parametric/server.php: Add/ffe/startand/ffe/evaluateendpoints for parametric tests.utils/build/docker/php/apache-mod/php.conf:RewriteRule ^/ffe$ /ffe.php [L]so Apache routes/ffeto the handler.utils/build/docker/php/common/composer.jsonandcomposer.gte8.2.json: Addopen-telemetry/sdkso the OTel PHP SDK is available whenDD_METRICS_OTEL_ENABLED=true.utils/build/docker/php/common/install_ddtrace.sh: Updated to include FFE-related install steps.utils/build/docker/php/php-fpm/php-fpm.conf: php-fpm tuning for FFE scenario.utils/_context/_scenarios/__init__.py: AddOTEL_PHP_AUTOLOAD_ENABLED=trueandOTEL_METRICS_EXPORTER=otlpto theFEATURE_FLAGGING_AND_EXPERIMENTATIONscenario env so the PHP OTel SDK autoloads and routes metrics to the OTLP exporter.Decisions
usleep()retry for PHP-FPM first-request timing. On the very first request to a PHP-FPM worker,FFE_STATE.configisNonebecause theddog_process_remote_configscall that loads the flag config only fires via aSIGVTALRMVM interrupt. That interrupt is delivered at PHP opcode boundaries — but only while PHP is executing, not while FPM is idle waiting for a request. Callingusleep()inside the handler yields CPU and makes PHP sleep at an opcode boundary; when the VM wakes up, the pending interrupt runsddog_process_remote_configs → store_config(). The loop retries up to 5× (500ms total), which is sufficient for the default 200ms RC poll interval in tests.forceFlush()after evaluation. The OTel SDK batches metrics on a 10s export interval. Without an explicit flush the metrics test would time out waiting for data to appear ininterfaces.agent.get_metrics(). Flushing inline afterProvider::flush()ensures both the exposure event and the OTel metric reach the agent in the same request lifecycle.OTel SDK via Composer, not bundled. The
open-telemetry/sdkpackage is added to the PHP weblog'scomposer.jsonrather than bundled in the tracer, keeping the dependency separate and consistent with how other weblogs consume OTel.Companion PRs