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

  1. Log on to Tracing Analysis console, in the Region-specific Information area, turn on View Token.
  2. In the Client area, click the desired tracing client.
  3. In the Related Information column in the table below, click the copy icon at the end of Endpoint information.

Background information

The workflow of reporting data directly without Agent is as shown in the following figure.

Report Tracing Data Directly

The workflow of reporting data through Agent is as shown in the following figure.

Report Tracing Data By Agent

Directly report data

  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 jaeger-agent. Then, set the following parameter to start the agent. This way, you can report data to Tracing Analysis.
    Notice Replace <endpoint> with the corresponding endpoint in the corresponding region that is displayed on the Overview page. For more information about how to obtain access point information, see Obtain access point information.
    // Reporter. grpc. host-port is used to set the gateway. The Gateway varies according to the region. Example:
    $ 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, visit 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 jaeger-agent. Then, set the following parameter to start the agent. This way, you can report data to Tracing Analysis.
    Notice Replace <endpoint> with the corresponding endpoint in the corresponding region that is displayed on the Overview page. For more information about how to obtain access point information, see Obtain access point information.
    // Reporter. grpc. host-port is used to set the gateway. The Gateway varies according to the region. Example:
    $ nohup. /jaeger-agent --reporter.grpc.host-port=tracing-analysis-dc-sz.aliyuncs.com:1883 --jaeger.tags=<endpoint>