Page MenuHomeIn-Portal Phabricator

INP-1837 - Record code fragment in the System Log backtrace
ClosedPublic

Authored by alex on Feb 10 2023, 6:39 AM.

Details

Test Plan

Preparations

  1. in IDE:
    1. open the modules/custom/units/widgets/widget_eh.php file for editing
    2. in the \WidgetEventHandler::SetCustomQuery method after calling the parent method add $b = $a + 1;
    3. save changes

Part 1 (install/upgrade)

NOTE: Repeat this test also for an upgrade.
  1. perform a clean install
  2. login to the Admin Console
  3. go to the ConfigurationWebsiteAdanced section
  4. confirm, that the Record code fragments in "System Log" for these paths (regexp) system setting is present and has #(modules/custom|system/cache/modules/custom)/.*# value
  5. go to the ConfigurationWebsiteScheduled Tasks
  6. confirm, that a rotate_system_log_code_fragments was added
  7. go to phpMyAdmin
  8. confirm, that TIMESTAMP_CODE_FRAGMENTS_ROTATED index for the SystemLog table is present

Part 2 (code fragment logging, filtering, display, rotation)

NOTE: Repeat this test with different (see below) system setting values.
  1. login to the Admin Console
  2. go to the ConfigurationWebsiteAdanced section
  3. set the Record code fragments in "System Log" for these paths (regexp) system setting to (choose value based on test iteration):
    • #(modules/custom|system/cache/modules/custom)/.*#
    • #(core|system/cache/core)/.*#
    • (empty string)
  4. save changes
  5. go to the CustomWidgets section
  6. confirm, that an Undefined variable: a notice appears in Debugger
  7. go to the Logs & ReportsSystem Log section
  8. confirm, that record for the Undefined variable: a notice was created
  9. open the record for the Undefined variable: a notice for viewing/editing
  10. testing source line toggle code
    1. confirm, that the Toggle Code... link is shown at the end of the Source Filename: line value when a source file matches used filtering regexp
    2. click on the Toggle Code... link once
    3. confirm, that:
      • a highlighted code fragment appears
      • each line in the code fragment has a line number, that corresponds to the line number in the associated file
      • line number associated with the trace is marked with the >>> sign
  11. testing backtrace
    1. confirm, that the backtrace looks visually the same as in other system log records
    2. click on the ALL Function: links of the backtrace records
    3. confirm, that:
      • the Arguments: text is shown above function/method arguments
      • the Toggle Code... link is shown below function/method arguments in the lines related to:
        • the Custom module files (e.g. PHP files from "modules/custom/units" or TPL file from the "modules/custom/admin_templates", that were compiled into PHP files), when the system setting was #(modules/custom|system/cache/modules/custom)/.*#
        • the Core module files (e.g. PHP files from "core/*" or TPL file from the "core/admin_templates", that were compiled into PHP files), when the system setting was #(core|system/cache/core)/.*#
        • the Core and Custom module files, when the system setting was (empty string)
    4. click on the Toggle Code... link once
    5. confirm, that:
      • a highlighted code fragment appears
      • each line in the code fragment has a line number, that corresponds to the line number in the associated file
      • line number associated with the trace is marked with the >>> sign
  12. testing rotation
    1. execute the rotate_system_log_code_fragments scheduled task
    2. confirm, that system log records, created during tests, have retained their code fragments
    3. change the LogTimestamp of a system log record, that has code fragments to a 1672524000 (1 Jan 2023)
    4. execute the rotate_system_log_code_fragments scheduled task
    5. confirm, that above changed system log record doesn't contain any code fragments (source & backtrace)

Diff Detail

Repository
rINP In-Portal
Lint
Automatic diff as part of commit; lint not applicable.
Unit
Automatic diff as part of commit; unit tests not applicable.

Event Timeline

alex created this revision.Feb 10 2023, 6:39 AM
alex requested review of this revision.Feb 10 2023, 6:39 AM
alex updated this revision to Diff 1135.Feb 10 2023, 6:41 AM

Adding phrases.

alex planned changes to this revision.EditedFeb 13 2023, 2:43 AM

Issues:

  1. attempts to extract code from the trace, that doesn't contain a file reference
  2. code of the source file/line isn't shown (because it's outside of a trace)

Improvements:

  1. add system setting to specify exclusion paths for code logging to save disk space
  2. remove "Code Fragment" information from the "SystemLog.LogBacktrace" column for records, older than 1 month
alex edited the test plan for this revision. (Show Details)Apr 14 2023, 5:16 AM
alex edited the test plan for this revision. (Show Details)Apr 14 2023, 6:16 AM
alex edited the test plan for this revision. (Show Details)Apr 14 2023, 6:36 AM
alex edited the test plan for this revision. (Show Details)
alex edited the test plan for this revision. (Show Details)Apr 14 2023, 7:02 AM
alex edited the test plan for this revision. (Show Details)Apr 17 2023, 5:16 AM
alex edited the test plan for this revision. (Show Details)Apr 17 2023, 5:19 AM
alex updated this revision to Diff 1147.Apr 17 2023, 5:24 AM
  • added ability to log code fragments for source file/line
  • added code fragment rotation
  • added filtering (prevent logging code fragments from non-interesting files)
  • fixed notices, when logging code fragments from non-specified files
alex updated this revision to Diff 1148.Apr 17 2023, 5:57 AM

Added "SystemLog.LogCodeFragmentsRotated" to the unit config.

erik accepted this revision.Apr 17 2023, 12:10 PM
This revision is now accepted and ready to land.Apr 17 2023, 12:10 PM
This revision was landed with ongoing or failed builds.Apr 19 2023, 6:35 AM
This revision was automatically updated to reflect the committed changes.