Api logs rex - #84
Open
Sidartha-CT wants to merge 7 commits into
Open
Conversation
… request Signed-off-by: Sidartha-CT <neelapu.sidartha@candelatech.com>
Signed-off-by: Sidartha-CT <neelapu.sidartha@candelatech.com>
Signed-off-by: Sidartha-CT <neelapu.sidartha@candelatech.com>
Signed-off-by: Sidartha-CT <neelapu.sidartha@candelatech.com>
…call logging Signed-off-by: Sidartha-CT <neelapu.sidartha@candelatech.com>
Signed-off-by: Sidartha-CT <neelapu.sidartha@candelatech.com>
…default Signed-off-by: Sidartha-CT <neelapu.sidartha@candelatech.com>
Sidartha-CT
force-pushed
the
api_logs_rex
branch
from
July 29, 2026 05:56
1df47bb to
05362fe
Compare
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Add opt-in API call logging for LANforge JSON requests
Summary
Adds a lightweight, opt-in CSV logger for every
json_get/json_post/json_put/json_deletecall made through either of LANforge's two client paths:py-json/LANforge/lfcli_base.py→Realmlanforge_client/lanforge_api.py→LFJsonCommand/LFJsonQueryWhen enabled via:
each call's method, URL, payload, HTTP status, and error/diagnostics get appended to a CSV (default
~/lf_api_calls.csv), which is copied into the run's report folder.Why a new
lanforge_client/api_call_log.pymoduleWe want to record specific fields per call (method, url, payload, status, error) and post-process them later as CSV, so the recording logic needed to live inside
json_get()/json_post()/json_put()/json_delete()themselves rather than being bolted on from outside.There are two independent call paths that implement those four methods:
LFCliBase(py-json, used byRealmand most scripts)BaseLFJsonRequest(lanforge_client/lanforge_api.py, not currently used by interop)Rather than duplicating logging logic in both, the common pieces (CSV schema, enable/disable state, the actual
record()call) live in one new module inlanforge_client/, and each call path just calls into it.lanforge_clientis the natural home since it's already a shared dependency of both.Why global (module-level) state instead of a constructor parameter
The enable flag is deliberately process-wide global state in
api_call_log.py, not a parameter threaded throughRealm/LFCliBase/ profile constructors.Reason:
Realmgets instantiated directly all over thepy-scriptstree, and profile classes build their own nested instances.For example:
lf_webpage.pyholds aRealml4_cxprofile, which itself instantiates its ownRealmTo pass an "enable logging" flag through the constructor, it would need to be threaded through every one of those call sites, and there's no guarantee the import/instantiation chain doesn't go a level or two deeper in other scripts.
A module-level
configure()called once near the top of a script'smain()avoids that — everyLFCliBase/RealmorLFJsonCommand/LFJsonQuerycreated afterward in the same process just picks it up.What's covered / not covered
Covered
LFRequest.pynow captureslast_response_codeand a one-linelast_diagnosticssummary (reason + X-Error-* headers) on every request, win or fail, so callers have something worth logging.lfcli_base.py(LFCliBase, used byRealm) andlanforge_api.py(BaseLFJsonRequest) both callapi_call_log.record(...)after every GET / POST / PUT / DELETE, using those diagnostics.Not covered
json_get()/ etc. at all — those aren't covered yet and will be migrated separately.Pause / resume
monitor_for_runtime_csv()inlf_webpage.pypolls in a tight loop and would otherwise flood the CSV with repetitive, rarely-useful entries.Added:
api_call_log.pause()api_call_log.resume()so state (enabled + filename) is preserved but recording is suppressed during that loop by default.
--log_monitor_api_callsopts back in if someone actually wants those calls logged too.Usage
lf_webpage.py ... \ --save_api \ [--api_log_file_name /path/to/log.csv] \ [--log_monitor_api_calls] (this is somthing change wrt script )Commits
LFRequest.py— capture response code + diagnostics summary per requestapi_call_log.py— new process-wide CSV logger (configure/record/is_enabled)lfcli_base.py— wire_log_api_callintojson_get/json_post/json_put/json_deletelanforge_api.py— same, for thelanforge_clientrequest pathlf_webpage.py— add--save_api/--api_log_file_nameflags, configure logger, copy CSV into report dirapi_call_log.py— addpause()/resume()lf_webpage.py— pause logging during the runtime-CSV monitor loop by default, add--log_monitor_api_callsoverrideFollow-ups (out of scope here)
json_get()/ etc.Here is the log csv That generated out of this when we ran lf_webpage.py :
lf_api_calls.csv