Bug 32057 - Add optional stack trace to action logs
Summary: Add optional stack trace to action logs
Status: Needs documenting
Alias: None
Product: Koha
Classification: Unclassified
Component: Architecture, internals, and plumbing (show other bugs)
Version: master
Hardware: All All
: P5 - low enhancement (vote)
Assignee: Kyle M Hall
QA Contact: Marcel de Rooy
URL:
Keywords:
Depends on:
Blocks:
 
Reported: 2022-11-01 10:35 UTC by Kyle M Hall
Modified: 2023-03-17 17:26 UTC (History)
4 users (show)

See Also:
Change sponsored?: ---
Patch complexity: Small patch
Documentation contact:
Documentation submission:
Text to go in the release notes:
It can be useful to know where in Koha a logged action was generated from, and how. This enhancement adds stack traces to action logs. To use, add a number for the trace depth (such as 3) to the new system preference ActionLogsTraceDepth. The details for the stack trace are available by querying the database, for example: SELECT * FROM action_logs WHERE trace IS NOT NULL;
Version(s) released in:
23.05.00


Attachments
Bug 32057: Add optional stack trace to action logs (6.40 KB, patch)
2022-11-01 10:51 UTC, Kyle M Hall
Details | Diff | Splinter Review
Bug 32057: Add optional stack trace to action logs (6.40 KB, patch)
2022-11-01 11:04 UTC, Kyle M Hall
Details | Diff | Splinter Review
Bug 32057: Add optional stack trace to action logs (6.27 KB, patch)
2022-12-20 14:16 UTC, Kyle M Hall
Details | Diff | Splinter Review
Bug 32057: Add optional stack trace to action logs (6.27 KB, patch)
2022-12-20 14:21 UTC, Kyle M Hall
Details | Diff | Splinter Review
Bug 32057: Use replace insert query with use of Koha::ActionLogs (1.45 KB, patch)
2022-12-20 14:22 UTC, Kyle M Hall
Details | Diff | Splinter Review
Bug 32057: Replace insert query with use of Koha::ActionLogs (1.44 KB, patch)
2022-12-20 14:22 UTC, Kyle M Hall
Details | Diff | Splinter Review
Bug 32057: Replace insert query with use of Koha::ActionLogs (1.44 KB, patch)
2022-12-20 14:24 UTC, Kyle M Hall
Details | Diff | Splinter Review
Bug 32057: Update ActionLog schema file [DO NOT PUSH] (1.51 KB, patch)
2022-12-21 14:49 UTC, Kyle M Hall
Details | Diff | Splinter Review
Bug 32057: Add optional stack trace to action logs (6.32 KB, patch)
2022-12-21 17:41 UTC, David Nind
Details | Diff | Splinter Review
Bug 32057: Replace insert query with use of Koha::ActionLogs (1.49 KB, patch)
2022-12-21 17:41 UTC, David Nind
Details | Diff | Splinter Review
Bug 32057: Update ActionLog schema file [DO NOT PUSH] (1.56 KB, patch)
2022-12-21 17:41 UTC, David Nind
Details | Diff | Splinter Review
Bug 32057: Add optional stack trace to action logs (6.41 KB, patch)
2023-02-22 13:56 UTC, Marcel de Rooy
Details | Diff | Splinter Review
Bug 32057: Replace insert query with use of Koha::ActionLogs (1.59 KB, patch)
2023-02-22 13:56 UTC, Marcel de Rooy
Details | Diff | Splinter Review
Bug 32057: Update ActionLog schema file [DO NOT PUSH] (1.66 KB, patch)
2023-02-22 13:56 UTC, Marcel de Rooy
Details | Diff | Splinter Review
Bug 32057: (QA follow-up) Remove pretty flag (871 bytes, patch)
2023-02-22 13:56 UTC, Marcel de Rooy
Details | Diff | Splinter Review
Bug 32057: (QA follow-up) Add a simple test (1.57 KB, patch)
2023-02-22 13:56 UTC, Marcel de Rooy
Details | Diff | Splinter Review
Bug 32057: (follow-up) Add INSERT IGNORE in dbrev (1.29 KB, patch)
2023-03-14 12:32 UTC, Marcel de Rooy
Details | Diff | Splinter Review

Note You need to log in before you can comment on or make changes to this bug.
Description Kyle M Hall 2022-11-01 10:35:05 UTC
It can be useful to know where in Koha a particular logged action was generated from, and how. We should add the ability to attach a syspref controlled basic stack trace with the caller depth controlled via the syspref. We can the call caller() until the specified depth has been reached.
Comment 1 Kyle M Hall 2022-11-01 10:51:22 UTC Comment hidden (obsolete)
Comment 2 Kyle M Hall 2022-11-01 11:04:22 UTC Comment hidden (obsolete)
Comment 3 David Nind 2022-12-20 01:58:01 UTC Comment hidden (obsolete)
Comment 4 Kyle M Hall 2022-12-20 14:16:02 UTC Comment hidden (obsolete)
Comment 5 Kyle M Hall 2022-12-20 14:21:51 UTC Comment hidden (obsolete)
Comment 6 Kyle M Hall 2022-12-20 14:22:01 UTC Comment hidden (obsolete)
Comment 7 Kyle M Hall 2022-12-20 14:22:57 UTC Comment hidden (obsolete)
Comment 8 Kyle M Hall 2022-12-20 14:24:07 UTC Comment hidden (obsolete)
Comment 9 David Nind 2022-12-20 22:00:05 UTC Comment hidden (obsolete)
Comment 10 Kyle M Hall 2022-12-21 14:49:00 UTC Comment hidden (obsolete)
Comment 11 David Nind 2022-12-21 17:41:40 UTC
Created attachment 144786 [details] [review]
Bug 32057: Add optional stack trace to action logs

