How do I use X-Amzn-Trace-Id to trace an Application Load Balancer request?

2 minute read
0

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:

  1. Open the Apache configuration file (/etc/httpd/conf/httpd.conf in Amazon Linux) in your preferred text editor.

  2. 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
  3. To apply your changes, run the following command:

    sudo service apache restart

Tomcat

Complete the following steps:

  1. Open the Tomcat configuration file (/etc/tomcat7/server.xml in Amazon Linux) in your preferred text editor.

  2. 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 &quot;%r&quot; %s %b %{X-Amzn-Trace-Id}i" />
  3. To apply your changes, run the following command:

    sudo service tomcat7 restart

NGINX

Complete the following steps:

  1. Open the NGINX configuration file ( /etc/nginx/nginx.conf in Amazon Linux) in your preferred text editor.

  2. 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"';
  3. To apply your changes, run the following command:

    sudo service nginx restart

Internet Information Services (IIS)

Complete the following steps:

  1. Open the IIS Manager.
  2. Select your server's name.
  3. Choose Logging.
  4. Choose Select Fields.
  5. Choose Add Field.
  6. 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.
  7. To apply your changes, choose Apply.

Related information

Request tracing for your Application Load Balancer

Access logs for your Application Load Balancer

AWS OFFICIAL
AWS OFFICIALUpdated 9 months ago