def callback(future_response): grpc_utils.add_message_event( proto_message=future_response.result(), span=current_span, message_event_type=time_event.Type.RECEIVED, ) self._trace_future_exception(future_response) self.tracer.end_span()
def new_behavior(request_or_iterator, servicer_context): span = self._start_server_span(servicer_context) try: if request_streaming: request_or_iterator = grpc_utils.wrap_iter_with_message_events( # noqa: E501 request_or_response_iter=request_or_iterator, span=span, message_event_type=time_event.Type.RECEIVED) else: grpc_utils.add_message_event( proto_message=request_or_iterator, span=span, message_event_type=time_event.Type.RECEIVED, ) # invoke the original rpc behavior response_or_iterator = behavior(request_or_iterator, servicer_context) if response_streaming: response_or_iterator = grpc_utils.wrap_iter_with_message_events( # noqa: E501 request_or_response_iter=response_or_iterator, span=span, message_event_type=time_event.Type.SENT) response_or_iterator = grpc_utils.wrap_iter_with_end_span( # noqa: E501 response_or_iterator) else: grpc_utils.add_message_event( proto_message=response_or_iterator, span=span, message_event_type=time_event.Type.SENT, ) except Exception: _add_exc_info(span) raise finally: # if the response is unary, end the span here. Otherwise # it will be closed when the response iter completes if not response_streaming: execution_context.get_opencensus_tracer().end_span() return response_or_iterator