Documentation Center

Trace logging with Spring

Add trace logging to your active Spring profiles in order to get detailed trace logs for a microservice. Note that trace logging impairs the performance of your microservice, and should be enabled only as long as is necessary to track down the source of an issue.

When tracking down the cause of a specific issue, it can help to get highly detailed logs of the activities of each microservice. You can achieve this by resolving the active Spring profiles property for a microservice.

You enable trace logging for a specific microservice by ensuring that the value of the spring.profiles.active property, a comma-separate list of values, includes the value trace-logging. For example, for the Content Service, you might set the property to the value broker,search,trace-logging.

After restarting the microservice, the microservice produces log output in a different format.

Without trace logging, the output format is as follows:
TIMESTAMP LOGLEVEL [SERVICENAME,CUSTOMERNAME,ENVIRONMENTNAME,CDENVNAME] LOGMESSAGE
With trace logging, the output format becomes:
TIMESTAMP LOGLEVEL [SERVICENAME,CUSTOMERNAME,ENVIRONMENTNAME,CDENVNAME,SPANID,TRACEID] LOGMESSAGE
In this format:
  • TIMESTAMP is a timestamp of the moment when the log output was produced
  • LOGLEVEL is the level of logging
  • SERVICENAME is the name of the microservice that produced the log output, taken from the property spring.application.name in the application.properties file of the microservice
  • CUSTOMERNAME is the value you have set for the customer environment variable
  • ENVIRONMENTNAME is the value you have set for the environment environment variable
  • CDENVNAME is the name of the Content Delivery environment, taken from the resolved placeholder cdenvironment
  • SPANID is the identifier for a step in the specific request, job or action that prompted this log output (initially the same as the trace ID)
  • TRACEID is the identifier for the specific request, job or action that prompted this log output
  • LOGMESSAGE is the text of the log message
For example, with trace logging enabled, your Content Delivery instance may produce the following log line:
2021-12-14 09:58:03.470 INFO [content-service,RWS,DockerCompose,staging,f975dae09b3c2849,f975dae09b3c2849] 80 --- [io2-8081-exec-7] c.s.d.s.c.TraceConfiguration : LOGMESSAGE

where LOGMESSAGE is the actual log message.

In a Cloud-based, load-balanced setup, you can also use the X-Amzn-Trace-Id header to trace an Application Load Balancer request. To learn how to configure your web server to log this ID, refer to the following support article from Amazon: https://aws.amazon.com/premiumsupport/knowledge-center/trace-elb-x-amzn-trace-id/

This produces log output like the following log line (presented here as two lines for the sake of readability):
2021-12-14 09:58:03.470  INFO [content-service,RWS,DockerCompose,staging,f975dae09b3c2849,f975dae09b3c2849] 
80 --- [io2-8081-exec-7] c.s.d.s.c.TraceConfiguration             : X-Amzn-Trace-Id: Self=1-67891234-12456789abcdef012345678;Root=1-67891233-abcdef012345678912345678