Skip to content

Expose the _X_AMZN_TRACE_ID variable in PHP-FPM too - #2192

Merged
mnapoli merged 1 commit into
masterfrom
fpm-trace-id
Sep 27, 2026
Merged

mnapoli merged 1 commit into
masterfrom
fpm-trace-id

Conversation

@mnapoli

@mnapoli mnapoli commented Sep 26, 2026

Copy link
Copy Markdown
Member

The function and console runtimes set _X_AMZN_TRACE_ID on every invocation, and the documentation says Bref exposes it on every invocation, but PHP-FPM workers didn't receive it: the trace ID was only available inside the LAMBDA_INVOCATION_CONTEXT JSON. #2189 fixed the same gap for LAMBDA_REQUEST_ID.

This passes it to PHP-FPM as a FastCGI parameter, so $_SERVER['_X_AMZN_TRACE_ID'] and getenv('_X_AMZN_TRACE_ID') work the same in every runtime. Documented in fpm-runtime.mdx.

Side effect to be aware of: on Lambda, the AWS SDK for PHP reads _X_AMZN_TRACE_ID (its recursion detection middleware) and sends it as the X-Amzn-Trace-Id header of AWS API calls. That was already the case in the function and console runtimes (and in AWS's native runtimes); AWS calls made from PHP-FPM now carry it too.

Tested on AWS Lambda (php-84-fpm behind an HTTP API) with this branch: $_SERVER['_X_AMZN_TRACE_ID'] and getenv('_X_AMZN_TRACE_ID') both return the trace header of the current invocation (Root=1-…;Parent=…;Sampled=0;Lineage=…), the same value as LAMBDA_INVOCATION_CONTEXT's traceId, and it changes on every request, including after PHP-FPM restarts following a timeout.

The function and console runtimes set it on every invocation, and the documentation says Bref
exposes it on every invocation, but PHP-FPM workers did not receive it.

Claude-Session: https://claude.ai/code/session_01Awk33iZ9mDSg1xgSAPkgGK
@mnapoli
mnapoli merged commit 407ae2d into master Sep 27, 2026
8 checks passed
@mnapoli
mnapoli deleted the fpm-trace-id branch September 27, 2026 08:46
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant