All Products
Search
Document Center

Managed Service for OpenTelemetry:Use Jaeger to report C++ application data

Last Updated:Apr 02, 2025

Managed Service for OpenTelemetry monitors your application after you use Jaeger to instrument it and report its trace data. You can view the monitoring data such as its topology, traces, abnormal and slow transactions, and SQL analysis data. This topic shows how to use Jaeger to instrument a C++ application and report its data.

Important

We recommend that you connect your application to Managed Service for OpenTelemetry by using OpenTelemetry Protocol (OTLP). In this case, you are provided with more features, more advanced tracing capabilities, and the best user experience.

Alibaba Cloud provides detailed instructions on how to integrate OpenTelemetry with an application and the best practices of using OpenTelemetry to help you quickly get started with Managed Service for OpenTelemetry. For more information, see Preparations.

Prerequisites

Obtain an endpoint

New console

  1. Log on to the Managed Service for OpenTelemetry console. In the left-side navigation pane, click Integration Center.

  2. On the Integration Center page, click the Jaeger card in the Open Source Frameworks section.

  3. In the Jaeger panel, click the Start Integration tab, and then select a region in which you want to report data.

    Note

    When you access a region for the first time, resources are automatically initialized there.

  4. Configure the Connection Type and Export Protocol parameters and copy an endpoint.

    • Connection Type: If your service is deployed on Alibaba Cloud and resides in the region that you selected, we recommend that you set this parameter to Alibaba Cloud VPC Network. Otherwise, set this parameter to Public Network.

    • Export Protocol: Set this parameter to HTTP (recommended) or gRPC based on the protocol that is supported by the client.

    image

Old console

  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 which you want to report data. In the Cluster Information section, turn on Show Token.

  4. Set the Client parameter to Jaeger.

    In the Related Information column of the table, copy an endpoint.jager中国.jpg

    Note

    If your application is deployed in an Alibaba Cloud production environment, use a VPC endpoint. Otherwise, use a public endpoint.

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. Extract the package and enter the directory. Then, run the following command to build the project.

    Note

    CMake is required and the version of GCC must be V4.9.2 or later.

    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 one you retrieved in the Prerequisites section.

    # 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

    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.

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 one you retrieved in the Prerequisites section.

    # 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>