Instrument a C++ application with the Jaeger client library to report trace data to Managed Service for OpenTelemetry. After integration, the ARMS console displays application topology, traces, abnormal and slow transactions, and SQL analysis data.
The Jaeger project no longer maintains its client SDKs. All users are advised to migrate to OpenTelemetry. Connect your application through OpenTelemetry Protocol (OTLP) for broader feature support and better tracing capabilities. For OTLP integration instructions, see Preparations.
How data reporting works
There are two ways to report trace data to the backend:
Direct reporting (without Jaeger Agent): Your application sends spans directly to the Managed Service for OpenTelemetry backend over HTTP or gRPC.
Agent-based reporting (with Jaeger Agent): Your application sends spans to a local Jaeger Agent, which forwards them to the backend.
Prerequisites
Before you begin, make sure you have:
CMake installed
GCC V4.9.2 or later
Quick start
Build the Jaeger C++ client, run the built-in example, and verify that trace data reaches the console.
Download jaeger-client-cpp:
wget https://github.com/jaegertracing/jaeger-client-cpp/archive/master.zip && unzip master.zipEnter the project directory and build:
mkdir build cd build cmake .. makeDownload the Jaeger Agent and start it. Replace
<endpoint>with the endpoint you copied in Get a reporting endpoint.# The reporter.grpc.host-port value is your region-specific endpoint. nohup ./jaeger-agent --reporter.grpc.host-port=tracing-analysis-dc-sz.aliyuncs.com:1883 --jaeger.tags=<endpoint>Run the built-in example:
./app ../examples/config.ymlVerify trace data in the console:
Log on to the ARMS console.
In the left-side navigation pane, choose Application Monitoring > Applications.
Click your application name to view trace data.
NoteIf the
icon appears in the Language column, the application is connected to Application Monitoring. If a hyphen (-) appears, the application is connected to Managed Service for OpenTelemetry.
Instrument your application
To instrument your own C++ application with the Jaeger Agent, complete the following steps: install the client, create a tracer, create spans, and start the agent to forward data.
Step 1: Install the Jaeger client
Download and build jaeger-client-cpp. For installation instructions and source code, see jaeger-client-cpp.
Step 2: Create a tracer
Create a tracer from a YAML configuration file. The tracer is registered as a global singleton so all parts of your application can access it.
void setUpTracer(const char* configFilePath)
{
auto configYAML = YAML::LoadFile(configFilePath);
// Parse the YAML configuration.
auto config = jaegertracing::Config::parse(configYAML);
// Create a tracer with a service name and logger.
auto tracer = jaegertracing::Tracer::make(
"example-service", config, jaegertracing::logging::consoleLogger());
// Register the tracer as the global tracer.
opentracing::Tracer::InitGlobal(
std::static_pointer_cast<opentracing::Tracer>(tracer));
}The following YAML file configures the tracer to sample all requests and log spans to the console:
disabled: false
reporter:
logSpans: true
sampler:
type: const
param: 1Step 3: Create spans
Create a root span for top-level operations and child spans for sub-operations:
// Create a child span under an existing parent span.
void tracedSubroutine(const std::unique_ptr<opentracing::Span>& parentSpan)
{
auto span = opentracing::Tracer::Global()->StartSpan(
"tracedSubroutine", { opentracing::ChildOf(&parentSpan->context()) });
}
// Create a root span with no parent.
void tracedFunction()
{
auto span = opentracing::Tracer::Global()->StartSpan("tracedFunction");
tracedSubroutine(span);
}Step 4: Start the Jaeger Agent and report data
Download the Jaeger Agent and start it. Replace <endpoint> with the endpoint you copied in Get a reporting endpoint.
# The reporter.grpc.host-port value is your region-specific endpoint.
nohup ./jaeger-agent --reporter.grpc.host-port=tracing-analysis-dc-sz.aliyuncs.com:1883 --jaeger.tags=<endpoint>