Skip to content

Bug: Correlation ID not logged in structured JSON #2250

@phipag

Description

@phipag

Expected Behaviour

When using correlationIdPath argument on @Logging I expect the correlation_id field to be added to the JSON output.

Example:

@Logging(correlationIdPath = "headers.Accept")
public APIGatewayProxyResponseEvent handleRequest(final APIGatewayProxyRequestEvent input, final Context context) {
    // ...
}

Assuming headers like this we should have log entries containing "correlation_id": "text/html,application/xhtml+xml,application/xml;q=0.9,image/webp,*/*;q=0.8"

    "headers": {
      "Accept": "text/html,application/xhtml+xml,application/xml;q=0.9,image/webp,*/*;q=0.8",
      "Accept-Encoding": "gzip, deflate, sdch",
      "Accept-Language": "en-US,en;q=0.8",
      "Cache-Control": "max-age=0",
      "CloudFront-Forwarded-Proto": "https",
      "CloudFront-Is-Desktop-Viewer": "true",
      "CloudFront-Is-Mobile-Viewer": "false",
      "CloudFront-Is-SmartTV-Viewer": "false",
      "CloudFront-Is-Tablet-Viewer": "false",
      "CloudFront-Viewer-Country": "US",
      "Host": "1234567890.execute-api.us-east-1.amazonaws.com",
      "Upgrade-Insecure-Requests": "1",
      "User-Agent": "Custom User Agent String",
      "Via": "1.1 08f323deadbeefa7af34d5feb414ce27.cloudfront.net (CloudFront)",
      "X-Amz-Cf-Id": "cDehVQoZnx43VYQb9j2-nvCh-9z396Uhbp027Y2JvkCPNLmGJHqlaA==",
      "X-Forwarded-For": "127.0.0.1, 127.0.0.2",
      "X-Forwarded-Port": "443",
      "X-Forwarded-Proto": "https"
    }

Current Behaviour

The correlation ID is silently missing in the log output.

Code snippet

Official code example at https://github.com/aws-powertools/powertools-lambda-java/blob/aae50c9d1952c22efda4e8ab9196c3856d11bde2/examples/powertools-examples-core-utilities/sam

Possible Solution

I think we are accidentally filtering out the correlation_id here: https://github.com/aws-powertools/powertools-lambda-java/blob/main/powertools-logging/powertools-logging-log4j/src/main/java/org/apache/logging/log4j/layout/template/json/resolver/PowertoolsResolver.java#L184-L188

We should add a custom resolver for this.

Steps to Reproduce

Use official example and add correlation id path.

Powertools for AWS Lambda (Java) version

2.5.0

AWS Lambda function runtime

Java 21

Debugging logs

Metadata

Metadata

Assignees

Labels

bugSomething isn't workinglogger

Type

Projects

Status

Working on it

Milestone

No milestone

Relationships

None yet

Development

No branches or pull requests

Issue actions