grpc/examples/python/observability
Xuan Wang 4f3fba65fb
[Python CSM] Add example for CSM O11Y (#36829)
Verified that when following User Guide, we're able to collect metrics
and export to GCP.
Images are available at:
*
`us-docker.pkg.dev/grpc-testing/examples/csm-o11y-example-python-client:latest`
*
`us-docker.pkg.dev/grpc-testing/examples/csm-o11y-example-python-server:latest`
<!--

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.

-->
2024-06-07 11:20:23 -07:00
..
csm [Python CSM] Add example for CSM O11Y (#36829) 2024-06-07 11:20:23 -07:00
README.md [Python O11Y] Add observability example (#35637) 2024-01-25 10:04:06 -08:00
helloworld_pb2.py [Python O11Y] Add observability example (#35637) 2024-01-25 10:04:06 -08:00
helloworld_pb2.pyi [Python O11Y] Add observability example (#35637) 2024-01-25 10:04:06 -08:00
helloworld_pb2_grpc.py [Python O11Y] Add observability example (#35637) 2024-01-25 10:04:06 -08:00
observability_greeter_client.py [Python O11y] Change public interface (#36094) 2024-03-14 09:37:19 -07:00
observability_greeter_server.py [Python O11y] Change public interface (#36094) 2024-03-14 09:37:19 -07:00
open_telemetry_exporter.py [Python O11Y] Add observability example (#35637) 2024-01-25 10:04:06 -08:00
requirements.txt [Python Otel] Remove opentelemetry version pin (#36448) 2024-04-29 10:40:27 -07:00

README.md

gRPC Observability Example

The examples here demonstrate how to setup gRPC Python Observability with Opentelemetry.

More details about how to use gRPC Python Observability APIs can be found in OpenTelemetry Metrics gRFC.

Install Requirements

  1. Navigate to this directory:
cd examples/python/observability
  1. Install requirements:
python -m pip install -r requirements.txt

Run the Server

Start the server:

python -m observability_greeter_server

Run the Client

Note that client should start within 10 seconds of the server becoming active.

python -m observability_greeter_client

Verifying Metrics

The example will print a list of metric names collected.

Server Side:

Server started, listening on 50051
Metrics exported on Server side:
grpc.server.call.started
grpc.server.call.sent_total_compressed_message_size
grpc.server.call.rcvd_total_compressed_message_size
grpc.server.call.duration

Client Side:

Greeter client received: Hello You
Metrics exported on client side:
grpc.client.call.duration
grpc.client.attempt.started
grpc.client.attempt.sent_total_compressed_message_size
grpc.client.attempt.rcvd_total_compressed_message_size
grpc.client.attempt.duration