Skip to content

Commit

Permalink
feat: support for data and content type storage
Browse files Browse the repository at this point in the history
  • Loading branch information
joamag committed Jan 14, 2021
1 parent 87efcfa commit 67b3ad0
Show file tree
Hide file tree
Showing 2 changed files with 24 additions and 1 deletion.
9 changes: 9 additions & 0 deletions src/appier_extras/parts/diag/models/request.py
Expand Up @@ -80,6 +80,15 @@ class DiagRequest(base.DiagBase):
immutable = True
)

content_type = appier.field(
index = "all",
immutable = True
)

data = appier.field(
immutable = True
)

duration = appier.field(
type = float,
index = "all",
Expand Down
16 changes: 15 additions & 1 deletion src/appier_extras/parts/diag/part.py
Expand Up @@ -67,6 +67,7 @@ def __init__(self, *args, **kwargs):
self.minimal = kwargs.get("minimal", False)
self.format = kwargs.get("format", "combined")
self.empty = kwargs.get("empty", False)
self.max_data_size = kwargs.get("max_data_size", 131072)
self.store = appier.conf("DIAG_STORE", self.store, cast = bool)
self.loggly = appier.conf("DIAG_LOGGLY", self.loggly, cast = bool)
self.logstash = appier.conf("DIAG_LOGSTASH", self.loggly, cast = bool)
Expand All @@ -78,6 +79,11 @@ def __init__(self, *args, **kwargs):
self.minimal = appier.conf("DIAG_MINIMAL", self.minimal, cast = bool)
self.format = appier.conf("DIAG_FORMAT", self.format)
self.empty = appier.conf("DIAG_EMPTY", self.empty, cast = bool)
self.max_data_size = appier.conf(
"DIAG_MAX_DATA_SIZE",
self.max_data_size,
cast = int
)
self._loggly_api = None
self._logstash_api = None
self._hostname_s = None
Expand Down Expand Up @@ -222,6 +228,8 @@ def _output_log(self):
def _store_log(self):
browser_info = self.request.browser_info
browser_info = browser_info or dict()
data = self.request.data if self.request.data and\
len(self.request.data) < self.max_data_size else None
diag_request = models.DiagRequest(
address = self.request.get_address(),
url = self.request.get_url(),
Expand All @@ -230,6 +238,8 @@ def _store_log(self):
query = self.request.query,
code = self.request.code,
protocol = self.request.protocol,
content_type = self.request.content_type,
data = data,
duration = self.request.duration,
in_length = self.request.in_length,
out_length = self.request.out_length,
Expand Down Expand Up @@ -295,13 +305,17 @@ def _get_item_minimal(self):
method = self.request.method,
path = self.request.path,
query = self.request.query,
code = self.request.code
code = self.request.code,
content_type = self.request.content_type
)
return item

def _get_item_normal(self):
item = self._get_item_minimal()
data = self.request.data if self.request.data and\
len(self.request.data) < self.max_data_size else None
item.update(
data = data,
protocol = self.request.protocol,
duration = self.request.duration,
in_length = self.request.in_length,
Expand Down

0 comments on commit 67b3ad0

Please sign in to comment.