It can be useful to know where in Koha a particular logged action was generated from, and how. We should add the ability to attach a syspref controlled basic stack trace with the caller depth controlled via the syspref. We can the call caller() until the specified depth has been reached.

Test Plan:
1) Apply this patch
2) Run updatedatabase.pl
4) Restart all the things!
5) Set the new syspref ActionLogsTraceDepth to a number ( e.g. 3 )
6) Update a syspref or trigger another enabled log action
7) Query the database: SELECT * FROM action_logs WHERE trace IS NOT NULL
8) Note the stack trace was created!

Signed-off-by: David Nind <david@davidnind.com>
Comment 12 David Nind 2022-12-21 17:41:45 UTC
Created attachment 144787 [details] [review]
Bug 32057: Replace insert query with use of Koha::ActionLogs

Signed-off-by: David Nind <david@davidnind.com>
Comment 13 David Nind 2022-12-21 17:41:51 UTC
Created attachment 144788 [details] [review]
Bug 32057: Update ActionLog schema file [DO NOT PUSH]

Signed-off-by: David Nind <david@davidnind.com>
Comment 14 David Nind 2022-12-21 18:01:35 UTC
Thanks Kyle for fixing!

I should have thought of running dbic!

Now signed off.

David
Comment 15 Marcel de Rooy 2023-02-17 10:55:37 UTC
Did you think about using Devel::StackTrace / libdevel-stacktrace-perl ?
Comment 16 Kyle M Hall 2023-02-21 13:25:29 UTC
(In reply to Marcel de Rooy from comment #15)
> Did you think about using Devel::StackTrace / libdevel-stacktrace-perl ?

I did have a look at Devel::StackTrace when I started this bug.
Simply put, using caller is the absolute fastest way to do what we need here.
If there are other benefits to Devel::StackTrace I'm not aware of we could look into that on followup bugs!
Comment 17 Marcel de Rooy 2023-02-22 13:56:06 UTC
Created attachment 147152 [details] [review]
Bug 32057: Add optional stack trace to action logs

It can be useful to know where in Koha a particular logged action was generated from, and how. We should add the ability to attach a syspref controlled basic stack trace with the caller depth controlled via the syspref. We can the call caller() until the specified depth has been reached.

Test Plan:
1) Apply this patch
2) Run updatedatabase.pl
4) Restart all the things!
5) Set the new syspref ActionLogsTraceDepth to a number ( e.g. 3 )
6) Update a syspref or trigger another enabled log action
7) Query the database: SELECT * FROM action_logs WHERE trace IS NOT NULL
8) Note the stack trace was created!

Signed-off-by: David Nind <david@davidnind.com>

Signed-off-by: Marcel de Rooy <m.de.rooy@rijksmuseum.nl>
Comment 18 Marcel de Rooy 2023-02-22 13:56:08 UTC
Created attachment 147153 [details] [review]
Bug 32057: Replace insert query with use of Koha::ActionLogs

Signed-off-by: David Nind <david@davidnind.com>

Signed-off-by: Marcel de Rooy <m.de.rooy@rijksmuseum.nl>
Comment 19 Marcel de Rooy 2023-02-22 13:56:10 UTC
Created attachment 147154 [details] [review]
Bug 32057: Update ActionLog schema file [DO NOT PUSH]

Signed-off-by: David Nind <david@davidnind.com>

Signed-off-by: Marcel de Rooy <m.de.rooy@rijksmuseum.nl>
Comment 20 Marcel de Rooy 2023-02-22 13:56:13 UTC
Created attachment 147155 [details] [review]
Bug 32057: (QA follow-up) Remove pretty flag

Not needed for storage. You can always display pretty in the
interface (on a follow-up report).

Signed-off-by: Marcel de Rooy <m.de.rooy@rijksmuseum.nl>
Comment 21 Marcel de Rooy 2023-02-22 13:56:15 UTC
Created attachment 147156 [details] [review]
Bug 32057: (QA follow-up) Add a simple test

Signed-off-by: Marcel de Rooy <m.de.rooy@rijksmuseum.nl>
Comment 22 Marcel de Rooy 2023-02-22 13:56:54 UTC
A future report should add this field to the interface (log viewer).
Comment 23 Tomás Cohen Arazi 2023-03-14 12:10:26 UTC
Pushed to master for 23.05.

Nice work everyone, thanks!
Comment 24 Marcel de Rooy 2023-03-14 12:32:51 UTC
Created attachment 148162 [details] [review]
Bug 32057: (follow-up) Add INSERT IGNORE in dbrev

Preventing:
ERROR - {UNKNOWN}: DBI Exception: DBD::mysql::db do failed: Duplicate entry 'ActionLogsTraceDepth' for key 'PRIMARY' at /usr/share/koha/C4/Installer.pm line 739

Signed-off-by: Marcel de Rooy <m.de.rooy@rijksmuseum.nl>
Comment 25 Marcel de Rooy 2023-03-14 12:33:54 UTC
@RM: last trivial follow-up
Comment 26 Tomás Cohen Arazi 2023-03-14 13:56:32 UTC
Thanks for the follow-up, Marcel.
Comment 27 Matt Blenkinsop 2023-03-17 17:26:11 UTC
Enhancement - not backporting to 22.11.x

Nice work everyone!