Before you can view the trace data of your application in the Tracing Analysis console, you must use a client to report the trace data to Tracing Analysis. This topic shows you how to use Jaeger to report the data of C++ applications.

Prerequisites

To obtain an endpoint of Jaeger or Zipkin, perform the following steps:
  1. Log on to the Tracing Analysis console. In the top navigation bar, select a region.
  2. In the left-side navigation pane, click Cluster Configurations. Then, click the Access point information tab.
  3. In the Cluster Information section of the Access point information tab, 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.

    Endpoint of Jaeger or Zipkin
    Note
    • If your application is deployed in an Alibaba Cloud production environment, use a private 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.

Background information

How is data reported?
  • The following figure shows how to report data without using the Jaeger agent. Report data without using the Jaeger agent
  • The following figure shows how to report data by using the Jaeger agent. Use the Jaeger agent to report data

Quick start

  1. Run the following command to obtain jaeger-client-cpp from the official website:
    wget https://github.com/jaegertracing/jaeger-client-cpp/archive/master.zip && unzip master.zip
  2. Run the following commands to compile jaeger-client-cpp:
    Note The compilation depends on CMake. The GCC version must be 4.9.2 or later.
    mkdir build
        cd build
        cmake ..
        make
  3. Download the native Jaeger agent and set the reporter.grpc.host-port parameter to start the agent. This way, data can be reported to Tracing Analysis.
    Important Replace <endpoint> with the endpoint of the region where the client resides. You can obtain the endppoint on the Overview page in the Tracing Analysis console. For more information, see the Prerequisites topic.
    // The reporter.grpc.host-port parameter specifies an endpoint. The endpoint varies based on the region.  Examples:
    nohup ./jaeger-agent --reporter.grpc.host-port=tracing-analysis-dc-sz.aliyuncs.com:1883 --jaeger.tags=<endpoint>
  4. Go to the examples directory of jaeger-client-cpp and run the test case.
    ./app ../examples/config.yml
  5. Log on to the Tracing Analysis console and view the reported data.

Use the Jaeger agent to report data

  1. Install a Jaeger client. For more information about how to download a Jaeger client, see jaeger-client-cpp.
  2. Create a Tracer object.

    For example, you can create a Tracer object based on the YAML configuration.

    void setUpTracer(const char* configFilePath)
    {
        auto configYAML = YAML::LoadFile(configFilePath);
        // Import the configuration from the YAML file. 
        auto config = jaegertracing::Config::parse(configYAML);
        // Set the service name and logger of the Tracer object. 
        auto tracer = jaegertracing::Tracer::make(
            "example-service", config, jaegertracing::logging::consoleLogger());
        // Set the Tracer object as a global variable. 
        opentracing::Tracer::InitGlobal(
            std::static_pointer_cast<opentracing::Tracer>(tracer));
    }

    Example of the YAML configuration:

    disabled: false
    reporter:
        logSpans: true
    sampler:
      type: const
      param: 1
  3. Create a span.
    // Create a span when a parent span exists. 
    void tracedSubroutine(const std::unique_ptr<opentracing::Span>& parentSpan)
    {
        auto span = opentracing::Tracer::Global()->StartSpan(
            "tracedSubroutine", { opentracing::ChildOf(&parentSpan->context()) });
    }
    
    // Create a span when no parent span exists. 
    void tracedFunction()
    {
        auto span = opentracing::Tracer::Global()->StartSpan("tracedFunction");
        tracedSubroutine(span);
    }
  4. Download the native Jaeger agent and set the reporter.grpc.host-port parameter to start the agent. This way, data can be reported to Tracing Analysis.
    Important Replace <endpoint> with the endpoint of the region where the client resides. You can obtain the endppoint on the Overview page in the Tracing Analysis console. For more information, see the Prerequisites topic.
    // The reporter.grpc.host-port parameter specifies an endpoint. The endpoint varies based on the region.  Examples:
    nohup ./jaeger-agent --reporter.grpc.host-port=tracing-analysis-dc-sz.aliyuncs.com:1883 --jaeger.tags=<endpoint>