Skip to content

Commit 85dbfe5

Browse files
authored
Improve grpc instrumentation examples (#3575)
1 parent b272252 commit 85dbfe5

File tree

1 file changed

+7
-2
lines changed
  • instrumentation/opentelemetry-instrumentation-grpc/src/opentelemetry/instrumentation/grpc

1 file changed

+7
-2
lines changed

instrumentation/opentelemetry-instrumentation-grpc/src/opentelemetry/instrumentation/grpc/__init__.py

Lines changed: 7 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -149,7 +149,7 @@ def serve():
149149
grpc_client_instrumentor.instrument()
150150
151151
async def run():
152-
with grpc.aio.insecure_channel("localhost:50051") as channel:
152+
async with grpc.aio.insecure_channel("localhost:50051") as channel:
153153
154154
stub = helloworld_pb2_grpc.GreeterStub(channel)
155155
response = await stub.SayHello(helloworld_pb2.HelloRequest(name="YOU"))
@@ -168,7 +168,7 @@ async def run():
168168
169169
from opentelemetry.instrumentation.grpc import aio_client_interceptors
170170
171-
channel = grpc.aio.insecure_channel("localhost:12345", interceptors=aio_client_interceptors())
171+
async with grpc.aio.insecure_channel("localhost:50051", interceptors=aio_client_interceptors()) as channel:
172172
173173
174174
Usage Aio Server
@@ -253,6 +253,11 @@ async def serve():
253253
254254
.. code-block::
255255
256+
import grpc
257+
from concurrent import futures
258+
from opentelemetry.instrumentation.grpc import filters
259+
from opentelemetry.instrumentation.grpc import server_interceptor
260+
256261
my_interceptor = server_interceptor(
257262
filter_ = filters.negate(filters.method_name("TestMethod"))
258263
)

0 commit comments

Comments
 (0)