@@ -69,8 +69,8 @@ class _OpenTelemetryServicerContext(grpc.ServicerContext):
69
69
def __init__ (self , servicer_context , active_span ):
70
70
self ._servicer_context = servicer_context
71
71
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
74
74
super ().__init__ ()
75
75
76
76
def __getattr__ (self , attr ):
@@ -119,8 +119,8 @@ def trailing_metadata(self):
119
119
return self ._servicer_context .trailing_metadata ()
120
120
121
121
def abort (self , code , details ):
122
- self .code = code
123
- self .details = details
122
+ self ._code = code
123
+ self ._details = details
124
124
self ._active_span .set_attribute (
125
125
SpanAttributes .RPC_GRPC_STATUS_CODE , code .value [0 ]
126
126
)
@@ -135,10 +135,25 @@ def abort(self, code, details):
135
135
def abort_with_status (self , status ):
136
136
return self ._servicer_context .abort_with_status (status )
137
137
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
+
138
153
def set_code (self , code ):
139
- self .code = code
154
+ self ._code = code
140
155
# 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 ]
142
157
self ._active_span .set_attribute (
143
158
SpanAttributes .RPC_GRPC_STATUS_CODE , code .value [0 ]
144
159
)
@@ -152,12 +167,12 @@ def set_code(self, code):
152
167
return self ._servicer_context .set_code (code )
153
168
154
169
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 :
157
172
self ._active_span .set_status (
158
173
Status (
159
174
status_code = StatusCode .ERROR ,
160
- description = f"{ self .code } :{ details } " ,
175
+ description = f"{ self ._code } :{ details } " ,
161
176
)
162
177
)
163
178
return self ._servicer_context .set_details (details )
0 commit comments