I'm trying to monitor the logs of few REST services and Microservices in Dynatrace, which are developed using Java (Spring Boot). I am able to see the logs, but couldn't find the trace_id and span_id of the logs. I suppose there is a solution that is, to manually add the trace_id and span_id which is not I'm looking for. It would be great if anyone could provide a solution for this.
Spring Boot Version - 3.1.0
Log Version - log4j2 (2.20.0)
Solved! Go to Solution.
First please check if the OneAgent feature for automatically enrich Java log sources is enabled (first flag in the screenshot)
Those OneAgent features can be set on the environment level, host or also process level, so it's not necessary to enable them globally.
Then it depends on what log format are you using. If you are using structured logs (JSON/XML) it should be enough to have the flag "Java - Trace/span context enrichment for logs [Opt-In]" enabled.
If you use unstructured (plaintext) logs, you have multiple options - you can try enabling "Java - Trace/span context enrichment for unstructured logs [Opt-In]" and let Dynatrace decide to put the trace context in the plaintext logs. This, however, might not work in all cases as it depends on the log pattern you use.
Or you can modify your log pattern as described here which I consider the best approach and then you have full control over the placement of the trace context information. When adding it by this method via modifying the log pattern, only the first feature flag "Java - Trace/span context enrichment for logs [Opt-In]" is required.