diff --git a/app/controllers/general.php b/app/controllers/general.php index 49f4dda705..3d2bd6a34d 100644 --- a/app/controllers/general.php +++ b/app/controllers/general.php @@ -609,6 +609,12 @@ function router(App $utopia, Database $dbForPlatform, callable $getProjectDB, Sw } } + if ($deployment->getAttribute('resourceType') === 'functions') { + $executionResponse['headers']['x-appwrite-execution-id'] = $execution->getId(); + } elseif ($deployment->getAttribute('resourceType') === 'sites') { + $executionResponse['headers']['x-appwrite-log-id'] = $execution->getId(); + } + $headersFiltered = []; foreach ($executionResponse['headers'] as $key => $value) { if (\in_array(\strtolower($key), FUNCTION_ALLOWLIST_HEADERS_RESPONSE)) { diff --git a/src/Appwrite/Platform/Modules/Functions/Http/Executions/Create.php b/src/Appwrite/Platform/Modules/Functions/Http/Executions/Create.php index 64056b7db7..3967b20e49 100644 --- a/src/Appwrite/Platform/Modules/Functions/Http/Executions/Create.php +++ b/src/Appwrite/Platform/Modules/Functions/Http/Executions/Create.php @@ -481,6 +481,8 @@ class Create extends Base $execution = Authorization::skip(fn () => $dbForProject->createDocument('executions', $execution)); } + $executionResponse['headers']['x-appwrite-execution-id'] = $execution->getId(); + $headers = []; foreach (($executionResponse['headers'] ?? []) as $key => $value) { $headers[] = ['name' => $key, 'value' => $value]; diff --git a/src/Appwrite/Platform/Workers/Functions.php b/src/Appwrite/Platform/Workers/Functions.php index 864d6451b8..af91019f2e 100644 --- a/src/Appwrite/Platform/Workers/Functions.php +++ b/src/Appwrite/Platform/Workers/Functions.php @@ -543,6 +543,8 @@ class Functions extends Action $status = $executionResponse['statusCode'] >= 500 ? 'failed' : 'completed'; + $executionResponse['headers']['x-appwrite-execution-id'] = $execution->getId(); + $headersFiltered = []; foreach ($executionResponse['headers'] as $key => $value) { if (\in_array(\strtolower($key), FUNCTION_ALLOWLIST_HEADERS_RESPONSE)) { diff --git a/tests/e2e/Services/Functions/FunctionsCustomClientTest.php b/tests/e2e/Services/Functions/FunctionsCustomClientTest.php index a60c9e59cf..0907e3da0b 100644 --- a/tests/e2e/Services/Functions/FunctionsCustomClientTest.php +++ b/tests/e2e/Services/Functions/FunctionsCustomClientTest.php @@ -142,6 +142,19 @@ class FunctionsCustomClientTest extends Scope ]); $output = json_decode($execution['body']['responseBody'], true); $this->assertEquals(201, $execution['headers']['status-code']); + + $this->assertNotEmpty($execution['body']['responseHeaders']); + + $executionIdHeader = null; + foreach ($execution['body']['responseHeaders'] as $header) { + if ($header['name'] === 'x-appwrite-execution-id') { + $executionIdHeader = $header['value']; + break; + } + } + $this->assertNotEmpty($executionIdHeader); + $this->assertEquals($execution['body']['$id'], $executionIdHeader); + $this->assertEquals(200, $execution['body']['responseStatusCode']); $this->assertGreaterThan(0, $execution['body']['duration']); $this->assertEquals('completed', $execution['body']['status']); diff --git a/tests/e2e/Services/Functions/FunctionsCustomServerTest.php b/tests/e2e/Services/Functions/FunctionsCustomServerTest.php index 1d993c19b7..95781f0390 100644 --- a/tests/e2e/Services/Functions/FunctionsCustomServerTest.php +++ b/tests/e2e/Services/Functions/FunctionsCustomServerTest.php @@ -892,6 +892,19 @@ class FunctionsCustomServerTest extends Scope ]); $this->assertEquals(201, $execution['headers']['status-code']); + + $this->assertNotEmpty($execution['body']['responseHeaders']); + + $executionIdHeader = null; + foreach ($execution['body']['responseHeaders'] as $header) { + if ($header['name'] === 'x-appwrite-execution-id') { + $executionIdHeader = $header['value']; + break; + } + } + $this->assertNotEmpty($executionIdHeader); + $this->assertEquals($execution['body']['$id'], $executionIdHeader); + $this->assertNotEmpty($execution['body']['$id']); $this->assertNotEmpty($execution['body']['functionId']); $this->assertEquals(true, (new DatetimeValidator())->isValid($execution['body']['$createdAt'])); @@ -1676,6 +1689,9 @@ class FunctionsCustomServerTest extends Scope $this->assertEquals(200, $response['headers']['status-code']); $this->assertEquals($cookie, $response['body']); + $this->assertArrayHasKey('x-appwrite-execution-id', $response['headers']); + $this->assertNotEmpty($response['headers']['x-appwrite-execution-id']); + // Async execution document creation $this->assertEventually(function () use ($functionId) { $executions = $this->client->call(Client::METHOD_GET, '/functions/' . $functionId . '/executions', array_merge([ diff --git a/tests/e2e/Services/Sites/SitesCustomServerTest.php b/tests/e2e/Services/Sites/SitesCustomServerTest.php index 0e792d6c36..ac1aab21ce 100644 --- a/tests/e2e/Services/Sites/SitesCustomServerTest.php +++ b/tests/e2e/Services/Sites/SitesCustomServerTest.php @@ -1433,6 +1433,9 @@ class SitesCustomServerTest extends Scope $this->assertEquals(200, $response['headers']['status-code']); $this->assertStringContainsString("Index page", $response['body']); + $this->assertArrayHasKey('x-appwrite-log-id', $response['headers']); + $this->assertNotEmpty($response['headers']['x-appwrite-log-id']); + $response = $proxyClient->call(Client::METHOD_GET, '/contact', array_merge([ 'content-type' => 'application/json', 'x-appwrite-project' => $this->getProject()['$id'],