Files
grpc/examples/cpp/otel/README.md
Yash Tibrewal 3032b5c48d [OTel C++] Add CMake build support (#36063)
Changes -
* Add CMake build support to `grpcpp_otel_plugin`. Currently, we are only supporting the `find_package CONFIG` method for depending on `opentelemetry-cpp`.
* Since, `grpcpp_otel_plugin` is an extension of gRPC, it will not be built by default. To enable building of this target, a new CMake option `gRPC_BUILD_GRPCPP_OTEL_PLUGIN` is being added.
* Also add `CMakeLists.txt` to the otel example.

The `otel_plugin_test` can also be built through cmake but, for the CI to work, there are some additional changes. Those will be made in an upcoming PR.

Closes #36063

COPYBARA_INTEGRATE_REVIEW=https://github.com/grpc/grpc/pull/36063 from yashykt:OTelCMakeSupport 3bc783823b17ed282ae9b6b7bf8a26cedaae30f9
PiperOrigin-RevId: 613734473
2024-03-07 16:12:10 -08:00

1.5 KiB

gRPC C++ OpenTelemetry Example

The opentelemetry example builds on the Hello World Example and changes the gRPC client and server to show a sample way of configuring the gRPC OpenTelemetry plugin with a prometheus exporter.

For more information on the gRPC OpenTelemetry plugin, please refer to - * A66: OpenTelemetry Metrics

Running the example

To run the server -

$ tools/bazel run examples/cpp/otel:greeter_callback_server

To run the client -

$ tools/bazel run examples/cpp/otel:greeter_callback_client

The client continuously sends an RPC to the server every second.

To make sure that the server and client metrics are being exported properly, in a separate terminal, run the following -

$ curl localhost:9464/metrics
$ curl localhost:9465/metrics

NOTE: If the prometheus endpoint configured is overridden, please update the target in the above curl command.

CMake Instructions

The following libraries need to be installed before building the example with CMake -

  • absl
  • protobuf
  • prometheus-cpp
  • opentelemetry-cpp (with the options -DWITH_ABSEIL=ON -DWITH_PROMETHEUS=ON)
  • grpc (with the option -DgRPC_BUILD_GRPCPP_OTEL_PLUGIN=ON)

You can find a complete set of instructions for building gRPC and running the Hello World app in the C++ Quick Start.