def request(self, host, handler, request_body, verbose=0): try: https = isinstance(self, xmlrpclib.SafeTransport) protocol = "https://" if https else "http://" target = "%s%s%s" % (protocol, host, handler) match = _parse_method_name.search(request_body) method = match.group(1) if match else None parent_trace = local().current self._trace = parent_trace.child("xmlrpclib") self._trace.record(Annotation.string("uri", target)) if method: self._trace.record(Annotation.string("method", method)) self._trace.record(Annotation.server_recv()) except Exception as exc: log.error(repr(exc)) try: return self.__origin.request(self, host, handler, request_body, verbose) finally: try: self._trace.record(Annotation.server_send()) except: pass
def task_postrun_handler(task_id, task, **kwargs): trace = local().current trace.record(Annotation.server_send()) trace.record(Annotation.client_recv()) log(trace) local().pop()
def pre_response(app, response, **extra): request.trace.record( Annotation.string('http.responsecode', '{0}'.format(response.status_code))) request.trace.record(Annotation.server_send()) log(request.trace) local().pop()
def track_end_request(self, request, response): if self.trace: self.trace.record(Annotation.server_send()) log.info("reporting trace %s", self.trace.name) response.headers["Trace-Id"] = str(self.trace.trace_id) zipkin_log(self.trace)
def wrapped(cursor, statement, vars=None): trace = None parent_trace = get_current_trace() if parent_trace: trace = parent_trace.child(trace_name) trace.record(Annotation.string("db.statement", statement)) if vars: if isinstance(vars, dict): params = dict([(key, getattr(param, "logged_value", param)) for key, param in vars.items()]) else: params = [ getattr(param, "logged_value", param) for param in vars ] trace.record( Annotation.string("db.parameters", repr(params))) trace.record(Annotation.string("span.kind", "client")) trace.record(Annotation.server_send()) try: fn(cursor, statement, vars) finally: if trace: status = "OK" if sys.exc_info()[0] is None else "KO" trace.record(Annotation.string("status", status)) trace.record(Annotation.server_recv())
def log_response(trace, response): trace.record( Annotation.string("http.responsecode", "{0}".format(response.status_code))) trace.record(Annotation.server_send()) try: zipkin_log(trace) except Exception as err: log.error("Error while sending trace: %s", trace)
def dbapi_error(conn, cursor, statement, parameters, context, exception): if not hasattr(context, 'trace') and not hasattr(cursor, 'trace'): return abstract = context if hasattr(context, 'trace') else cursor try: abstract.trace.record(Annotation.string('status', 'KO')) abstract.trace.record(Annotation.server_send()) except Exception: log.exception('Unexpected exception while tracing SQL')
def dbapi_error(conn, cursor, statement, parameters, context, exception): if not hasattr(context, "trace") and not hasattr(cursor, "trace"): return abstract = context if hasattr(context, "trace") else cursor try: abstract.trace.record(Annotation.string("status", "KO")) abstract.trace.record(Annotation.server_send()) except Exception: log.exception("Unexpected exception while tracing SQL")
def pre_response(resp, req=None): if not req: req = resp.request if not hasattr(req, 'trace'): return resp req.trace.record( Annotation.string('http.status_code', '{0}'.format(getattr(resp, 'status', None)))) req.trace.record(Annotation.server_send()) return resp
def pre_response(resp, req=None): if not req: req = resp.request if not hasattr(req, "trace"): return resp req.trace.record( Annotation.string("http.status_code", "{0}".format(getattr(resp, "status", None)))) req.trace.record(Annotation.server_send()) return resp
def wrap(request): trace = request.trace trace.record(Annotation.server_send()) log(trace) local().pop()