# Instrumenting a C++ application

**URL:** <https://discuss.elastic.co/t/instrumenting-a-c-application/245026>\
**Category:** APM\
**Created:** [August 14, 2020, 2:11pm UTC](https://discuss.elastic.co/t/instrumenting-a-c-application/245026 "2020-08-14T14:11:33Z")\
**Posts on this page:** 9\
**Page:** 1

<div class="post-metadata">

**Author:** ![DenProg](https://avatars.discourse-cdn.com/v4/letter/d/779978/32.png) [@DenProg](https://discuss.elastic.co/u/DenProg)\
**Post date:** [August 14, 2020, 2:11pm UTC](https://discuss.elastic.co/t/instrumenting-a-c-application/245026/1 "2020-08-14T14:11:33Z")

</div>

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.

---

<div class="post-metadata">

**Author:** ![felixbarny](https://sea2.discourse-cdn.com/elastic/user_avatar/discuss.elastic.co/felixbarny/32/27341_2.png) [@felixbarny](https://discuss.elastic.co/u/felixbarny)\
**Post date:** [August 14, 2020, 3:04pm UTC](https://discuss.elastic.co/t/instrumenting-a-c-application/245026/2 "2020-08-14T15:04:20Z")

</div>

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](https://github.com/open-telemetry/opentelemetry-cpp)

---

<div class="post-metadata">

**Author:** ![DenProg](https://avatars.discourse-cdn.com/v4/letter/d/779978/32.png) [@DenProg](https://discuss.elastic.co/u/DenProg)\
**Post date:** [August 14, 2020, 4:33pm UTC](https://discuss.elastic.co/t/instrumenting-a-c-application/245026/3 "2020-08-14T16:33:34Z")

</div>

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

---

<div class="post-metadata">

**Author:** ![felixbarny](https://sea2.discourse-cdn.com/elastic/user_avatar/discuss.elastic.co/felixbarny/32/27341_2.png) [@felixbarny](https://discuss.elastic.co/u/felixbarny)\
**Post date:** [August 15, 2020, 8:07am UTC](https://discuss.elastic.co/t/instrumenting-a-c-application/245026/4 "2020-08-15T08:07:12Z")

</div>

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](https://www.elastic.co/guide/en/apm/server/current/events-api.html)

---

<div class="post-metadata">

**Author:** ![DenProg](https://avatars.discourse-cdn.com/v4/letter/d/779978/32.png) [@DenProg](https://discuss.elastic.co/u/DenProg)\
**Post date:** [August 20, 2020, 12:14pm UTC](https://discuss.elastic.co/t/instrumenting-a-c-application/245026/5 "2020-08-20T12:14:26Z")

</div>

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

```auto
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

```auto
    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?

---

<div class="post-metadata">

**Author:** ![felixbarny](https://sea2.discourse-cdn.com/elastic/user_avatar/discuss.elastic.co/felixbarny/32/27341_2.png) [@felixbarny](https://discuss.elastic.co/u/felixbarny)\
**Post date:** [August 20, 2020, 1:15pm UTC](https://discuss.elastic.co/t/instrumenting-a-c-application/245026/6 "2020-08-20T13:15:57Z")

</div>

We only support the trace exporter at the moment.

> [@DenProg](#):
>
> 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?

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

---

<div class="post-metadata">

**Author:** ![axw](https://sea2.discourse-cdn.com/elastic/user_avatar/discuss.elastic.co/axw/32/28197_2.png) [@axw](https://discuss.elastic.co/u/axw)\
**Post date:** [August 21, 2020, 1:03am UTC](https://discuss.elastic.co/t/instrumenting-a-c-application/245026/7 "2020-08-21T01:03:32Z")

</div>

> [@DenProg](#):
>
> 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?

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](https://github.com/open-telemetry/opentelemetry-cpp/tree/master/examples/simple) does:

> In this example, the application in `main.cc` initializes and registers a tracer provider from the [OpenTelemetry SDK](https://github.com/open-telemetry/opentelemetry-cpp). The application then calls a `foo_library` which has been instrumented using the [OpenTelemetry API](https://github.com/open-telemetry/opentelemetry-cpp/tree/master/api). **Resulting telemetry is directed to stdout through the StdoutSpanExporter**.

(Emphasis mine.)

You need to use the [OTLP exporter](https://github.com/open-telemetry/opentelemetry-cpp/tree/master/exporters/otlp) 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](https://gitter.im/open-telemetry/opentelemetry-cpp).

---

<div class="post-metadata">

**Author:** ![DenProg](https://avatars.discourse-cdn.com/v4/letter/d/779978/32.png) [@DenProg](https://discuss.elastic.co/u/DenProg)\
**Post date:** [August 21, 2020, 5:02am UTC](https://discuss.elastic.co/t/instrumenting-a-c-application/245026/8 "2020-08-21T05:02:14Z")

</div>

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.

---

<div class="post-metadata">

**Author:** ![system](https://us1.discourse-cdn.com/elastic/original/3X/1/a/1ac57faf039f6b580b3f104ef42a2a89e41014de.png) [@system](https://discuss.elastic.co/u/system)\
**Post date:** [September 11, 2020, 1:02am UTC](https://discuss.elastic.co/t/instrumenting-a-c-application/245026/9 "2020-09-11T01:02:26Z")

</div>

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