diff --git a/manifests/php.yml b/manifests/php.yml index db6eb53666d..220ba53ab12 100644 --- a/manifests/php.yml +++ b/manifests/php.yml @@ -1044,7 +1044,16 @@ manifest: tests/test_library_conf.py::Test_ExtractBehavior_Default::test_single_tracecontext: v1.17.0 tests/test_library_conf.py::Test_ExtractBehavior_Ignore: incomplete_test_app (/make_distant_call endpoint is not correctly implemented) tests/test_library_conf.py::Test_ExtractBehavior_Restart: incomplete_test_app (/make_distant_call endpoint is not correctly implemented) - tests/test_library_conf.py::Test_ExtractBehavior_Restart_Otel: missing_feature (OTel extraction endpoint not implemented) + tests/test_library_conf.py::Test_ExtractBehavior_Restart_Otel: + - weblog_declaration: + "*": missing_feature (OTel SDK requires PHP >= 8.1) + apache-mod-8.1: v1.22.0 + apache-mod-8.1-zts: v1.22.0 + apache-mod-8.2: v1.22.0 + apache-mod-8.2-zts: v1.22.0 + php-fpm-8.1: v1.22.0 + php-fpm-8.2: v1.22.0 + php-fpm-8.5: v1.22.0 tests/test_library_conf.py::Test_ExtractBehavior_Restart_With_Extract_First: incomplete_test_app (/make_distant_call endpoint is not correctly implemented) tests/test_library_conf.py::Test_HeaderTags: v0.68.2 tests/test_library_conf.py::Test_HeaderTags_Colon_Leading: v0.74.0 diff --git a/utils/build/docker/php/common/otel_drop_in_extract_and_make_distant_call.php b/utils/build/docker/php/common/otel_drop_in_extract_and_make_distant_call.php new file mode 100644 index 00000000000..25632f63b66 --- /dev/null +++ b/utils/build/docker/php/common/otel_drop_in_extract_and_make_distant_call.php @@ -0,0 +1,72 @@ + "url parameter required"]); + exit(); +} + +// Collect incoming headers (lowercase keys) for OTel propagator extraction. +// In restart extract mode, the DD drop-in creates a new root context with +// span links to the incoming trace, rather than propagating it directly. +$headers = []; +foreach (getallheaders() as $k => $v) { + $headers[strtolower($k)] = $v; +} + +$context = \OpenTelemetry\API\Globals::propagator()->extract($headers); + +$tracer = \OpenTelemetry\API\Globals::tracerProvider()->getTracer('dd-trace-php/system-tests'); +$span = $tracer->spanBuilder('otel_extract_distant_call') + ->setParent($context) + ->setSpanKind(\OpenTelemetry\API\Trace\SpanKind::KIND_SERVER) + ->startSpan(); +$scope = $span->activate(); + +// Make the distant call; auto-instrumentation propagates the active span context. +$ch = curl_init($url); +$response_headers = []; +curl_setopt($ch, CURLOPT_RETURNTRANSFER, true); +curl_setopt($ch, CURLOPT_HEADER, false); +curl_setopt($ch, CURLINFO_HEADER_OUT, true); +curl_setopt($ch, CURLOPT_HEADERFUNCTION, function ($curl, $header) use ( + &$response_headers, +) { + $len = strlen($header); + $parts = explode(":", $header, 2); + if (count($parts) === 2) { + $response_headers[strtolower(trim($parts[0]))] = trim($parts[1]); + } + return $len; +}); +$status_code = 0; +$request_headers = []; +try { + curl_exec($ch); + $status_code = curl_getinfo($ch, CURLINFO_HTTP_CODE); + $raw = curl_getinfo($ch, CURLINFO_HEADER_OUT); + if ($raw) { + foreach (explode("\r\n", $raw) as $line) { + if (strpos($line, ":") !== false) { + [$k, $v] = explode(":", $line, 2); + $request_headers[strtolower(trim($k))] = trim($v); + } + } + } + curl_close($ch); + $span->end(); +} finally { + $scope->detach(); +} + +header("Content-Type: application/json"); +echo json_encode([ + "url" => $url, + "status_code" => $status_code, + "request_headers" => $request_headers, + "response_headers" => $response_headers, +]); diff --git a/utils/build/docker/php/common/rewrite-rules.conf b/utils/build/docker/php/common/rewrite-rules.conf index 7f46acdd997..58fc6921735 100644 --- a/utils/build/docker/php/common/rewrite-rules.conf +++ b/utils/build/docker/php/common/rewrite-rules.conf @@ -27,6 +27,7 @@ RewriteRule "^/signup$" "/signup/" RewriteRule "^/shell_execution$" "/shell_execution/" RewriteRule "^/otel_drop_in_baggage_api_otel$" "/otel_drop_in_baggage_api_otel/" RewriteRule "^/otel_drop_in_baggage_api_datadog$" "/otel_drop_in_baggage_api_datadog/" +RewriteRule "^/otel_drop_in_extract_and_make_distant_call$" "/otel_drop_in_extract_and_make_distant_call/" [QSA] RewriteRule "^/otel_drop_in$" "/otel_drop_in/" RewriteRule "^/db$" "/db/" RewriteRule "^/trace/sql$" "/trace_sql/"