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
The _OpenTelemetryServicerContext inside of _server.py implements code and details as attributes while the official grpcio API implements them as methods.
Proposed Bugfix
Stick with the attributes to support older grpcio versions, but make them private. Furthermore, add code() and details() with RuntimeError:
class_OpenTelemetryServicerContext(grpc.ServicerContext):
def__init__(self, servicer_context, active_span):
self._servicer_context=servicer_contextself._active_span=active_spanself._code=grpc.StatusCode.OKself._details=Nonesuper().__init__()
# ...defabort(self, code, details):
self._code=codeself._details=detailsself._active_span.set_attribute(
SpanAttributes.RPC_GRPC_STATUS_CODE, code.value[0]
)
self._active_span.set_status(
Status(
status_code=StatusCode.ERROR,
description=f"{code}:{details}",
)
)
returnself._servicer_context.abort(code, details)
defcode(self):
ifnothasattr(self._servicer_context, "code"):
raiseRuntimeError(
"code() is not supported with the installed version of grpcio"
)
returnself._servicer_context.code()
defset_code(self, code):
self._code=code# use details if we already have it, otherwise the status descriptiondetails=self._detailsorcode.value[1]
self._active_span.set_attribute(
SpanAttributes.RPC_GRPC_STATUS_CODE, code.value[0]
)
ifcode!=grpc.StatusCode.OK:
self._active_span.set_status(
Status(
status_code=StatusCode.ERROR,
description=f"{code}:{details}",
)
)
returnself._servicer_context.set_code(code)
defdetails(self):
ifnothasattr(self._servicer_context, "details"):
raiseRuntimeError(
"details() is not supported with the installed version of ""grpcio"
)
returnself._servicer_context.details()
defset_details(self, details):
self._details=detailsifself._code!=grpc.StatusCode.OK:
self._active_span.set_status(
Status(
status_code=StatusCode.ERROR,
description=f"{self._code}:{details}",
)
)
returnself._servicer_context.set_details(details)
The text was updated successfully, but these errors were encountered:
CoLa5
changed the title
opentelemetry-instrumentation-grpc _OpenTelemetryServicerContex
opentelemetry-instrumentation-grpc - code()/details()-bug in ServicerContext
Jan 11, 2022
Describe your environment
python version: 3.7.12
grpcio: 1.43.0
Steps to reproduce
Call inside of a RPC-method-implementation of a grpc service the methods:
context.code()
context.details()
which are supported since grpcio v1.38.0 (s. here).
Example:
Add the functions into e.g. helloworld/greeter_server.py:
What is the expected behavior?
This should print:
What is the actual behavior?
There are
TypeError
raised:Additional context
The
_OpenTelemetryServicerContext
inside of _server.py implementscode
anddetails
as attributes while the official grpcio API implements them as methods.Proposed Bugfix
Stick with the attributes to support older grpcio versions, but make them private. Furthermore, add
code()
anddetails()
withRuntimeError
:The text was updated successfully, but these errors were encountered: