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
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: https://github.com/open-telemetry/opentelemetry-cpp
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: https://www.elastic.co/guide/en/apm/server/current/events-api.html
Felix, thanks for your answers.
I decided to use OpenTelemetry. I installed opentelemetry-collector-contrib and create the config:
receivers: otlp: protocols: grpc: otlp/withendpoint: protocols: grpc: endpoint: 127.0.0.1:55680 processors: batch: timeout: 1s send_batch_size: 1024 exporters: elastic: apm_server_url: "https://localhost:8200" service: pipelines: traces: receivers: [otlp] processors: [batch] exporters: [elastic]
The server runs well. But if I add
metrics: 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
main.ccinitializes and registers a tracer provider from the OpenTelemetry SDK. The application then calls a
foo_librarywhich has been instrumented using the OpenTelemetry API. Resulting telemetry is directed to stdout through the StdoutSpanExporter.
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 https://gitter.im/open-telemetry/opentelemetry-cpp.
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.