Skip to content
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

Log4j JsonTemplateLayout w/ local decorating - Properly support escaped double quotes followed by a comma #2184

Open
jtduffy opened this issue Dec 23, 2024 · 1 comment · May be fixed by #2187
Assignees
Labels
2 Story Point Estimate

Comments

@jtduffy
Copy link
Contributor

jtduffy commented Dec 23, 2024

Description

An edge case was discovered where malformed JSON was generated using the JsonTemplateLayout instrumentation module with a log message that contained an escaped double quote followed by a comma.

For example, this log line:
LOGGER.info("info {}", "\"bar\",");

produces the following JSON (prior to local decorating):

{
  "instant" : {
    "epochSecond" : 1734983121,
    "nanoOfSecond" : 537701000
  },
  "thread" : "background-preinit",
  "level" : "INFO",
  "loggerName" : "org.hibernate.validator.internal.util.Version",
  "message" : "info \"bar\",",
  "endOfBatch" : true,
  "loggerFqcn" : "org.hibernate.validator.internal.util.logging.Log_$logger",
  "threadId" : 75,
  "threadPriority" : 5
}

which is valid JSON.

With local decorating enabled, the instrumentation module injects the NR-LINKING metadata as follows:

{
  "instant" : {
    "epochSecond" : 1734983121,
    "nanoOfSecond" : 537701000
  },
  "thread" : "background-preinit",
  "level" : "INFO",
  "loggerName" : "org.hibernate.validator.internal.util.Version",
  "message" : "info \"bar\ NR-LINKING|abc12345|7253f5d752ed8f11|async-logger-tests|",",
  "endOfBatch" : true,
  "loggerFqcn" : "org.hibernate.validator.internal.util.logging.Log_$logger",
  "threadId" : 75,
  "threadPriority" : 5
}

which is invalid JSON since we inject in between the escaped \ and ",

The code currently checks for ", in order to get the index for metadata injection.
https://github.com/newrelic/newrelic-java-agent/blob/3cd9554e59a6575522a862178f78e6ef022a5a17/instrumentation/apache-log4j-layout-template-json-2.14.0/src/main/java/com/nr/agent/instrumentation/log4j2/layout/template/json/AgentUtils.java

We need to check for an unescaped " followed by a , and adjust the metadata addition appropriately.

@workato-integration
Copy link

@jtduffy jtduffy added the 2 Story Point Estimate label Dec 23, 2024
@jtduffy jtduffy moved this from Triage to Needs Review in Java Engineering Board Dec 30, 2024
@jtduffy jtduffy self-assigned this Dec 30, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
2 Story Point Estimate
Projects
Status: Needs Review
Development

Successfully merging a pull request may close this issue.

1 participant