Ejemplo n.º 1
0
async def get_data_from_response(response: Response,
                                 capture_body=False,
                                 capture_headers=True) -> dict:
    """Loads data from response for APM capturing.

    Args:
        response (Response)
        capture_body (bool): Loads also response body if True
        capture_headers (bool): Loads also response HTTP headers if True

    Returns:
        dict
    """
    result = {}

    if isinstance(getattr(response, "status_code", None),
                  compat.integer_types):
        result["status_code"] = response.status_code

    if capture_headers and getattr(response, "headers", None):
        headers = response.headers
        result["headers"] = {
            key: ";".join(headers.getlist(key))
            for key in compat.iterkeys(headers)
        }

    if capture_body:
        result["body"] = response.body.decode("utf-8")

    return result
Ejemplo n.º 2
0
async def get_data_from_response(response: Response, config: Config,
                                 event_type: str) -> dict:
    """Loads data from response for APM capturing.

    Args:
        response (Response)
        config (Config)
        event_type (str)

    Returns:
        dict
    """
    result = {}

    if isinstance(getattr(response, "status_code", None),
                  compat.integer_types):
        result["status_code"] = response.status_code

    if config.capture_headers and getattr(response, "headers", None):
        headers = response.headers
        result["headers"] = {
            key: ";".join(headers.getlist(key))
            for key in compat.iterkeys(headers)
        }

    if config.capture_body in ("all", event_type) and hasattr(
            response, "body"):
        result["body"] = response.body.decode("utf-8")

    return result
Ejemplo n.º 3
0
class Context(object):
    def __init__(self, dict):
        self.dict = dict

    __getitem__ = lambda s, *a: s.dict.__getitem__(*a)
    __setitem__ = lambda s, *a: s.dict.__setitem__(*a)
    iterkeys = lambda s, *a: compat.iterkeys(s.dict, *a)
Ejemplo n.º 4
0
def get_data_from_response(response):
    data = {"status_code": response.status_int}
    if response.headers:
        data["headers"] = {
            key: ";".join(response.headers.getall(key))
            for key in compat.iterkeys(response.headers)
        }
    return data
Ejemplo n.º 5
0
 def get_data_from_response(self, response):
     data = {'status_code': response.status_int}
     if response.headers:
         data['headers'] = {
             key: ';'.join(response.headers.getall(key))
             for key in compat.iterkeys(response.headers)
         }
     return data
Ejemplo n.º 6
0
def get_data_from_response(response):
    """Extract APM data from response properties"""
    data = {"status_code": response.status_int}
    if response.headers:
        data["headers"] = {
            key: ";".join(response.headers.getall(key))
            for key in compat.iterkeys(response.headers)
        }
    return data
Ejemplo n.º 7
0
def get_data_from_response(response, config, event_type):
    result = {}

    if isinstance(getattr(response, "status_code", None), compat.integer_types):
        result["status_code"] = response.status_code

    if config.capture_headers and getattr(response, "headers", None):
        headers = response.headers
        result["headers"] = {key: ";".join(headers.getlist(key)) for key in compat.iterkeys(headers)}
    return result
Ejemplo n.º 8
0
def get_data_from_response(response):
    result = {}

    if isinstance(getattr(response, 'status_code', None), compat.integer_types):
        result['status_code'] = response.status_code

    if getattr(response, 'headers', None):
        headers = response.headers
        result['headers'] = {key: ';'.join(headers.getlist(key)) for key in compat.iterkeys(headers)}
    return result
Ejemplo n.º 9
0
def get_data_from_response(request_handler, config, event_type):
    result = {}

    result["status_code"] = request_handler.get_status()

    if config.capture_headers and request_handler._headers:
        headers = request_handler._headers
        result["headers"] = {key: ";".join(headers.get_list(key)) for key in compat.iterkeys(headers)}
        pass
    return result
Ejemplo n.º 10
0
def get_data_from_response(response: Union[HTTPException, Response],
                           config: Config, event_type: str):
    result = {}
    status = getattr(response, "status", getattr(response, "status_code",
                                                 None))
    if isinstance(status, compat.integer_types):
        result["status_code"] = status
    if config.capture_headers and getattr(response, "headers", None):
        headers = response.headers
        result["headers"] = {
            key: ";".join(headers.getall(key))
            for key in compat.iterkeys(headers)
        }
    return result
Ejemplo n.º 11
0
    def reset(self):
        """
        Reset state to the original configuration

        Note that because ConfigurationValues can have callbacks, we need to
        note any differences between the original configuration and the most
        recent configuration and run any callbacks that might exist for those
        values.
        """
        callbacks = []
        for key in compat.iterkeys(self._config.values):
            if key in self._first_config.values and self._config.values[key] != self._first_config.values[key]:
                callbacks.append((key, self._config.values[key], self._first_config.values[key]))

        with self._lock:
            self._version = self._first_version
            self._config = self._first_config

        self._config.callbacks_queue.extend(callbacks)
        self._config.call_pending_callbacks()
Ejemplo n.º 12
0
async def get_data_from_response(message: dict, config: Config, event_type: str) -> dict:
    """Loads data from response for APM capturing.

    Args:
        message (dict)
        config (Config)
        event_type (str)

    Returns:
        dict
    """
    result = {}

    if "status_code" in message:
        result["status_code"] = message["status"]

    if config.capture_headers and "headers" in message:
        headers = Headers(raw=message["headers"])
        result["headers"] = {key: ";".join(headers.getlist(key)) for key in compat.iterkeys(headers)}

    return result