• EnglishEspañol日本語한국어Português
  • Log inStart now

C SDK OpenTelemetry alternative

OpenTelemetry C++ is an exciting observability solution with stable functionality and a wide base of contributors in an active codebase. New Relic is compatible with OpenTelemetry and the benefits it can provide, such as future proofing code by putting end-point agnostic instrumentation calls versus adhering to vendor-specific formats.

Please see the New Relic OpenTelemetry setup for detailed instructions on how to use OpenTelemetry to work with the language of your choice to send data to New Relic.

The OpenTelemetry C++ repository has many fine examples in GitHub. See its CONTRIBUTING.md for further instructions on building and using the OpenTelemetry C++ SDK as well as building and running the examples.

Quick start example

Want to get started right away and see what New Relic can do without having to instrument your code? Follow the steps below for an example that will have you sending data to New Relic in no time.

When you're ready to start instrumenting, please refer to the New Relic OpenTelemetry setup instructions and the OpenTelemetry C++ repository CONTRIBUTING.md for further details on integrating with your code.

1. Set up your environment

Ensure you have the prerequisites outlined in the New Relic OpenTelemetry documentation.

  1. Run git clone https://github.com/open-telemetry/opentelemetry-cpp.
  2. Copy the Dockerfile.ubuntu, docker-compose-collector.yaml, and the config.dev.yaml example files to the root of the directory cloned in step 1.
  3. Edit config.dev.yaml with your license key and endpoint.
  4. Run docker-compose -f docker-compose-collector.yaml up.
  5. Verify the two containers are running, one for the collector and one for the C++ application.

2. Run the C++ application

Open a terminal in the C++ container and run the following commands:

  1. cd /usr/src/myapp

  2. mkdir build

  3. cd build

  4. rm -rf *

    bash
    $
    cmake -DCMAKE_BUILD_TYPE=Debug \
    >
    -DWITH_METRICS_PREVIEW=ON \
    >
    -DWITH_LOGS_PREVIEW=ON \
    >
    -DCMAKE_CXX_FLAGS="-Wno-error=deprecated-declarations" \
    >
    -DWITH_OTLP=ON \
    >
    ..
  5. cd examples

  6. make

  7. cd otlp

  8. ./example_otlp_http

3. View your data

Verify data has arrived by querying your New Relic account data:

  1. To see span data: Go to one.newrelic.com > All capabilities > Query your data and enter this query:

    FROM Span SELECT * where telemetry.sdk.name = 'opentelemetry'
  2. View the OpenTelemetry service by searching for unknown_service for more details.

Sample files

docker-compose-collector.yaml

version: '3.7'
services:
cpp:
build:
context: .
dockerfile: Dockerfile.ubuntu
stdin_open: true
environment:
- OTEL_EXPORTER_OTLP_ENDPOINT=otel-collector:4318
volumes:
- ./:/usr/src/myapp
otel-collector:
image: otel/opentelemetry-collector-contrib
stdin_open: true
command: ["--config=/etc/otel-collector-config.yml"]
volumes:
- ./config.dev.yaml:/etc/otel-collector-config.yml
ports:
- "1888:1888" # pprof extension
- "8888:8888" # Prometheus metrics exposed by the collector
- "8889:8889" # Prometheus exporter metrics
- "13133:13133" # health_check extension
- "9411" # Zipkin receiver
- "4317:4317" # OTLP gRPC receiver
- "4318:4318" # OTLP http receiver
- "55680:55679" # zpages extension
depends_on:
- cpp

Dockerfile.ubuntu

FROM ubuntu:20.04
ENV DEBIAN_FRONTEND noninteractive
## Update cache and upgrade image
RUN apt-get -y update && apt-get -y upgrade && apt-get -y dist-upgrade
## Build environment packages
RUN apt-get install -qq -y --ignore-missing \
apt-utils \
automake \
bc \
build-essential \
bzip2 \
cmake \
curl \
git \
libcurl4-openssl-dev \
libssl-dev \
libtool-bin \
make \
pkg-config \
protobuf-compiler \
libprotobuf-dev \
python \
sudo \
tar \
zip \
unzip \
wget \
zlib1g-dev
WORKDIR /setup-tools
ADD ci/setup_ci_environment.sh /setup-tools
ADD ci/setup_cmake.sh /setup-tools
ADD ci/install_protobuf.sh /setup-tools
RUN /setup-tools/setup_ci_environment.sh \
&& /setup-tools/setup_cmake.sh \
&& /setup-tools/install_protobuf.sh
WORKDIR /usr/src/myapp
# ENTRYPOINT bash
CMD /bin/bash

config.dev.yaml

exporters:
newrelic:
apikey: 'EDIT_TO_ADD_YOUR_KEY_HERE'
timeout: 30s
host_override: "otlp.nr-data.net"
logging:
loglevel: DEBUG
receivers:
otlp:
protocols:
grpc:
endpoint: 0.0.0.0:4317
http:
endpoint: 0.0.0.0:4318
cors:
allowed_origins:
- '*'
service:
pipelines:
traces:
receivers:
- otlp
exporters:
- logging
- newrelic
logs:
receivers:
- otlp
exporters:
- logging
Copyright © 2024 New Relic Inc.

This site is protected by reCAPTCHA and the Google Privacy Policy and Terms of Service apply.