Instrumenting a C++ application

I didn't find any topic like that... Which library should I use to instrument a C++ application? We found the Elastic APM system very appropriate for our software, but we have C++ apps and we want to collect custom data from them - metrics, errors, exceptions. I googled a lot, but didn't find any library for that.

Hi and welcome to the forum :wave:

We don’t have an official Elastic c++ agent. However, we do support ingesting OpenTelemetry data via the OT collector exporter that can send data to APM Server.

There is an OpenTelemetry SDK available for C++, although it’s not generally available yet:

An unready library is not a case... I found here on the forum a man used the REST API to connect a C++ app to the server. Is it possible? I don't understand how such a popular system can not have even an unofficial C++ library...

Yes, you can also manually send events to the APM Server intake API:

Felix, thanks for your answers.
I decided to use OpenTelemetry. I installed opentelemetry-collector-contrib and create the config:


    timeout: 1s
    send_batch_size: 1024

    apm_server_url: "https://localhost:8200"

      receivers: [otlp]
      processors: [batch]
      exporters: [elastic]

The server runs well. But if I add

      receivers: [otlp]
      processors: [batch]
      exporters: [elastic]

I get the error:
Error: cannot setup pipelines: cannot build builtExporters: pipeline "metrics" of data type "metrics" has an exporter "elastic", which does not support that data type
So, can I use the OT exporter for metrics or only for traces?
I tried some examples from opentelemetry-cpp. They runs, get some output to the console, but should they output something to the input port of the OT service? Or how should it work?

We only support the trace exporter at the moment.

I'm not really sure what you mean by that. Could you elaborate a bit? I'd suggest creating a separate thread for it.

The OpenTelemetry SDKs have pluggable "exporters". This is how telemetry data (traces, metrics, ...) gets to the OpenTelemetry Collector, or some other service.

If the examples are printing data to stdout, then they've probably been written to use the "ostream" exporter. For example, that's what opentelemetry-cpp/examples/simple does:

In this example, the application in initializes and registers a tracer provider from the OpenTelemetry SDK. The application then calls a foo_library which has been instrumented using the OpenTelemetry API. Resulting telemetry is directed to stdout through the StdoutSpanExporter.

(Emphasis mine.)

You need to use the OTLP exporter to send data to OpenTelemetry Collector. If you have trouble with the C++ SDK, I would recommend seeking advice at

Andrew, thank you for your answer, it would help me if opentelemetry-collector-contrib supported metrics. Supporting only traces is not enough. I will try to use the REST API. May be I need to write a library for it.

This topic was automatically closed 20 days after the last reply. New replies are no longer allowed.