Skip to content

Commit 5f4864c

Browse files
committed
Bugfix of (open-telemetry#855 )
1 parent 092d8c8 commit 5f4864c

File tree

1 file changed

+24
-9
lines changed
  • instrumentation/opentelemetry-instrumentation-grpc/src/opentelemetry/instrumentation/grpc

1 file changed

+24
-9
lines changed

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

Lines changed: 24 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -69,8 +69,8 @@ class _OpenTelemetryServicerContext(grpc.ServicerContext):
6969
def __init__(self, servicer_context, active_span):
7070
self._servicer_context = servicer_context
7171
self._active_span = active_span
72-
self.code = grpc.StatusCode.OK
73-
self.details = None
72+
self._code = grpc.StatusCode.OK
73+
self._details = None
7474
super().__init__()
7575

7676
def __getattr__(self, attr):
@@ -119,8 +119,8 @@ def trailing_metadata(self):
119119
return self._servicer_context.trailing_metadata()
120120

121121
def abort(self, code, details):
122-
self.code = code
123-
self.details = details
122+
self._code = code
123+
self._details = details
124124
self._active_span.set_attribute(
125125
SpanAttributes.RPC_GRPC_STATUS_CODE, code.value[0]
126126
)
@@ -135,10 +135,25 @@ def abort(self, code, details):
135135
def abort_with_status(self, status):
136136
return self._servicer_context.abort_with_status(status)
137137

138+
def code(self):
139+
if not hasattr(self._servicer_context, "code"):
140+
raise RuntimeError(
141+
"code() is not supported with the installed version of grpcio"
142+
)
143+
return self._servicer_context.code()
144+
145+
def details(self):
146+
if not hasattr(self._servicer_context, "details"):
147+
raise RuntimeError(
148+
"details() is not supported with the installed version of "
149+
"grpcio"
150+
)
151+
return self._servicer_context.details()
152+
138153
def set_code(self, code):
139-
self.code = code
154+
self._code = code
140155
# use details if we already have it, otherwise the status description
141-
details = self.details or code.value[1]
156+
details = self._details or code.value[1]
142157
self._active_span.set_attribute(
143158
SpanAttributes.RPC_GRPC_STATUS_CODE, code.value[0]
144159
)
@@ -152,12 +167,12 @@ def set_code(self, code):
152167
return self._servicer_context.set_code(code)
153168

154169
def set_details(self, details):
155-
self.details = details
156-
if self.code != grpc.StatusCode.OK:
170+
self._details = details
171+
if self._code != grpc.StatusCode.OK:
157172
self._active_span.set_status(
158173
Status(
159174
status_code=StatusCode.ERROR,
160-
description=f"{self.code}:{details}",
175+
description=f"{self._code}:{details}",
161176
)
162177
)
163178
return self._servicer_context.set_details(details)

0 commit comments

Comments
 (0)