Esempio n. 1
0
 def intercept_stream(self, request_or_iterator, metadata, client_info,
                      invoker):
     if client_info.is_server_stream:
         return self._intercept_server_stream(request_or_iterator, metadata,
                                              client_info, invoker)
     with self._start_guarded_span(client_info.full_method) as guarded_span:
         metadata = _inject_span_context(self._tracer, guarded_span.span,
                                         metadata)
         rpc_info = RpcInfo(full_method=client_info.full_method,
                            metadata=metadata,
                            timeout=client_info.timeout,
                            request=request_or_iterator)
         if self._log_payloads:
             request_or_iterator = log_or_wrap_request_or_iterator(
                 guarded_span.span, client_info.is_client_stream,
                 request_or_iterator)
         try:
             result = invoker(request_or_iterator, metadata)
         except:
             e = sys.exc_info()[0]
             guarded_span.span.set_tag('error', True)
             guarded_span.span.log_kv({'event': 'error', 'error.object': e})
             rpc_info.error = e
             if self._span_decorator is not None:
                 self._span_decorator(guarded_span.span, rpc_info)
             raise
         return self._trace_result(guarded_span, rpc_info, result)
Esempio n. 2
0
 def intercept_stream(self, request_or_iterator, servicer_context,
                      server_info, handler):
     if server_info.is_server_stream:
         return self._intercept_server_stream(request_or_iterator,
                                              servicer_context, server_info,
                                              handler)
     with self._start_span(servicer_context,
                           server_info.full_method) as span:
         rpc_info = RpcInfo(full_method=server_info.full_method,
                            metadata=servicer_context.invocation_metadata(),
                            timeout=servicer_context.time_remaining())
         if self._log_payloads:
             request_or_iterator = log_or_wrap_request_or_iterator(
                 span, server_info.is_client_stream, request_or_iterator)
         servicer_context = _OpenTracingServicerContext(
             servicer_context, span)
         try:
             response = handler(request_or_iterator, servicer_context)
         except:
             e = sys.exc_info()[0]
             span.set_tag('error', True)
             span.log_kv({'event': 'error', 'error.object': e})
             rpc_info.error = e
             if self._span_decorator is not None:
                 self._span_decorator(span, rpc_info)
             raise
         if self._log_payloads:
             span.log_kv({'response': response})
         _check_error_code(span, servicer_context, rpc_info)
         rpc_info.response = response
         if self._span_decorator is not None:
             self._span_decorator(span, rpc_info)
         return response
Esempio n. 3
0
 def _intercept_server_stream(self, request_or_iterator, metadata,
                              client_info, invoker):
     with self._start_span(client_info.full_method) as span:
         metadata = _inject_span_context(self._tracer, span, metadata)
         rpc_info = RpcInfo(full_method=client_info.full_method,
                            metadata=metadata,
                            timeout=client_info.timeout)
         if client_info.is_client_stream:
             rpc_info.request = request_or_iterator
         if self._log_payloads:
             request_or_iterator = log_or_wrap_request_or_iterator(
                 span, client_info.is_client_stream, request_or_iterator)
         try:
             result = invoker(request_or_iterator, metadata)
             for response in result:
                 if self._log_payloads:
                     span.log_kv({'response': response})
                 yield response
         except:
             e = sys.exc_info()[0]
             span.set_tag('error', True)
             span.log_kv({'event': 'error', 'error.object': e})
             rpc_info.error = e
             if self._span_decorator is not None:
                 self._span_decorator(span, rpc_info)
             raise
         if self._span_decorator is not None:
             self._span_decorator(span, rpc_info)
