Merge pull request #10379 from appwrite/feat-add-execution-and-log-response-headers

Add execution id and log id to response headers
This commit is contained in:
Matej Bačo 2025-08-27 09:16:28 +02:00 committed by GitHub
commit 82e12d4fcd
No known key found for this signature in database
GPG key ID: B5690EEEBB952194
6 changed files with 42 additions and 0 deletions

View file

@ -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)) {

View file

@ -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];

View file

@ -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)) {

View file

@ -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']);

View file

@ -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([

View file

@ -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'],