Skip to content
Advertisement

How to get trace id and span id in the log4j2, in the format [traceId, spanId ]?

How to get trace id and span id in the log4j2, not the in the [traceId, spanId ] ?

Expected Output : [APPNAME,5a59b2372d9a3814,5a59b2372d9a3814]

Actual Output : [logLevel=ERROR] — 2021-01-21 11:30:32,489 +0530 — http-nio-8080-exec-1 com.springboot.test.aspect.MyAspect — asnId= – message=”Logging key:”, traceId=f19556b82d98bf86, executionTimeSeconds=23

My log4j2 : tried adding below commented property but not seeing trace id in logs

JavaScript

Aspect class :

In the log of my Aspect class however I can see the trace id

JavaScript

pom :

JavaScript

ConfigHandler :

JavaScript

Please see that in the test project where I am not using log4j it comes as expected.

Advertisement

Answer

I was able to get the traceId and spanId by making below changes : 1)Add to log4j

JavaScript

2)Add property :

JavaScript

3)Add

JavaScript
User contributions licensed under: CC BY-SA
7 People found this is helpful
Advertisement