I want to use X-Amzn-Trace-Id to trace requests through my Application Load Balancer and web servers.
Short description
When an Application Load Balancer handles a request, the trace information is added to the X-Amzn-Trace-Id header:
X-Amzn-Trace-Id: Root=1-67891233-abcdef012345678912345678
Log the identifier and then use it to troubleshoot issues with your load balancer. For example, to identify when similar requests are received from the same client within a short time, use the X-Amzn-Trace-Id header. If you have many layers in your stack, then you can also use the X-Amzn-Trace-Id header to track a request across all the layers.
Resolution
To log the X-Amzn-Trace-Id header, complete the steps related to your web server configuration.
Apache
Complete the following steps:
-
Open the Apache configuration file (/etc/httpd/conf/httpd.conf in Amazon Linux) in your preferred text editor.
-
In the LogFormat section, add the option %{X-Amzn-Trace-Id}i:
LogFormat "%{X-Forwarded-For}i %h %l %u %t \"%r\" %>s %b %D \"%{Referer}i\" \"%{User-Agent}i\" \"%{X-Amzn-Trace-Id}i\"" combined
-
To apply your changes, run the following command:
sudo service apache restart
Tomcat
Complete the following steps:
-
Open the Tomcat configuration file (/etc/tomcat7/server.xml in Amazon Linux) in your preferred text editor.
-
In the org.apache.catalina.valves.AccessLogValve class, add the option %{X-Amzn-Trace-Id}i:
<Valve className="org.apache.catalina.valves.AccessLogValve" directory="logs"
prefix="localhost_access_log." suffix=".txt"
pattern="%h %l %u %t "%r" %s %b %{X-Amzn-Trace-Id}i" />
-
To apply your changes, run the following command:
sudo service tomcat7 restart
NGINX
Complete the following steps:
-
Open the NGINX configuration file ( /etc/nginx/nginx.conf in Amazon Linux) in your preferred text editor.
-
In the log_format section, add the option $http_x_amzn_trace_id:
log_format main '"$http_x_forwarded_for" $remote_addr - $remote_user [$time_local] "$request" '
'$status $body_bytes_sent "$http_referer" '
'"$http_user_agent" "$http_x_amzn_trace_id"';
-
To apply your changes, run the following command:
sudo service nginx restart
Internet Information Services (IIS)
Complete the following steps:
- Open the IIS Manager.
- Select your server's name.
- Choose Logging.
- Choose Select Fields.
- Choose Add Field.
- In the dialog box, for Field Name, enter X-Amzn-Trace-Id. For Source Type, enter Request Header. For Source, enter X-Amzn-Trace-Id.
- To apply your changes, choose Apply.
Related information
Request tracing for your Application Load Balancer
Access logs for your Application Load Balancer