grpc/examples/cpp/gcp_observability/helloworld
Yash Tibrewal bdd1ac4d1d
[GcpObservability C++] De-experimentalize API (#32715)
This PR aims to de-experimentalize the APIs for GCP Observability. 

We would have ideally wanted public feedback before declaring the APIs
stable, but we need stable APIs for GA.

Changes made after API review with @markdroth @veblush, @ctiller and the
entire Core/C++ team -
* The old experimental APIs `grpc::experimental::GcpObservabilityInit`
and `grpc::experimental::GcpObservabilityClose` are now deprecated and
will be deleted after v.1.55 release.
* The new API gets rid of the Close method and follows the RAII idiom
with a single `grpc::GcpObservability::Init()` call that returns an
`GcpObservability` object, the lifetime of which controls when
observability data is flushed.
* The `GcpObservability` class could in the future add more methods. For
example, a debug method that shows the current configuration.
* Document that GcpObservability initialization and flushing (on
`GcpObservability` destruction) are blocking calls.
* Document that gRPC is still usable if GcpObservability initialization
failed. (Added a test to prove the same).
* Since we don't have a good way to flush stats and tracing with
OpenCensus, the examples required users to sleep for 25 seconds. This
sleep is now part of `GcpObservability` destruction.

Additional Implementation details -
* `GcpObservability::Init` is now marked with `GRPC_MUST_USE_RESULT` to
make sure that the results are used. We ideally want users to store it,
but this is better than nothing.
* Added a note on GCP Observability lifetime guarantees.

<!--

If you know who should review your pull request, please assign it to
that
person, otherwise the pull request would get assigned randomly.

If your pull request is for a specific language, please add the
appropriate
lang label.

-->
2023-04-05 21:45:21 +00:00
..
.gitignore Gcp Observability: Add example (#32710) 2023-03-27 12:59:45 -07:00
BUILD Gcp Observability: Add example (#32710) 2023-03-27 12:59:45 -07:00
README.md GCP Observability: Fix instructions for README (#32730) 2023-03-27 21:33:28 -07:00
client_config.json Gcp Observability: Add example (#32710) 2023-03-27 12:59:45 -07:00
greeter_client.cc [GcpObservability C++] De-experimentalize API (#32715) 2023-04-05 21:45:21 +00:00
greeter_server.cc [GcpObservability C++] De-experimentalize API (#32715) 2023-04-05 21:45:21 +00:00
server_config.json Gcp Observability: Add example (#32710) 2023-03-27 12:59:45 -07:00

README.md

gRPC C++ GCP Observability Hello World Example

This example consists of a hello world client and a hello world server instrumented with GCP Observability for logs, metrics and tracing. Note that familiarity with the basic hello world example is assumed.

Please refer to GCP's Microservices Observability user guide for setup instructions.

Run the example with configuration

To use Observability, you should first setup and configure authorization as mentioned in the Microservices Observability user guide.

You need to set the GRPC_GCP_OBSERVABILITY_CONFIG_FILE environment variable to point to the gRPC GCP Observability configuration file (preferred) or alternatively set GRPC_GCP_OBSERVABILITY_CONFIG environment variable to gRPC GCP Observability configuration value. This is needed by both client and server.

Sample configurations are provided with the example.

To start the observability-enabled example server on its default port of 50051, run the following from the grpc directory:

$ export
    GRPC_GCP_OBSERVABILITY_CONFIG_FILE="$(pwd)/examples/cpp/gcp_observability/helloworld/server_config.json"
$ tools/bazel run examples/cpp/gcp_observability/helloworld:greeter_server

In a different terminal window, run the observability-enabled example client:

$ export
    GRPC_GCP_OBSERVABILITY_CONFIG_FILE="$(pwd)/examples/cpp/gcp_observability/helloworld/client_config.json"
$ tools/bazel run examples/cpp/gcp_observability/helloworld:greeter_client