Skip to content
Draft
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 1 addition & 3 deletions manifests/php.yml
Original file line number Diff line number Diff line change
Expand Up @@ -483,8 +483,7 @@ manifest:
- declaration: missing_feature (Not implemented yet)
component_version: <1.12.0
tests/docker_ssi/test_docker_ssi_appsec.py::TestDockerSSIAppsecFeatures::test_telemetry_source_ssi: missing_feature
tests/ffe/test_dynamic_evaluation.py: missing_feature
tests/ffe/test_exposures.py: missing_feature
tests/ffe/test_exposures.py::Test_FFE_Exposure_Caching_Same_Subject::test_ffe_exposure_caching_same_subject: missing_feature (PHP shared-nothing architecture - exposure cache does not persist across HTTP requests)
tests/integrations/crossed_integrations/test_kafka.py::Test_Kafka: missing_feature
tests/integrations/crossed_integrations/test_kinesis.py::Test_Kinesis_PROPAGATION_VIA_MESSAGE_ATTRIBUTES: missing_feature
tests/integrations/crossed_integrations/test_rabbitmq.py::Test_RabbitMQ_Trace_Context_Propagation: missing_feature
Expand Down Expand Up @@ -543,7 +542,6 @@ manifest:
tests/parametric/test_dynamic_configuration.py::TestDynamicConfigV1_EmptyServiceTargets: v1.4.0
tests/parametric/test_dynamic_configuration.py::TestDynamicConfigV1_ServiceTargets: missing_feature
tests/parametric/test_dynamic_configuration.py::TestDynamicConfigV2: missing_feature
tests/parametric/test_ffe/test_dynamic_evaluation.py::Test_Feature_Flag_Dynamic_Evaluation: missing_feature
tests/parametric/test_headers_b3.py::Test_Headers_B3::test_headers_b3_migrated_extract_invalid: missing_feature (Need to remove b3=b3multi alias)
tests/parametric/test_headers_b3.py::Test_Headers_B3::test_headers_b3_migrated_extract_valid: missing_feature (Need to remove b3=b3multi alias)
tests/parametric/test_headers_b3.py::Test_Headers_B3::test_headers_b3_migrated_inject_valid: missing_feature (Need to remove b3=b3multi alias)
Expand Down
1 change: 1 addition & 0 deletions utils/build/docker/php/apache-mod/php.conf
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,7 @@
RewriteRule "^/load_dependency$" "/load_dependency/"
RewriteRule "^/signup$" "/signup/"
RewriteRule "^/shell_execution$" "/shell_execution/"
RewriteRule "^/ffe$" "/ffe.php" [L]
RewriteCond /var/www/html/%{REQUEST_URI} !-f
RewriteRule "^/rasp/(.*)" "/rasp/$1.php" [L]
RewriteRule "^/api_security.sampling/.*" "/api_security_sampling.php$0" [L]
Expand Down
53 changes: 53 additions & 0 deletions utils/build/docker/php/common/ffe.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,53 @@
<?php

header('Content-Type: application/json');

$input = json_decode(file_get_contents('php://input'), true);

if (!is_array($input)) {
http_response_code(400);
echo json_encode(['error' => 'Invalid JSON body']);
exit;
}

$flag = isset($input['flag']) ? $input['flag'] : null;
$variationType = isset($input['variationType']) ? $input['variationType'] : null;
$defaultValue = isset($input['defaultValue']) ? $input['defaultValue'] : null;
$targetingKey = array_key_exists('targetingKey', $input) ? $input['targetingKey'] : '';
$attributes = isset($input['attributes']) ? $input['attributes'] : [];

