In v2.16, we GA'd OpenTelemetry tracing. This provides basic instrumentation for all the google-cloud-cpp libraries.
In v2.19 release[^1], we added instrumentation for the Google Cloud Pub/Sub C++ library on the Publish side. This example provides a basic tracing application that exports spans to Cloud Trace.
[^1]: The telemetry data emitted by the google-cloud-cpp library does not follow any versioning guarantees and is subject to change without notice in later versions.
The quickstart creates a tracing enabled Pub/Sub Publisher client that publishes 5 messages and sends the collected traces to Cloud Trace.
To find the traces, navigate to the Cloud Trace UI.
For an overview of the Cloud Trace UI, see: Find and explore traces.
If you haven't already created a project, create one now.
Projects enable you to manage all Google Cloud Platform resources for your app, including deployment, access control, billing, and services.
- Open the Cloud Platform Console.
- In the drop-down menu at the top, select Create a project.
- Give your project a name.
- Make a note of the project ID, which might be different from the project name. The project ID is used in commands and in configurations.
If you haven't already enabled billing for your project, enable billing now. Enabling billing allows the application to consume billable resources such as Pub/Sub API calls.
See Cloud Platform Console Help for more information about billing settings.
Click here to visit Cloud Platform Console and enable the Pub/Sub and Trace API via the UI.
Or use the CLI:
gcloud services enable trace.googleapis.com
gcloud services enable pubsub.googleapis.com
export=GOOGLE_CLOUD_PROJECT=<project-id>
export=GOOGLE_CLOUD_TOPIC=<topic-id>
gcloud pubsub topics create "--project=${GOOGLE_CLOUD_PROJECT}" ${GOOGLE_CLOUD_TOPIC}
This project uses vcpkg
for dependency
management. Clone the vcpkg repository to your preferred location. In these
instructions we use$HOME
:
git clone -C $HOME https://github.com/microsoft/vcpkg.git
cd $HOME/vcpkg
./vcpkg install google-cloud-cpp
git clone https://github.com/GoogleCloudPlatform/cpp-samples
Use the vcpkg
toolchain file to download and compile dependencies. This file
would be in the directory you cloned vcpkg
into, $HOME/vcpkg
if you are
following the instructions to the letter. Note that building all the
dependencies can take up to an hour, depending on the performance of your
workstation. These dependencies are cached, so a second build should be
substantially faster.
cd cpp-samples/pubsub-open-telemetry
cmake -S . -B .build -DCMAKE_TOOLCHAIN_FILE=$HOME/vcpkg/scripts/buildsystems/vcpkg.cmake -G Ninja
cmake --build .build --target quickstart
.build/quickstart ${GOOGLE_CLOUD_PROJECT} ${GOOGLE_CLOUD_TOPIC}
git clone https://github.com/GoogleCloudPlatform/cpp-samples
cd cpp-samples/pubsub-open-telemetry
bazel build //:quickstart
bazel run //:quickstart -- ${GOOGLE_CLOUD_PROJECT} ${GOOGLE_CLOUD_TOPIC}
bazel run --override_repository=google_cloud_cpp=$HOME/your-path-to-the-repo/google-cloud-cpp \
//:quickstart -- ${GOOGLE_CLOUD_PROJECT} ${GOOGLE_CLOUD_TOPIC}
gcloud pubsub topics delete "--project=${GOOGLE_CLOUD_PROJECT}" ${GOOGLE_CLOUD_TOPIC}
gRPC requires an environment variable to configure the trust store for SSL certificates, you can download and configure this using:
curl -Lo roots.pem https://pki.google.com/roots.pem
export GRPC_DEFAULT_SSL_ROOTS_FILE_PATH="$PWD/roots.pem"
gRPC requires an environment variable to configure the trust store for SSL certificates, you can download and configure this using:
@powershell -NoProfile -ExecutionPolicy unrestricted -Command ^
(new-object System.Net.WebClient).Downloadfile( ^
'https://pki.google.com/roots.pem', 'roots.pem')
set GRPC_DEFAULT_SSL_ROOTS_FILE_PATH=%cd%\roots.pem