Skip to content

Add tenant id to lambda context and structured log messages #540

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Open
wants to merge 1 commit into
base: main
Choose a base branch
from

Conversation

ramisa2108
Copy link

Issue #, if available:

Description of changes:

  • Add tenant id to LambdaContext object and structured log messages

Target (OCI, Managed Runtime, both):

  • Both

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

Copy link
Contributor

@maxday maxday left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Awesome job @ramisa2108 ! 💯
I left only some small comments, let me know if that makes sense

@@ -333,6 +334,31 @@ public void nextTest() {
}
}

@Test
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

great test! 💯

@@ -581,7 +581,8 @@ public ByteArrayOutputStream call(InvocationRequest request) throws Error, Excep
cognitoIdentity,
LambdaEnvironment.FUNCTION_VERSION,
request.getInvokedFunctionArn(),
clientContext
clientContext,
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I think it would be great to leave the clientContext as the last parameter? This way we keep aws-related fields grouped. WDYT?

Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Great suggestion. Updated.

@@ -34,7 +35,8 @@ public LambdaContext(
CognitoIdentity identity,
String functionVersion,
String invokedFunctionArn,
ClientContext clientContext
ClientContext clientContext,
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

same here, maybe it would be better to swap args

Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Updated.

mockResponse.setHeader("lambda-runtime-aws-request-id", "1234567890");
mockResponse.setHeader("Content-Type", "application/json");
String expectedTenantId = "my-tenant-id";
mockResponse.setHeader("lambda-runtime-aws-tenant-id", expectedTenantId);
Copy link
Contributor

@maxday maxday Apr 16, 2025

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I think it would be great to have another set of tests for:

  1. header not present
  2. header present and empty string
  3. header present and null value

Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thanks for the suggestion. Added these test cases.

@@ -61,6 +61,11 @@ struct invocation_request {
*/
std::chrono::time_point<std::chrono::system_clock> deadline;

/**
Copy link
Contributor

@maxday maxday Apr 16, 2025

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

hopefully at some point, we won't have a copy of aws-lambda-cpp in here, so let's keep that change here but I think you also need to modify the source of truth here: https://github.com/awslabs/aws-lambda-cpp? (Not blocking for this PR to be merged) I've also created an issue for us to track that change at some point: #541

Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Ack.

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Agreed, one day, we could get rid of this. (Not blocking PR from my end either).

@@ -29,7 +29,8 @@ void testFormattingWithLambdaContext() {
null,
null,
"function-arn",
null
null,
"tenant-id"
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

let's also add a test with a null value for tenant-id as it's optional

Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Added test with null tenant-id.

@ramisa2108 ramisa2108 force-pushed the ramisa2108/support-multi-tenancy branch from 30c667c to b7c13ac Compare April 17, 2025 10:59
Copy link
Contributor

@maxday maxday left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

🎉

Copy link
Contributor

@godcrampy godcrampy left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Great work! 🎉

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.

3 participants