try {
// Use OpenFeature API if available, fall back to direct provider
if (class_exists('\OpenFeature\API')) {
$provider = new \DDTrace\OpenFeature\DataDogProvider();
\OpenFeature\API::setProvider($provider);
$client = \OpenFeature\API::getClient();

$context = new \OpenFeature\implementation\flags\EvaluationContext(
$targetingKey,
new \OpenFeature\implementation\flags\Attributes($attributes)
);

$value = match ($variationType) {
'BOOLEAN' => $client->getBooleanValue($flag, (bool) $defaultValue, $context),
'STRING' => $client->getStringValue($flag, (string) $defaultValue, $context),
'INTEGER' => $client->getIntegerValue($flag, (int) $defaultValue, $context),
'NUMERIC' => $client->getFloatValue($flag, (float) $defaultValue, $context),
'JSON' => $client->getObjectValue($flag, is_array($defaultValue) ? $defaultValue : [], $context),
default => $defaultValue,
};
} else {
// Fallback to direct provider (no OpenFeature SDK installed)
$provider = \DDTrace\FeatureFlags\Provider::getInstance();
$provider->start();
$result = $provider->evaluate($flag, $variationType, $defaultValue, $targetingKey, $attributes);
$value = $result['value'];
}

// Flush exposure events immediately for system test observability
\DDTrace\FeatureFlags\Provider::getInstance()->flush();

echo json_encode(['value' => $value]);
} catch (\Throwable $e) {
echo json_encode(['value' => $defaultValue, 'error' => $e->getMessage()]);
}
3 changes: 2 additions & 1 deletion utils/build/docker/php/parametric/composer.json
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,8 @@
"amphp/log": "2.x-dev",
"open-telemetry/sdk": "^1.0.0",
"symfony/http-client": "6.4.x-dev",
"nyholm/psr7": "^1.8@dev"
"nyholm/psr7": "^1.8@dev",
"open-feature/sdk": "^2.0"
},
"config": {
"allow-plugins": {
Expand Down
45 changes: 45 additions & 0 deletions utils/build/docker/php/parametric/server.php
Original file line number Diff line number Diff line change
Expand Up @@ -546,6 +546,51 @@ function remappedSpanKind($spanKind) {
return jsonResponse([]);
}));

// FFE (Feature Flags & Experimentation) endpoints
$openFeatureClient = null;

$router->addRoute('POST', '/ffe/start', new ClosureRequestHandler(function (Request $req) use (&$openFeatureClient) {
try {
$provider = new \DDTrace\OpenFeature\DataDogProvider();
\OpenFeature\API::setProvider($provider);
$openFeatureClient = \OpenFeature\API::getClient();
return jsonResponse([]);
} catch (\Throwable $e) {
return new Response(status: 500, body: json_encode(['error' => $e->getMessage()]));
}
}));

$router->addRoute('POST', '/ffe/evaluate', new ClosureRequestHandler(function (Request $req) use (&$openFeatureClient) {
try {
if ($openFeatureClient === null) {
$provider = new \DDTrace\OpenFeature\DataDogProvider();
\OpenFeature\API::setProvider($provider);
$openFeatureClient = \OpenFeature\API::getClient();
}

$flag = arg($req, 'flag');
$variationType = arg($req, 'variationType');
$defaultValue = arg($req, 'defaultValue');
$targetingKey = arg($req, 'targetingKey');
$attributes = arg($req, 'attributes') ?? [];

$context = new \OpenFeature\implementation\flags\EvaluationContext($targetingKey, new \OpenFeature\implementation\flags\Attributes($attributes));

$value = match ($variationType) {
'BOOLEAN' => $openFeatureClient->getBooleanValue($flag, (bool) $defaultValue, $context),
'STRING' => $openFeatureClient->getStringValue($flag, (string) $defaultValue, $context),
'INTEGER' => $openFeatureClient->getIntegerValue($flag, (int) $defaultValue, $context),
'NUMERIC' => $openFeatureClient->getFloatValue($flag, (float) $defaultValue, $context),
'JSON' => $openFeatureClient->getObjectValue($flag, is_array($defaultValue) ? $defaultValue : [], $context),
default => $defaultValue,
};

return jsonResponse(['value' => $value]);
} catch (\Throwable $e) {
return new Response(status: 500, body: json_encode(['error' => $e->getMessage()]));
}
}));

$middleware = new class implements Middleware {
public function handleRequest(Request $request, RequestHandler $next): Response {
$response = $next->handleRequest($request);
Expand Down
Loading