Beispiel #1
0
    async def call(self, module, method, wrapped, instance, args, kwargs):
        if not hasattr(instance.application, "zuqa_client"):
            # If tornado was instrumented but not as the main framework
            # (i.e. in Flower), we should skip it.
            return await wrapped(*args, **kwargs)

        # Late import to avoid ImportErrors
        from zuqa.contrib.tornado.utils import get_data_from_request, get_data_from_response

        request = instance.request
        trace_parent = TraceParent.from_headers(request.headers)
        client = instance.application.zuqa_client
        client.begin_transaction("request", trace_parent=trace_parent)
        zuqa.set_context(
            lambda: get_data_from_request(instance, request, client.config,
                                          constants.TRANSACTION), "request")
        # TODO: Can we somehow incorporate the routing rule itself here?
        zuqa.set_transaction_name("{} {}".format(request.method,
                                                 type(instance).__name__),
                                  override=False)

        ret = await wrapped(*args, **kwargs)

        zuqa.set_context(
            lambda: get_data_from_response(instance, client.config, constants.
                                           TRANSACTION), "response")
        result = "HTTP {}xx".format(instance.get_status() // 100)
        zuqa.set_transaction_result(result, override=False)
        client.end_transaction()

        return ret
Beispiel #2
0
def _request_started_handler(client, sender, *args, **kwargs):
    if not _should_start_transaction(client):
        return
    # try to find trace id
    if "environ" in kwargs:
        trace_parent = TraceParent.from_headers(
            kwargs["environ"],
            TRACEPARENT_HEADER_NAME_WSGI,
            TRACEPARENT_LEGACY_HEADER_NAME_WSGI,
            TRACESTATE_HEADER_NAME_WSGI,
        )
    elif "scope" in kwargs and "headers" in kwargs["scope"]:
        trace_parent = TraceParent.from_headers(kwargs["scope"]["headers"])
    else:
        trace_parent = None
    client.begin_transaction("request", trace_parent=trace_parent)
 def request_started(self, app):
     if not self.app.debug or self.client.config.debug:
         trace_parent = TraceParent.from_headers(request.headers)
         self.client.begin_transaction("request", trace_parent=trace_parent)
         zuqa.set_context(
             lambda: get_data_from_request(request, self.client.config,
                                           constants.TRANSACTION),
             "request")
         rule = request.url_rule.rule if request.url_rule is not None else ""
         rule = build_name_with_http_method_prefix(rule, request)
         zuqa.set_transaction_name(rule, override=False)
Beispiel #4
0
    async def _request_started(self, request: Request):
        """Captures the begin of the request processing to APM.

        Args:
            request (Request)
        """
        trace_parent = TraceParent.from_headers(dict(request.headers))
        self.client.begin_transaction("request", trace_parent=trace_parent)

        await set_context(
            lambda: get_data_from_request(request, self.client.config,
                                          constants.TRANSACTION), "request")
        zuqa.set_transaction_name("{} {}".format(request.method,
                                                 request.url.path),
                                  override=False)