Skip to content

Commit

Permalink
[getappmap#256] Flag to disable static request recording "APPMAP_ENAB…
Browse files Browse the repository at this point in the history
…LED_STATIC_REQUEST_RECORDINGS"
  • Loading branch information
virajkanwade committed Feb 29, 2024
1 parent dff8b0f commit a2dcea3
Show file tree
Hide file tree
Showing 2 changed files with 15 additions and 2 deletions.
5 changes: 5 additions & 0 deletions _appmap/env.py
Original file line number Diff line number Diff line change
Expand Up @@ -46,6 +46,7 @@ def __init__(self, env=None, cwd=None):

self._configure_logging()
self._enabled = self._env.get("APPMAP", "").lower() != "false"
self._enabled_static_request_recordings = self._env.get("APPMAP_ENABLED_STATIC_REQUEST_RECORDINGS", "").lower() != "false"

self._root_dir = str(self._cwd) + "/"
self._root_dir_len = len(self._root_dir)
Expand Down Expand Up @@ -89,6 +90,10 @@ def enabled(self):
def enabled(self, value):
self._enabled = value

@property
def enabled_static_request_recordings(self):
return self._enabled_static_request_recordings

def enables(self, recording_method, default="true"):
if not self.enabled:
return False
Expand Down
12 changes: 10 additions & 2 deletions _appmap/web_framework.py
Original file line number Diff line number Diff line change
Expand Up @@ -157,6 +157,12 @@ def __init__(self, framework_name):
logger.info("Requests will be recorded (%s)", framework_name)

self.should_record = env.enables("remote") or record_requests
self.should_record_static = env.enabled_static_request_recordings

def _is_static_request(self, request_path):
import mimetypes
mime_type = mimetypes.guess_type(request_path)[0] or ""
return mime_type in ("text/css", "text/javascript") or mime_type.startswith(("image/"))

def before_request_hook(self, request) -> Tuple[Optional[Recorder], float, int]:
rec = None
Expand All @@ -171,7 +177,8 @@ def before_request_hook(self, request) -> Tuple[Optional[Recorder], float, int]:
elif env.enables("remote"):
rec = Recorder.get_global()

if rec and rec.get_enabled():
skip_static_request = self._is_static_request(request.path) and not self.should_record_static
if rec and rec.get_enabled() and not skip_static_request:
start, call_event_id = self.before_request_main(rec, request)

return rec, start, call_event_id
Expand All @@ -186,7 +193,8 @@ def after_request_hook(
start,
call_event_id,
) -> None:
if request_path == self.record_url:
skip_static_request = self._is_static_request(request_path) and not self.should_record_static
if request_path == self.record_url or skip_static_request:
return

env = Env.current
Expand Down

0 comments on commit a2dcea3

Please sign in to comment.