Use Jaeger to report C++ application data

Updated at: 2025-01-24 07:38

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 the 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. On the page that appears, 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. Set the Client parameter to Jaeger or Zipkin. In this example, Jaeger is selected.

    Obtain the 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 the VPC endpoint. Otherwise, use the 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 the data reported?

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

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

    image

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.

    Note

    Replace <endpoint> with the endpoint of the region in which your client resides. You can log on to the Managed Service for OpenTelemetry console and view the endpoint on the Access point information tab of the Cluster Configurations page. For more information about how to obtain the endpoint, see the "Prerequisites" section of this 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 image 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 Managed Service for OpenTelemetry console.

    Note

    Replace <endpoint> with the endpoint of the region in which your client resides. You can log on to the Managed Service for OpenTelemetry console and view the endpoint on the Access point information tab of the Cluster Configurations page. For more information about how to obtain the endpoint, see the "Prerequisites" section of this 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>
  • On this page (1, T)
  • Prerequisites
  • Background information
  • Getting started
  • Use the Jaeger agent to report data
Feedback
phone Contact Us

Chat now with Alibaba Cloud Customer Service to assist you in finding the right products and services to meet your needs.

alicare alicarealicarealicare