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
Background information
Getting started
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
Decompress and open the jaeger-client-cpp file. Then, run the following command to compile the jaeger-client-cpp file.
NoteThe compilation depends on CMake and the version of GCC cannot be earlier than 4.9.2.
mkdir build cd build cmake .. make
Download Jaeger Agent and start Agent by specifying the following parameters to report data to the Managed Service for OpenTelemetry console.
ImportantReplace
<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>
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 . On the Applications page, click the name of the application. On the page that appears, view the trace data.
NoteIf the 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
Install a Jaeger client. For more information about how to download a Jaeger client, see jaeger-client-cpp.
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
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); }
Download Jaeger Agent and start Agent by specifying the following parameters to report data to the Tracing Analysis console.
ImportantReplace
<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>