Skip to content

Conversation

phipag
Copy link
Contributor

@phipag phipag commented May 15, 2025

Issue #, if available: N/A (found while working on something else)

Description of changes:

This is a small change fixing an edge case where the JSON formatting of structured arguments in the logging module was broken. If a String contained double quotes they were not escaped leading to a broken JSON output in the Lambda logs.

Example:

Before

LOGGER.info("Message", entry("myString", "String with \"double quotes\""));

Invalid JSON (inner double quotes are not escaped)
jq: parse error: Invalid numeric literal at ...

{
  "level": "INFO",
  "message": "Message",
  "cold_start": true,
  "function_arn": "arn:aws:lambda:us-east-1:***:function:***",
  "function_memory_size": 512,
  "function_name": "***",
  "function_request_id": "7e97091d-c48e-4bc2-809f-822ac34a316f",
  "function_version": "$LATEST",
  "service": "***",
  "timestamp": "2025-05-15T14:07:52.036Z",
  "myString": "String with "double quotes""
}

After

LOGGER.info("Message", entry("myString", "String with \"double quotes\""));

Valid JSON

{
  "level": "INFO",
  "message": "Message",
  "cold_start": true,
  "function_arn": "arn:aws:lambda:us-east-1:***:function:***",
  "function_memory_size": 512,
  "function_name": "***",
  "function_request_id": "7e97091d-c48e-4bc2-809f-822ac34a316f",
  "function_version": "$LATEST",
  "service": "***",
  "timestamp": "2025-05-15T14:07:52.036Z",
  "myString": "String with \"double quotes\""
}

Checklist

@phipag phipag requested a review from leandrodamascena May 15, 2025 14:12
@phipag phipag added bug Something isn't working v2 logger and removed size/M labels May 15, 2025
@phipag phipag self-assigned this May 15, 2025
@sonarqubecloud
Copy link

Copy link
Contributor

@leandrodamascena leandrodamascena left a comment

Choose a reason for hiding this comment

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

Nice! APPROVED

@phipag phipag merged commit 9d111b3 into v2 May 15, 2025
15 checks passed
@phipag phipag deleted the phipag/v2-logging-string-escaping branch May 15, 2025 14:23
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

bug Something isn't working logger

Projects

Status: Coming soon

Development

Successfully merging this pull request may close these issues.

2 participants