You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
# Copyright 2015 gRPC authors.## Licensed under the Apache License, Version 2.0 (the "License");# you may not use this file except in compliance with the License.# You may obtain a copy of the License at## http://www.apache.org/licenses/LICENSE-2.0## Unless required by applicable law or agreed to in writing, software# distributed under the License is distributed on an "AS IS" BASIS,# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.# See the License for the specific language governing permissions and# limitations under the License."""The Python implementation of the GRPC helloworld.Greeter client."""from __future__ importprint_functionimportloggingimportgrpcfromopentelemetryimporttracefromopentelemetry.instrumentation.grpcimportGrpcInstrumentorClientfromopentelemetry.sdk.traceimportTracerProviderfromopentelemetry.sdk.trace.exportimport (
ConsoleSpanExporter,
SimpleExportSpanProcessor,
)
importhelloworld_pb2importhelloworld_pb2_grpctrace.set_tracer_provider(TracerProvider())
trace.get_tracer_provider().add_span_processor(
SimpleExportSpanProcessor(ConsoleSpanExporter())
)
GrpcInstrumentorClient().instrument()
defrun():
# NOTE(gRPC Python Team): .close() is possible on a channel and should be# used in circumstances in which the with statement does not fit the needs# of the code.withgrpc.insecure_channel('localhost:50051') aschannel:
stub=helloworld_pb2_grpc.GreeterStub(channel)
response=stub.SayHello(helloworld_pb2.HelloRequest(name='you'))
print("Greeter client received: "+response.message)
if__name__=='__main__':
logging.basicConfig()
run()
What is the expected behavior?
The channel should be usable as normal, except now with instrumentation
What is the actual behavior?
❯ python greeter_client.py
Traceback (most recent call last):
File "greeter_client.py", line 52, in <module>
run()
File "greeter_client.py", line 44, in run
with grpc.insecure_channel('localhost:50051') as channel:
File "/home/isobel/workspace/tmp/otlp/grpc/lib/python3.8/site-packages/opentelemetry/instrumentation/grpc/grpcext/_interceptor.py", line 235, in __enter__
raise NotImplementedError()
NotImplementedError
Additional context
LMK and I can make a PR
The text was updated successfully, but these errors were encountered:
I did a lot of testing with this (see recent PRs) but apparently never once tried a channel as a context manager - all of my production code saves the channel in a client class instead. Good catch!
ocelotl
added a commit
to ocelotl/opentelemetry-python-contrib
that referenced
this issue
Mar 3, 2021
Describe your environment
Verified on python 3.8.6 with opentelemetry 0.17b0
Steps to reproduce
Use a gRPC channel as a context manager.
For instance, this happens if you add instrumentation to the gRPC helloworld example client:
What is the expected behavior?
The channel should be usable as normal, except now with instrumentation
What is the actual behavior?
Additional context
LMK and I can make a PR
The text was updated successfully, but these errors were encountered: