Skip to content

fix: include tenantId in custom JSON log entries - #203

Open
maxday wants to merge 2 commits into
nodejs24.xfrom
maxday/fix-tenantId
Open

maxday wants to merge 2 commits into
nodejs24.xfrom
maxday/fix-tenantId

Conversation

@maxday

@maxday maxday commented Oct 23, 2026

Copy link
Copy Markdown
Member

runWithInvokeContext stored only the request ID and X-Ray trace ID in the InvokeStore, never the tenant ID. The JSON loggers read tenantId from the store, so it was always undefined, fell back to "", and the if (tenantId) guard dropped the field, even though it was correctly parsed onto context.tenantId.

By submitting this pull request, I confirm that my contribution is made under the terms of the Apache 2.0 license.

runWithInvokeContext only stored REQUEST_ID and X_RAY_TRACE_ID in the
InvokeStore, never TENANT_ID. The JSON loggers read tenantId via
invokeStore.getTenantId() (PROTECTED_KEYS.TENANT_ID), so it was always
undefined, fell back to "", and formatJsonMessage's `if (tenantId)`
guard dropped the field. The header was parsed correctly onto
context.tenantId (hence available in code and platform events), but that
value never reached the store the loggers consult.

Thread context.tenantId through runWithInvokeContext and set
PROTECTED_KEYS.TENANT_ID for both the single- and multi-concurrent call
sites so tenantId appears in custom JSON log entries, matching the
documented behavior and the Python runtime.

Add regression tests covering both call sites. tenantId is pinned to the
sandbox, so it stays constant across every invocation in the execution
environment's lifecycle (unlike requestId/traceId).

Ref: V2290595765
cr: https://code.amazon.com/reviews/CR-290016955
Reuse the existing JSON-log test to verify tenantId is emitted as a
top-level field in JSON-formatted logs, per review feedback on
CR-290016955.

cr: https://code.amazon.com/reviews/CR-290016955

This branch has not been deployed

No deployments
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