From be463c548a603607ec9c4e2f24dc5004393de14e Mon Sep 17 00:00:00 2001 From: Michael Stella Date: Fri, 11 Dec 2020 13:18:16 -0500 Subject: [PATCH] gRPC client instrumentation docs fixes (#245) --- .../instrumentation/grpc/__init__.py | 17 ++++++++++++++--- 1 file changed, 14 insertions(+), 3 deletions(-) diff --git a/instrumentation/opentelemetry-instrumentation-grpc/src/opentelemetry/instrumentation/grpc/__init__.py b/instrumentation/opentelemetry-instrumentation-grpc/src/opentelemetry/instrumentation/grpc/__init__.py index 776e29e8e208..955ef22ac9e4 100644 --- a/instrumentation/opentelemetry-instrumentation-grpc/src/opentelemetry/instrumentation/grpc/__init__.py +++ b/instrumentation/opentelemetry-instrumentation-grpc/src/opentelemetry/instrumentation/grpc/__init__.py @@ -26,7 +26,7 @@ import grpc from opentelemetry import trace - from opentelemetry.instrumentation.grpc import GrpcInstrumentorClient, client_interceptor + from opentelemetry.instrumentation.grpc import GrpcInstrumentorClient from opentelemetry.sdk.trace import TracerProvider from opentelemetry.sdk.trace.export import ( ConsoleSpanExporter, @@ -51,8 +51,9 @@ metrics.set_meter_provider(MeterProvider()) # Optional - export GRPC specific metrics (latency, bytes in/out, errors) by passing an exporter - instrumentor = GrpcInstrumentorClient(exporter=ConsoleMetricsExporter(), interval=10) - instrumentor.instrument() + instrumentor = GrpcInstrumentorClient().instrument( + exporter = ConsoleMetricsExporter(), + interval = 10) def run(): with grpc.insecure_channel("localhost:50051") as channel: @@ -175,6 +176,16 @@ def _uninstrument(self, **kwargs): class GrpcInstrumentorClient(BaseInstrumentor): + """ + Globally instrument the grpc client + + Usage:: + + grpc_client_instrumentor = GrpcInstrumentorClient() + grpc.client_instrumentor.instrument() + + """ + def _instrument(self, **kwargs): exporter = kwargs.get("exporter", None) interval = kwargs.get("interval", 30)