Skip to content

Commit

Permalink
docs, examples: show how to enable gRPC instrumentation
Browse files Browse the repository at this point in the history
  • Loading branch information
odeke-em committed Aug 21, 2024
1 parent d653c04 commit f902573
Show file tree
Hide file tree
Showing 2 changed files with 21 additions and 1 deletion.
18 changes: 17 additions & 1 deletion docs/opentelemetry-tracing.rst
Original file line number Diff line number Diff line change
Expand Up @@ -55,12 +55,28 @@ Alternatively you can pass in a tracer provider into the Cloud Spanner initializ
instance = spanner_client.instance(instance_id)
database = instance.database(database_id)
please not that the tracer being used is retrieved by invoking:
please note that the tracer being used is retrieved by invoking:

.. code:: python
tracer = tracerProvider.get_tracer('cloud.google.com/python/spanner', SPANNER_LIB_VERSION)
To get more fine-grained traces from gRPC, you can enable the gRPC instrumentation by the following

.. code-block:: sh
pip install opentelemetry-instrumentation-grpc
and then in your Python code, please add the following lines:

.. code:: python
from opentelemetry.instrumentation.grpc import GrpcInstrumentorClient
grpc_client_instrumentor = GrpcInstrumentorClient()
grpc_client_instrumentor.instrument()
Generated spanner traces should now be available on `Cloud Trace <https://console.cloud.google.com/traces>`_.

Tracing is most effective when many libraries are instrumented to provide insight over the entire lifespan of a request.
Expand Down
4 changes: 4 additions & 0 deletions examples/trace.py
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,10 @@
from opentelemetry.sdk.trace.sampling import ALWAYS_ON
from opentelemetry import trace

# Enable the gRPC instrumentation if you'd like more introspection.
from opentelemetry.instrumentation.grpc import GrpcInstrumentorClient
grpc_client_instrumentor = GrpcInstrumentorClient()
grpc_client_instrumentor.instrument()

def main():
# Setup common variables that'll be used between Spanner and traces.
Expand Down

0 comments on commit f902573

Please sign in to comment.