grpc-java/examples/example-opentelemetry
Eric Anderson f30964ab82
Bump versions of dependencies (#12252)
Notably, protobuf to 3.25.8, opentelemetry to 1.52.0. Protobuf in Bazel
has 25.5 in the BCR and it seems better to align the WORKSPACE
with that version. But we can't actually use 25.5 in BCR because it is
incompatible with Bazel 7.
2025-08-06 11:01:45 -07:00
..
src/main examples: Add gRPC OpenTelemetry example (#11299) 2024-06-21 14:35:02 -07:00
README.md examples: Add gRPC OpenTelemetry example (#11299) 2024-06-21 14:35:02 -07:00
build.gradle Bump versions of dependencies (#12252) 2025-08-06 11:01:45 -07:00
settings.gradle examples: Add gRPC OpenTelemetry example (#11299) 2024-06-21 14:35:02 -07:00

README.md

gRPC OpenTelemetry Example

The example extends the gRPC "hello world" example by modifying the client and server to showcase a sample configuration for gRPC OpenTelemetry with a Prometheus exporter.

The example requires grpc-java to be pre-built. Using a release tag will download the relevant binaries from a maven repository. But if you need the latest SNAPSHOT binaries you will need to follow COMPILING to build these.

Build the example

The source code is here. To build the example, run in this directory:

$ ../gradlew installDist

The build creates scripts opentelemetry-server and opentelemetry-client in the build/install/example-opentelemetry/bin/ directory which can be used to run this example. The example requires the server to be running before starting the client.

Run the example

opentelemetry-server:

The opentelemetry-server accepts optional arguments for server-port and prometheus-port:

USAGE: opentelemetry-server [server-port [prometheus-port]]

opentelemetry-client:

The opentelemetry-client accepts optional arguments for user-name, target and prometheus-port:

USAGE: opentelemetry-client-client [user-name [target [prometheus-port]]]

The opentelemetry-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.