All Products
Search
Document Center

Managed Service for OpenTelemetry:Use Jaeger to perform tracing analysis on NGINX

Last Updated:Dec 21, 2023

NGINX is a free, open source, and high-performance server that serves as an HTTP server and a reverse proxy. You can perform tracing analysis on NGINX to better monitor the status of your applications. This topic describes how to perform tracing analysis on NGINX.

Prerequisites

To obtain an endpoint of Jaeger or Zipkin, perform the following steps:

  1. Log on to the Managed Service for OpenTelemetry console.

  2. In the left-side navigation pane, click Cluster Configurations. Then, click the Access point information tab.

  3. In the top navigation bar, select a region. In the Cluster Information section, turn on Show Token.

  4. In the Client section, click Jaeger or Zipkin.

    Obtain an endpoint of Jaeger or Zipkin in the Related Information column of the table in the lower part.

    Jaeger/Zipkin接入点信息

    Note

    If your application is deployed in an Alibaba Cloud production environment, use a VPC endpoint. Otherwise, use a public endpoint. Generally, use the endpoint of v2 for Zipkin. Use the endpoint of v1 only if you know Zipkin well.

Overview

If a slow response occurs in a microservice that uses NGINX as a proxy, you cannot estimate the impact of the slow response because no data is collected. In this case, you can use Tracing Analysis to trace NGINX requests for the microservice and calculate the number of page views that are affected by the slow response.

Deploy and trace NGINX in a Docker container

  1. Download, build, and then deploy a Dockerfile:

    wget https://arms-apm.oss-cn-hangzhou.aliyuncs.com/demo/nginx-jaeger-docker.tgz
    tar -xzvf nginx-jaeger-docker.tgz
    cd nginx-jaeger
    # Build the Dockerfile.
    docker build --rm --tag nginx-jaeger:0.1 .
  2. Run Docker:

    docker run --rm  -p 80:80 -e "GRPC_HOST=${GRPC_HOST}" -e "GRPC_AUTH=${GRPC_AUTH}" -d jaeger-nginx:0.1

    Set the ${GRPC_HOST} and ${GRPC_AUTH} variables to the endpoint information of the agent that you obtain in Prerequisites.

    Example:

    docker run --rm  -p 80:80 -e "GRPC_HOST=tracing-analysis-dc-hz.aliyuncs.com:1883" -e "GRPC_AUTH=123abc@123abc_789abc@456abc}" -d jaeger-nginx:0.1

Deploy and trace NGINX on an ECS instance

  1. Run the following command to install NGINX:

    1. Download and decompress the NGINX source code:

      wget http://nginx.org/download/nginx-1.14.2.tar.gz
      tar -xzvf nginx-1.14.2.tar.gz
    2. Compile the NGINX source code:

      cd nginx-1.14.2
      ./configure --with-compat
      make
      sudo make install
  2. Install OpenTracing.

    1. Download and decompress the OpenTracing package:

      wget https://github.com/opentracing-contrib/nginx-opentracing/releases/download/v0.7.0/linux-amd64-nginx-1.14.0-ngx_http_module.so.tgz
      tar -xzvf linux-amd64-nginx-1.14.0-ngx_http_module.so.tgz
    2. Copy the .so file to the modules folder of NGINX. If the folder does not exist, create the folder:

      sudo mkdir /usr/local/nginx/modules
      sudo cp ngx_http_opentracing_module.so /usr/local/nginx/modules/ngx_http_opentracing_module.so
  3. Use Jaeger to perform tracing analysis.

    1. Download Jaeger to a working directory:

      wget https://github.com/jaegertracing/jaeger-client-cpp/releases/download/v0.4.2/libjaegertracing_plugin.linux_amd64.so
      sudo cp /usr/local/lib/libjaegertracing_plugin.so /usr/local/lib/libjaegertracing.so
    2. Configure the /usr/local/nginx/conf/nginx.conf file:

      load_module modules/ngx_http_opentracing_module.so;
      events {}
      http {
        opentracing on;
        opentracing_load_tracer /usr/local/lib/libjaegertracing_plugin.so /etc/jaeger-config.json;
        server {
          error_log /var/log/nginx/debug.log debug;
          listen 80;
          location  ~ {
            opentracing_operation_name $uri;
            opentracing_trace_locations off;
            # The service that you use to navigate to the proxy. Set the value based on your business requirements. 
            proxy_pass http://127.0.0.1:8081;
            opentracing_propagate_context;
          }
        }
      }
      Note

      For information about the parameters, see opentracing-contrib.

    3. Set the Jaeger parameters in the /etc/jaeger-config.json file:

      {
        "service_name": "nginx",
        // Specify the sampling rate.
        "sampler": {
          "type": "const",
          "param": 1
        },
        "reporter": {
          "localAgentHostPort": "localhost:6831"
        }
      }
    4. Use one of the following methods to configure the Jaeger agent:

      • If you use a self-managed Jaeger service, download the native Jaeger agent and set the collector.host-port parameter:

        nohup ./jaeger-agent  --collector.host-port=10.100.**.**:142**   1>1.log 2>2.log &
      • If you use the Jaeger service that is managed by Alibaba Cloud, download the Tracing Analysis agent. Then, set the collector.host-port parameter to start the agent. This way, you can report data to Tracing Analysis.

        Set the <endpoint> parameter to the endpoint that you obtain in Prerequisites. Delete "/api/traces" at the end of the endpoint that is obtained in Prerequisites. For example, you can set the <endpoint> parameter to http://tracing-analysis-dc-sh.aliyuncs.com/adapt_abc123@abc123_efg123@efg123.

        # collector.host-port specifies the endpoint. The endpoint varies with the region. Example:
        nohup ./tracing-analysis-agent-linux-amd64 --collector.host-port=<endpoint>
    5. Run NGINX and access the NGINX service:

      sudo /usr/local/nginx/sbin/nginx
      curl "http://localhost"

Deploy and trace NGINX on other environments

  1. Pull an image from Container Registry:

    docker pull registry.cn-hangzhou.aliyuncs.com/public-community/jaeger-nginx:0.1
  2. Run NGINX in a Docker container:

    docker run --rm  -p 80:80 -e "GRPC_HOST=${GRPC_HOST}" -e "GRPC_AUTH=${GRPC_AUTH}" -d registry.cn-hangzhou.aliyuncs.com/public-community/jaeger-nginx:0.1

    Set the ${GRPC_HOST} and ${GRPC_AUTH} variables to the endpoint information of the agent that you obtain in Prerequisites.

    Example:

    docker run --rm  -p 80:80 -e "GRPC_HOST=tracing-analysis-dc-hz.aliyuncs.com:1883" -e "GRPC_AUTH=123abc@123abc_789abc@456abc}" -d jaeger-nginx:0.1
  3. Go to the NGINX page by using a browser.

    Enter localhost/nginx.conf or curl "localhost/nginx.conf" in the address bar of a browser to go to the NGINX page.

Check the result

On the Applications page of the Managed Service for OpenTelemetry console, click the name of the application. On the page that appears, view the trace data.