def run(self): event_type = self.args.get("<event-type>") body = json.loads(self.args.get("<body>")) trace.set_id(self.args.get("--trace-id")) client = Client.from_config(self.config) client.emit(event_type, body)
def dispatch_request(self, request): trace.set_id() urls = self.url_map.bind_to_environ(request.environ) request.urls = urls try: endpoint, args = urls.match() if callable(endpoint): handler = endpoint(self, request) response = handler.dispatch(args) else: try: handler = getattr(self, endpoint) except AttributeError: raise # FIXME response = handler(request, **args) except HTTPException as e: response = e.get_response(request.environ) except Exception as e: if hasattr(e, 'to_http_response'): response = e.to_http_response(request.environ) else: if not self.container.debug: logger.exception('uncaught exception') exc_info = sys.exc_info() try: self.container.error_hook(exc_info) except: logger.exception('error hook failure') finally: del exc_info if self.container.debug: raise response = Response('', status=500) return response
def run(self): event_type = self.args.get('<event-type>') body = json.loads(self.args.get('<body>')) trace.set_id(self.args.get('--trace-id')) client = Client.from_config(self.config) client.emit(event_type, body)
def loop(self): i = 0 while True: gevent.sleep(self.delay) trace.set_id() try: result = self.echo.upper(text='foo_%s' % i) except lymph.RpcError: continue print("result = %s" % result) i += 1
def loop(self): i = 0 echo = self.proxy('lymph://echo', timeout=2) while True: gevent.sleep(.1) trace.set_id() try: result = echo.upper(text='foo_%s' % i) except lymph.RpcError: continue print("result = %s" % result) i += 1
def recv_message(self, msg): trace.set_id(msg.headers.get('trace_id')) logger.debug('<- %s', msg) connection = self.connect(msg.source) connection.on_recv(msg) if msg.is_request(): self.spawn(self.dispatch_request, msg) elif msg.is_reply(): try: channel = self.channels[msg.subject] except KeyError: logger.debug('reply to unknown subject: %s (msg-id=%s)', msg.subject, msg.id) return channel.recv(msg) else: logger.warning('unknown message type: %s (msg-id=%s)', msg.type, msg.id)
def dispatch_request(self, request): trace.set_id() logger.info('%s %s', request.method, request.path) urls = self.url_map.bind_to_environ(request.environ) request.urls = urls try: rule, kwargs = request.urls.match(method=request.method, return_rule=True) except NotFound: response = self.NotFound().get_response(request.environ) except MethodNotAllowed: response = self.MethodNotAllowed().get_response(request.environ) except HTTPException as ex: response = ex.get_response(request.environ) else: response = self.handle(request, rule, kwargs) response.headers['X-Trace-Id'] = trace.get_id() return response
def recv_message(self, msg): trace.set_id(msg.headers.get('trace_id')) logger.debug('<- %s %r', msg, msg.headers) connection = self.connect(msg.source) connection.on_recv(msg) if msg.is_request(): self.spawn(self.dispatch_request, msg) elif msg.is_reply(): try: channel = self.channels[msg.subject] except KeyError: logger.debug('reply to unknown subject: %s (msg-id=%s)', msg.subject, msg.id) return channel.recv(msg) else: logger.warning('unknown message type: %s (msg-id=%s)', msg.type, msg.id)
def dispatch_request(self, request): trace.set_id() urls = self.url_map.bind_to_environ(request.environ) request.urls = urls try: endpoint, args = urls.match() if callable(endpoint): handler = endpoint(self, request) response = handler.dispatch(args) else: try: handler = getattr(self, endpoint) except AttributeError: raise # FIXME response = handler(request, **args) except HTTPException as e: response = e.get_response(request.environ) return response
def dispatch_request(self, request): if self.request_trace_id_header: trace_id = request.headers.get(self.request_trace_id_header) else: trace_id = None trace.set_id(trace_id) logger.info("%s %s", request.method, request.path) urls = self.url_map.bind_to_environ(request.environ) request.urls = urls try: rule, kwargs = request.urls.match(method=request.method, return_rule=True) except NotFound: response = self.NotFound().get_response(request.environ) except MethodNotAllowed: response = self.MethodNotAllowed().get_response(request.environ) except HTTPException as ex: response = ex.get_response(request.environ) else: response = self.handle(request, rule, kwargs) response.headers[self.response_trace_id_header] = trace.get_id() return response
def dispatch_request(self, request): trace.set_id() logger.info('%s %s', request.method, request.path) urls = self.url_map.bind_to_environ(request.environ) request.urls = urls try: rule, kwargs = request.urls.match(return_rule=True) self.container.http_request_hook(request, rule, kwargs) handler = self.get_handler(request, rule) if hasattr(handler, "dispatch"): response = handler.dispatch(kwargs) else: response = handler(request, **kwargs) except HTTPException as e: response = e.get_response(request.environ) except Exception as e: if hasattr(e, 'to_http_response'): response = e.to_http_response(request.environ) else: if not self.container.debug: logger.exception('uncaught exception') exc_info = sys.exc_info() extra_info = { 'url': request.url, 'trace_id': trace.get_id(), 'interface': self.__class__.__name__, } try: self.container.error_hook(exc_info, extra=extra_info) except: logger.exception('error hook failure') finally: del exc_info if self.container.debug: raise response = Response('', status=500) response.headers['X-Trace-Id'] = trace.get_id() return response
def __call__(self, event, *args, **kwargs): trace.set_id(event.headers.get('trace_id')) logger.debug('<E %s', event) return self.func(self.interface, event, *args, **kwargs)
def request(): trace.set_id(self.args.get('--trace-id')) return client.request(address, subject, body, timeout=timeout)
def get_trace_id_from_request(): if self.request_trace_id_header is not None: trace.set_id(flask_current_request.get(self.request_trace_id_header))