@@ -161,11 +161,22 @@ def _grpc_client_response_hook(span: Any, response: Any) -> None:
161161 Upstream ``opentelemetry-instrumentation-grpc`` sets the integer status code
162162 ``rpc.grpc.status_code`` (e.g. 0), but does not record the modern string status
163163 ``rpc.response.status_code`` (e.g. "OK") required by Cloud Trace and current
164- OpenTelemetry semantic conventions.
164+ OpenTelemetry semantic conventions (v1.27.0+) .
165165
166166 This hook enriches successful RPC attempt spans with ``rpc.response.status_code = "OK"``.
167167 Errors and non-OK statuses are handled at the Tier 3 method span layer or upstream.
168168
169+ Upstream handles synchronous and asynchronous invocations differently:
170+ - **Synchronous gRPC**: Upstream only invokes the response hook when an RPC call
171+ succeeds. On failure, the hook is bypassed entirely.
172+ - **Asynchronous gRPC**: Upstream invokes the response hook unconditionally for
173+ both successes and failures (passing exception details on error). However, it
174+ always marks ``span.status`` with an error status before calling the hook.
175+
176+ Because of this disparity, this hook checks ``span.status`` to guard against
177+ async failure callbacks while allowing synchronous and successful asynchronous
178+ calls to be marked "OK".
179+
169180 Note:
170181 If upstream ``opentelemetry-instrumentation-grpc`` adds native support for
171182 modern ``rpc.response.status_code`` in future releases, this hook can be retired.
@@ -177,9 +188,7 @@ def _grpc_client_response_hook(span: Any, response: Any) -> None:
177188 if not span .is_recording ():
178189 return
179190
180- # Verify the RPC succeeded before recording the OK response status.
181- # Upstream async instrumentation invokes this hook on both successes
182- # and failures, so check whether an error status was already recorded.
191+ # Guard against upstream async calls that invoke this hook on failures.
183192 status = getattr (span , "status" , None )
184193 status_code = getattr (status , "status_code" , None )
185194 if (
0 commit comments