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.
- Run
git clone https://github.com/open-telemetry/opentelemetry-cpp
. - Copy the
Dockerfile.ubuntu
,docker-compose-collector.yaml
, and theconfig.dev.yaml
example files to the root of the directory cloned in step 1. - Edit
config.dev.yaml
with your license key and endpoint. - Run
docker-compose -f docker-compose-collector.yaml up
. - 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:
cd /usr/src/myapp
mkdir build
cd build
rm -rf *
cmake -DCMAKE_BUILD_TYPE=Debug \-DWITH_METRICS_PREVIEW=ON \-DWITH_LOGS_PREVIEW=ON \-DCMAKE_CXX_FLAGS="-Wno-error=deprecated-declarations" \-DWITH_OTLP=ON \..
cd examples
make
cd otlp
./example_otlp_http
3. View your data
Verify data has arrived by querying your New Relic account data:
- To see span data: Go to one.newrelic.com > Query your data and enter this query:
FROM Span SELECT * where telemetry.sdk.name = 'opentelemetry'
- 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.04ENV DEBIAN_FRONTEND noninteractive
## Update cache and upgrade imageRUN apt-get -y update && apt-get -y upgrade && apt-get -y dist-upgrade
## Build environment packagesRUN 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-toolsADD ci/setup_cmake.sh /setup-toolsADD 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 bashCMD /bin/bash
config.dev.yaml
exporters: newrelic: apikey: 'EDIT_TO_ADD_YOUR_KEY_HERE' timeout: 30s host_override: "otlp.nr-data.net" logging: loglevel: DEBUGreceivers: 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