diff --git a/nameko_tracer/constants.py b/nameko_tracer/constants.py index 155fd3e..c21ce3a 100644 --- a/nameko_tracer/constants.py +++ b/nameko_tracer/constants.py @@ -20,15 +20,14 @@ class Status(Enum): Use this name to configure entrypoint logging in ``LOGGING`` setting of Nameko config. - """ + TRACE_KEY = 'nameko_trace' """ Name of the log record attribute holding the serialisable details Contains gathered entrypoint call and result details in serialisable and compact form. - """ @@ -51,37 +50,38 @@ class Status(Enum): """ A key holding a dictionary of arguments passed to the entrypoint call """ + REQUEST_REDACTED_KEY = 'call_args_redacted' """ A key holding a boolean value saying whether sensitive values of the entrypoint call arguments were redacted. - """ + RESPONSE_KEY = 'response' """ A key holding serialisable return value of the entrypoint. """ + REQUEST_TRUNCATED_KEY = 'call_args_truncated' """ A key holding a boolean value saying whether the call args data were truncated. Set by ``TruncateRequestFilter``. - """ + RESPONSE_TRUNCATED_KEY = 'response_truncated' """ A key holding a boolean value saying whether the result data were truncated. Set by ``TruncateResponseFilter``. - """ + REQUEST_LENGTH_KEY = 'call_args_length' """ A key holding the original call args data length Set by ``TruncateRequestFilter`` to the original length of data in ``REQUEST_KEY``. - """ RESPONSE_LENGTH_KEY = 'response_length' @@ -89,9 +89,9 @@ class Status(Enum): Set by ``TruncateResponseFilter`` to the original length of data in ``RESPONSE_KEY``. - """ + RESPONSE_STATUS_KEY = 'response_status' """ A key holding the result status (a value of one of ``Status`` options) """ @@ -108,48 +108,56 @@ class Status(Enum): Set if the entrypoint resulted into an error """ + EXCEPTION_PATH_KEY = 'exception_path' """ A key holding exception path e.g. ``some.module.SomeError`` Set if the entrypoint resulted into an error """ + EXCEPTION_VALUE_KEY = 'exception_value' """ A key holding string representation of exception raised Set if the entrypoint resulted into an error """ + EXCEPTION_ARGS_KEY = 'exception_args' """ A key holding a list of exception arguments Set if the entrypoint resulted into an error """ + EXCEPTION_TRACEBACK_KEY = 'exception_traceback' """ A key holding exception traceback string Set if the entrypoint resulted into an error """ + EXCEPTION_EXPECTED_KEY = 'exception_expected' """ A key holding a boolean saying whether the exception raised was one of errors expected by the entrypoint - """ + SERVICE_NAME_KEY = 'service' """ A key holding the name of the service """ + ENTRYPOINT_NAME_KEY = 'entrypoint_name' """ A key holding the entrypoint service method name e.g. ``'get_user'`` """ + ENTRYPOINT_TYPE_KEY = 'entrypoint_type' """ A key holding the entrypoint type name e.g. ``'Rpc'``. """ + CALL_ID_KEY = 'call_id' """ A key holding the unique ID of the entrypoint call """ @@ -158,10 +166,12 @@ class Status(Enum): """ A key holding the call ID stack ... """ + CONTEXT_DATA_KEY = 'context_data' """ A key holding the worker context data dictionary """ + DEFAULT_ADAPTERS = { 'nameko.web.handlers.HttpRequestHandler': ( 'nameko_tracer.adapters.HttpRequestHandlerAdapter'), @@ -171,8 +181,15 @@ class Status(Enum): Sets an override for Nameko built-in HttpRequestHandler. Extra overrides coming from config are merged in. - """ + CONFIG_KEY = 'TRACER' +""" Nameko config key holding tracer configuration +""" + + ADAPTERS_CONFIG_KEY = 'ADAPTERS' +""" +A key holding adapters configuration in Nameko config (under ``CONFIG_KEY``) +""" diff --git a/nameko_tracer/filters.py b/nameko_tracer/filters.py index a169c1c..694e19f 100644 --- a/nameko_tracer/filters.py +++ b/nameko_tracer/filters.py @@ -87,6 +87,10 @@ class TruncateResponseFilter(BaseTruncateFilter): lifecycle_stage = constants.Stage.response def truncate(self, data): + + if constants.RESPONSE_KEY not in data: + return data + result = utils.serialise_to_string(data[constants.RESPONSE_KEY]) length = len(result) if length > self.max_len: diff --git a/setup.py b/setup.py index e43fbb4..0c0a1da 100644 --- a/setup.py +++ b/setup.py @@ -3,7 +3,7 @@ setup( name='nameko-tracer', - version='1.0.5', + version='1.0.6', description='Nameko extension logging entrypoint processing metrics', author='student.com', author_email='wearehiring@student.com', diff --git a/tests/test_filters.py b/tests/test_filters.py index 26cbe68..98fba63 100644 --- a/tests/test_filters.py +++ b/tests/test_filters.py @@ -205,6 +205,30 @@ def test_truncate_response_to_string_casting( assert data[constants.RESPONSE_KEY] == expected_response_out +def test_truncate_response_ignores_error_response(handler, logger): + + filter_ = filters.TruncateResponseFilter(entrypoints=['^spam'], max_len=5) + + logger.addFilter(filter_) + + extra = { + constants.TRACE_KEY: { + constants.STAGE_KEY: constants.Stage.response.value, + constants.ENTRYPOINT_NAME_KEY: 'spam', + constants.RESPONSE_STATUS_KEY: constants.Status.error.value, + }, + } + + logger.info('response', extra=extra) + + data = getattr(handler.log_record, constants.TRACE_KEY) + + assert constants.RESPONSE_TRUNCATED_KEY not in data + assert constants.RESPONSE_LENGTH_KEY not in data + assert constants.REQUEST_TRUNCATED_KEY not in data + assert constants.REQUEST_LENGTH_KEY not in data + + def test_truncate_request_ignores_response_data(handler, logger): filter_ = filters.TruncateRequestFilter(entrypoints=['^spam'], max_len=5)