This directory contains components to export traces captured with OpenTelemetry to Cloud Trace. Traces are a form of telemetry where calls across multiple distributed systems can be collected in a centralized view, showing the sequence of calls and their latency. Cloud Trace can provide such views of your system calls.
The C++ client libraries are already instrumented to collect traces. You can enable the collection and export of traces with minimal changes to your application. It is not necessary to instrument your application too.
This library is experimental. Its APIs are subject to change without notice.
Please note Google Cloud C++ client libraries do not follow Semantic Versioning.
Quickstart
The following shows the code that you'll run in the google/cloud/opentelemetry/quickstart/ directory, which demonstrates how to enable tracing in the Google Cloud client libraries.
#include "google/cloud/opentelemetry/configure_basic_tracing.h"
#include "google/cloud/storage/client.h"
#include "google/cloud/opentelemetry_options.h"
#include <iostream>
int main(int argc, char* argv[]) {
if (argc != 3) {
std::cerr << "Usage: " << argv[0] << " <bucket-name> <project-id>\n";
return 1;
}
std::string const bucket_name = argv[1];
std::string const project_id = argv[2];
// Create aliases to make the code easier to read.
namespace gc = ::google::cloud;
namespace gcs = ::google::cloud::storage;
// Instantiate a basic tracing configuration which exports traces to Cloud
// Trace. By default, spans are sent in batches and always sampled.
auto project = gc::Project(project_id);
auto configuration = gc::otel::ConfigureBasicTracing(project);
// Create a client with OpenTelemetry tracing enabled.
auto options = gc::Options{}.set<gc::OpenTelemetryTracingOption>(true);
auto client = gcs::Client(options);
auto writer = client.WriteObject(bucket_name, "quickstart.txt");
writer << "Hello World!";
writer.Close();
if (!writer.metadata()) {
std::cerr << "Error creating object: " << writer.metadata().status()
<< "\n";
return 1;
}
std::cout << "Successfully created object: " << *writer.metadata() << "\n";
auto reader = client.ReadObject(bucket_name, "quickstart.txt");
if (!reader) {
std::cerr << "Error reading object: " << reader.status() << "\n";
return 1;
}
std::string contents{std::istreambuf_iterator<char>{reader}, {}};
std::cout << contents << "\n";
// The basic tracing configuration object goes out of scope. The collected
// spans are flushed to Cloud Trace.
return 0;
}
More Information
The Setting up your development environment guide describes how to set up a C++ development environment in various platforms, including the Google Cloud C++ client libraries.
[[["Easy to understand","easyToUnderstand","thumb-up"],["Solved my problem","solvedMyProblem","thumb-up"],["Other","otherUp","thumb-up"]],[["Hard to understand","hardToUnderstand","thumb-down"],["Incorrect information or sample code","incorrectInformationOrSampleCode","thumb-down"],["Missing the information/samples I need","missingTheInformationSamplesINeed","thumb-down"],["Other","otherDown","thumb-down"]],["Last updated 2025-09-04 UTC."],[[["\u003cp\u003eThis webpage provides documentation for the Google Cloud C++ OpenTelemetry Exporters, which facilitate sending traces captured with OpenTelemetry to Cloud Trace.\u003c/p\u003e\n"],["\u003cp\u003eThe latest version available in the documentation is 2.37.0-rc, while version 2.18.0 is noted elsewhere on the page, with many previous releases listed.\u003c/p\u003e\n"],["\u003cp\u003eThe C++ client libraries are instrumented for trace collection, and enabling trace export to Cloud Trace requires minimal application modifications, without needing the user to instrument the application.\u003c/p\u003e\n"],["\u003cp\u003eThe library is experimental, with its APIs subject to change, and the Google Cloud C++ client libraries do not adhere to Semantic Versioning.\u003c/p\u003e\n"],["\u003cp\u003eThe Quickstart guide demonstrates enabling tracing with OpenTelemetry by using code from the \u003ccode\u003egoogle/cloud/opentelemetry/quickstart/\u003c/code\u003e directory to integrate with Google Cloud client libraries, using the sample code provided.\u003c/p\u003e\n"]]],[],null,["Version 2.18.0keyboard_arrow_down\n\n- [2.42.0-rc (latest)](/cpp/docs/reference/opentelemetry/latest)\n- [2.41.0](/cpp/docs/reference/opentelemetry/2.41.0)\n- [2.40.0](/cpp/docs/reference/opentelemetry/2.40.0)\n- [2.39.0](/cpp/docs/reference/opentelemetry/2.39.0)\n- [2.38.0](/cpp/docs/reference/opentelemetry/2.38.0)\n- [2.37.0](/cpp/docs/reference/opentelemetry/2.37.0)\n- [2.36.0](/cpp/docs/reference/opentelemetry/2.36.0)\n- [2.35.0](/cpp/docs/reference/opentelemetry/2.35.0)\n- [2.34.0](/cpp/docs/reference/opentelemetry/2.34.0)\n- [2.33.0](/cpp/docs/reference/opentelemetry/2.33.0)\n- [2.32.0](/cpp/docs/reference/opentelemetry/2.32.0)\n- [2.31.0](/cpp/docs/reference/opentelemetry/2.31.0)\n- [2.30.0](/cpp/docs/reference/opentelemetry/2.30.0)\n- [2.29.0](/cpp/docs/reference/opentelemetry/2.29.0)\n- [2.28.0](/cpp/docs/reference/opentelemetry/2.28.0)\n- [2.27.0](/cpp/docs/reference/opentelemetry/2.27.0)\n- [2.26.0](/cpp/docs/reference/opentelemetry/2.26.0)\n- [2.25.1](/cpp/docs/reference/opentelemetry/2.25.1)\n- [2.24.0](/cpp/docs/reference/opentelemetry/2.24.0)\n- [2.23.0](/cpp/docs/reference/opentelemetry/2.23.0)\n- [2.22.1](/cpp/docs/reference/opentelemetry/2.22.1)\n- [2.21.0](/cpp/docs/reference/opentelemetry/2.21.0)\n- [2.20.0](/cpp/docs/reference/opentelemetry/2.20.0)\n- [2.19.0](/cpp/docs/reference/opentelemetry/2.19.0)\n- [2.18.0](/cpp/docs/reference/opentelemetry/2.18.0)\n- [2.17.0](/cpp/docs/reference/opentelemetry/2.17.0)\n- [2.16.0](/cpp/docs/reference/opentelemetry/2.16.0)\n- [2.15.1](/cpp/docs/reference/opentelemetry/2.15.1)\n- [2.14.0](/cpp/docs/reference/opentelemetry/2.14.0) \n\nGoogle Cloud C++ OpenTelemetry Exporters\n========================================\n\nThis directory contains components to export [traces](https://opentelemetry.io/docs/concepts/observability-primer/#distributed-traces) captured with [OpenTelemetry](https://opentelemetry.io/) to [Cloud Trace](https://cloud.google.com/trace). Traces are a form of telemetry where calls across multiple distributed systems can be collected in a centralized view, showing the sequence of calls and their latency. Cloud Trace can provide such views of your system calls.\n\nThe C++ client libraries are already instrumented to collect traces. You can enable the collection and export of traces with minimal changes to your application. It is not necessary to instrument your application too.\n\nThis library is **experimental**. Its APIs are subject to change without notice.\n\nPlease note Google Cloud C++ client libraries do **not** follow [Semantic Versioning](https://semver.org/).\n\n### Quickstart\n\nThe following shows the code that you'll run in the `google/cloud/opentelemetry/quickstart/` directory, which demonstrates how to enable tracing in the Google Cloud client libraries. \n\n #include \"google/cloud/opentelemetry/configure_basic_tracing.h\"\n #include \"google/cloud/storage/client.h\"\n #include \"google/cloud/opentelemetry_options.h\"\n #include \u003ciostream\u003e\n\n int main(int argc, char* argv[]) {\n if (argc != 3) {\n std::cerr \u003c\u003c \"Usage: \" \u003c\u003c argv[0] \u003c\u003c \" \u003cbucket-name\u003e \u003cproject-id\u003e\\n\";\n return 1;\n }\n std::string const bucket_name = argv[1];\n std::string const project_id = argv[2];\n\n // Create aliases to make the code easier to read.\n namespace gc = ::google::cloud;\n namespace gcs = ::google::cloud::storage;\n\n // Instantiate a basic tracing configuration which exports traces to Cloud\n // Trace. By default, spans are sent in batches and always sampled.\n auto project = gc::Project(project_id);\n auto configuration = gc::otel::ConfigureBasicTracing(project);\n\n // Create a client with OpenTelemetry tracing enabled.\n auto options = gc::Options{}.set\u003cgc::OpenTelemetryTracingOption\u003e(true);\n auto client = gcs::Client(options);\n\n auto writer = client.WriteObject(bucket_name, \"quickstart.txt\");\n writer \u003c\u003c \"Hello World!\";\n writer.Close();\n if (!writer.metadata()) {\n std::cerr \u003c\u003c \"Error creating object: \" \u003c\u003c writer.metadata().status()\n \u003c\u003c \"\\n\";\n return 1;\n }\n std::cout \u003c\u003c \"Successfully created object: \" \u003c\u003c *writer.metadata() \u003c\u003c \"\\n\";\n\n auto reader = client.ReadObject(bucket_name, \"quickstart.txt\");\n if (!reader) {\n std::cerr \u003c\u003c \"Error reading object: \" \u003c\u003c reader.status() \u003c\u003c \"\\n\";\n return 1;\n }\n\n std::string contents{std::istreambuf_iterator\u003cchar\u003e{reader}, {}};\n std::cout \u003c\u003c contents \u003c\u003c \"\\n\";\n\n // The basic tracing configuration object goes out of scope. The collected\n // spans are flushed to Cloud Trace.\n\n return 0;\n }\n\n### More Information\n\n- The [Setting up your development environment](https://cloud.google.com/cpp/docs/setup) guide describes how to set up a C++ development environment in various platforms, including the Google Cloud C++ client libraries."]]