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
11 changes: 10 additions & 1 deletion manifests/php.yml
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,72 @@
<?php

require_once __DIR__ . "/vendor/autoload.php";

$url = $_GET["url"] ?? null;
if ($url === null) {
http_response_code(400);
header("Content-Type: application/json");
echo json_encode(["error" => "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,
]);
1 change: 1 addition & 0 deletions utils/build/docker/php/common/rewrite-rules.conf
Original file line number Diff line number Diff line change
Expand Up @@ -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/"
Expand Down
Loading