All Products
Search
Document Center

Application Real-Time Monitoring Service:Use Jaeger to report C++ application data

Last Updated:Jan 12, 2024

Before you can view the trace data of your application in the Managed Service for OpenTelemetry console, you must use a client to submit the trace data to Managed Service for OpenTelemetry. This topic shows 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 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.

Background information

How is data reported?

  • The following figure shows how to report data without using the Jaeger agent. 不通过Jaeger Agent而直接上报

  • The following figure shows how to report data by using the Jaeger agent.

    通过Jaeger Agent上报数据

Getting started

  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. Decompress and open the jaeger-client-cpp file. Then, run the following command to compile the jaeger-client-cpp file.

    Note

    The compilation depends on CMake and the version of GCC cannot be earlier than 4.9.2.

    mkdir build
        cd build
        cmake ..
        make
  3. Download Jaeger Agent and start Agent by specifying the following parameters to report data to the Managed Service for OpenTelemetry console.

    Important

    Replace <endpoint> with the endpoint of the region where the client resides. You can obtain the endpoint on the Overview page in the Managed Service for OpenTelemetry console. For more information, see the Prerequisites topic.

    // The reporter.grpc.host-port parameter specifies an endpoint. The endpoint varies based on the region.  Example:
    nohup ./jaeger-agent --reporter.grpc.host-port=tracing-analysis-dc-sz.aliyuncs.com:1883 --jaeger.tags=<endpoint>
  4. Enter the example directory of jaeger-client-cpp and run test commands.

    ./app ../examples/config.yml

    Log on to the ARMS console. In the left-side navigation pane, choose Application Monitoring > Applications. On the Applications page, click the name of the application. On the page that appears, view the trace data.

    Note

    If the Java图标 icon is displayed in the Language column, the application is connected to Application Monitoring. If a hyphen (-) is displayed, the application is connected to Managed Service for OpenTelemetry.

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, we can generate a Trace object based on the YAML configurations:

    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));
    }

    YAML configuration example:

    disabled: false
    reporter:
      logSpans: true
    sampler:
      type: const
      param: 1
  3. Create a span:

    // Create a span in scenarios where 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 in scenarios where no parent span exists. 
    void tracedFunction()
    {
        auto span = opentracing::Tracer::Global()->StartSpan("tracedFunction");
        tracedSubroutine(span);
    }
  4. Download Jaeger Agent and start Agent by specifying the following parameters to report data to the Tracing Analysis console.

    Important

    Replace <endpoint> with the endpoint of the region where the client resides. You can obtain the endpoint on the Overview page in the Managed Service for OpenTelemetry console. For more information, see the Prerequisites topic.

    // The reporter.grpc.host-port parameter specifies an endpoint. The endpoint varies based on the region.  Example:
    nohup ./jaeger-agent --reporter.grpc.host-port=tracing-analysis-dc-sz.aliyuncs.com:1883 --jaeger.tags=<endpoint>