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

No MDC Data in logs with enable_log_correlation=true after a RestTemplate call #499

Closed
joelrovira opened this issue Feb 24, 2019 · 3 comments · Fixed by #500
Closed

No MDC Data in logs with enable_log_correlation=true after a RestTemplate call #499

joelrovira opened this issue Feb 24, 2019 · 3 comments · Fixed by #500
Assignees
Labels
bug Bugs

Comments

@joelrovira
Copy link

joelrovira commented Feb 24, 2019

Describe the bug
When the property enable_log_correlation is configured with true value in the apm agent (for Java), traceId and transactionId are inserted in MDC and these values are written in log registries, but when you call a RestTemplate the next logs doesn't print the MDC values (traceId and transactionId).

To Reproduce

  1. Configure APM Agent with the following params (used in Eclipse IDE)

-javaagent:${workspace_loc:elastic_apm_micros_spring2}/configuration/apm/elastic-apm-agent-1.4.0.jar
-Delastic.apm.service_name=bankservice
-Delastic.apm.service_version=1.0.0
-Delastic.apm.environment=dev
-Delastic.apm.sanitize_field_names=pass*,pwd*
-Delastic.apm.capture_headers=true
-Delastic.apm.enable_log_correlation=true
-Delastic.apm.application_packages=org.jrovira.blog.apm
-Delastic.apm.server_urls=http://localhost:8200

  1. The source code with Spring Framework 2.1.2.RELEASE and JDK 1.8

@PostMapping("/account")
public ResponseEntity processAccount(@RequestParam String name, @RequestParam String nif) {
LOGGER.info("test1");
restTemplate.getForEntity(riskUrl, Boolean.class, nif);
LOGGER.info("test2");
}

  1. The logback configuration

<appender name="STDOUT" class="ch.qos.logback.core.ConsoleAppender">
<encoder class="net.logstash.logback.encoder.LogstashEncoder">
<includeCallerData>false</includeCallerData>
<includeContext>false</includeContext>
<shortenedLoggerNameLength>36</shortenedLoggerNameLength>
<customFields>
{
"micro_name": "${microName}"
}
</customFields>
</encoder>
</appender>

The console output

{...,"message":"test1",...,"transaction.id":"612a533941b93965","trace.id":"484302c7d391d4df487d39e238ded4b1",...}
{...,"message":"test2",...}

in the second log doesn't appear the transaction.id and trace.id fields.

Expected behavior
The second log should be

{...,"message":"test2",...,"transaction.id":"612a533941b93965","trace.id":"484302c7d391d4df487d39e238ded4b1",...}

The complete source code of my app is in https://bitbucket.org/jrovirablog/elastic_apm_micros_spring2/commits/f4fe94b424abe3ee416816893e4d8e5a1c6e583e

Thanks for all.

@eyalkoren
Copy link
Contributor

eyalkoren commented Feb 24, 2019

I think the problem is that we insert the properties properly to MDC when creating the transaction. Later, when RestTemplate is invoked we create a span and activate it, then when we deactivate it, we remove the properties from MDC, but since we are using same property names, the properties are no longer set in MDC after RestTemplate span is deactivated.
I will try to prepare a quick fix and provide a test build.

@eyalkoren eyalkoren self-assigned this Feb 24, 2019
@eyalkoren
Copy link
Contributor

@joelrovira Please try this snapshot and let me know if it fixes the problem. Thanks!

@joelrovira
Copy link
Author

the problem is fixed with the snapshot.

Thanks for all.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug Bugs
Projects
None yet
Development

Successfully merging a pull request may close this issue.

3 participants