Esempio n. 4
0
 def intercept_stream(self, request_or_iterator, metadata, client_info,
                      invoker):
     if client_info.is_server_stream:
         return self._intercept_server_stream(request_or_iterator, metadata,
                                              client_info, invoker)
     with self._start_guarded_span(client_info.full_method) as guarded_span:
         metadata = _inject_span_context(self._tracer, guarded_span.span,
                                         metadata)
         rpc_info = RpcInfo(
             full_method=client_info.full_method,
             metadata=metadata,
             timeout=client_info.timeout,
             request=request_or_iterator)
         if self._log_payloads:
             request_or_iterator = log_or_wrap_request_or_iterator(
                 guarded_span.span, client_info.is_client_stream,
                 request_or_iterator)
         try:
             result = invoker(request_or_iterator, metadata)
         except:
             e = sys.exc_info()[0]
             guarded_span.span.set_tag('error', True)
             guarded_span.span.log_kv({'event': 'error', 'error.object': e})
             rpc_info.error = e
             if self._span_decorator is not None:
                 self._span_decorator(guarded_span.span, rpc_info)
             raise
         return self._trace_result(guarded_span, rpc_info, result)
Esempio n. 5
0
 def _intercept_server_stream(self, request_or_iterator, metadata,
                              client_info, invoker):
     with self._start_span(client_info.full_method) as span:
         metadata = _inject_span_context(self._tracer, span, metadata)
         rpc_info = RpcInfo(
             full_method=client_info.full_method,
             metadata=metadata,
             timeout=client_info.timeout)
         if client_info.is_client_stream:
             rpc_info.request = request_or_iterator
         if self._log_payloads:
             request_or_iterator = log_or_wrap_request_or_iterator(
                 span, client_info.is_client_stream, request_or_iterator)
         try:
             result = invoker(request_or_iterator, metadata)
             for response in result:
                 if self._log_payloads:
                     span.log_kv({'response': response})
                 yield response
         except:
             e = sys.exc_info()[0]
             span.set_tag('error', True)
             span.log_kv({'event': 'error', 'error.object': e})
             rpc_info.error = e
             if self._span_decorator is not None:
                 self._span_decorator(span, rpc_info)
             raise
         if self._span_decorator is not None:
             self._span_decorator(span, rpc_info)
Esempio n. 6
0
 def intercept_stream(self, request_or_iterator, servicer_context,
                      server_info, handler):
     if server_info.is_server_stream:
         return self._intercept_server_stream(
             request_or_iterator, servicer_context, server_info, handler)
     with self._start_span(servicer_context,
                           server_info.full_method) as span:
         rpc_info = RpcInfo(
             full_method=server_info.full_method,
             metadata=servicer_context.invocation_metadata(),
             timeout=servicer_context.time_remaining())
         if self._log_payloads:
             request_or_iterator = log_or_wrap_request_or_iterator(
                 span, server_info.is_client_stream, request_or_iterator)
         servicer_context = _OpenTracingServicerContext(
             servicer_context, span)
         try:
             response = handler(request_or_iterator, servicer_context)
         except:
             e = sys.exc_info()[0]
             span.set_tag('error', True)
             span.log_kv({'event': 'error', 'error.object': e})
             rpc_info.error = e
             if self._span_decorator is not None:
                 self._span_decorator(span, rpc_info)
             raise
         if self._log_payloads:
             span.log_kv({'response': response})
         _check_error_code(span, servicer_context, rpc_info)
         rpc_info.response = response
         if self._span_decorator is not None:
             self._span_decorator(span, rpc_info)
         return response
 def intercept_unary(self, request, metadata, client_info, invoker):
     with self._start_guarded_span(client_info.full_method) as guarded_span:
         #将span的信息注入到metadata
         metadata = _inject_span_context(self._tracer, guarded_span.span,
                                         metadata)
         print(f"metadata:{metadata}")
         rpc_info = RpcInfo(full_method=client_info.full_method,
                            metadata=metadata,
                            timeout=client_info.timeout,
                            request=request)
         if self._log_payloads:
             guarded_span.span.log_kv({'request': request})
         try:
             # result = 1
             result = invoker(request, metadata)
         except:
             e = sys.exc_info()[0]
             guarded_span.span.set_tag('error', True)
             guarded_span.span.log_kv({'event': 'error', 'error.object': e})
             rpc_info.error = e
             if self._span_decorator is not None:
                 self._span_decorator(guarded_span.span, rpc_info)
             raise
         return self._trace_result(guarded_span, rpc_info, result)