CMake needs following two changes which were missed part from https://github.com/grpc/grpc/pull/37919 to make CMake use C++17. - **Explicitly require C++17 for gRPC targets using `cxx_std_17`**: This ensures that gRPC build targets are built with the correct C++17 support. - **Enforce C++17 for all CMake invocations using `CMAKE_CXX_STANDARD=17`**: This is necessary due to Abseil's API changes depending on the C++ standard used. (e.g. Abseil's `absl::string_view` is implemented differently depending on the C++ standard. Before C++17, it's a distinct type. From C++17 onwards, it's simply an alias for `std::string_view`.) To maintain consistency and avoid build errors, all CMake builds (except particular build tests targetting C++20 or C++23) are now configured to use C++17. The requirement of C++17 for building gRPC should be documented in the release notes and build instructions. Closes #38335 PiperOrigin-RevId: 712926964 |
1 month ago | |
---|---|---|
.. | ||
codelab | [clang-format] Remove custom clang-format rules for include ordering (#37820) | 5 months ago |
ostream | [C++] Transition to C++17 (CMake) (#38335) | 1 month ago |
BUILD | [Examples] Remove grpcpp_admin dependency (#38196) | 3 months ago |
CMakeLists.txt | [Build] Bumped the minimum version of cmake (#37702) | 5 months ago |
Makefile | [C++] Transition to C++17 (CMake) (#38335) | 1 month ago |
README.md | [OTel C++] Add CMake build support (#36063) | 12 months ago |
greeter_callback_client.cc | [OTel] Set prometheus exporter option to populate otel scope (#38170) | 3 months ago |
greeter_callback_server.cc | [OTel] Set prometheus exporter option to populate otel scope (#38170) | 3 months ago |
util.cc | [Examples] Remove grpcpp_admin dependency (#38196) | 3 months ago |
util.h | [CSM] Use xds-enabled server and xds credentials in examples (#38192) | 3 months ago |
README.md
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
- https://opentelemetry.io/
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.