Repository navigation
feat(parser): count Flow and Process Builder database usage (#871) - #930
Merged
lcottercertinia merged 3 commits intoAug 13, 2026
Merged
Conversation
…#871) A flow element's SOQL and DML never appear as statement lines, so the only record is the count the element reports. Attribute that count to the element, less whatever its own subtree already logged, so the totals stay at or below what the log reports. Runs after the tree is aggregated, because the residual needs the subtree totals. Elements register at parse time, so an element the log truncated is still counted.
COUNT_LABEL_RE requires a leading digit, so a head such as "SOQL queries, total 1 out of 100" lost its limitUsage entirely. The previous code stripped the count with a no-op replace and kept the observation. A missing count now costs only the delta.
applyFlowDbResiduals summed every child delta. A repeated or cumulative line over-attributed the element, and the zero floor does not catch that direction. The reported rise in `used` is now the ceiling.
lcottercertinia
approved these changes
Aug 13, 2026
lcottercertinia
pushed a commit
to apex-dev-tools/apex-log-parser
that referenced
this pull request
Aug 14, 2026
Ports certinia/debug-log-analyzer#930 (merged upstream as `fb35a536`), plus a cleanup pass. ## Why Salesforce emits no `SOQL_EXECUTE_BEGIN` or `DML_BEGIN` for the database work a Flow or Process Builder element does itself. The only record is the leading count on `FLOW_BULK_ELEMENT_LIMIT_USAGE` / `FLOW_ELEMENT_LIMIT_USAGE`. Those elements therefore showed zero SOQL and DML. ## How That count is the rise in the transaction's governor counter across the element, so it also covers any statement the element's subtree logged for itself. Only the residual is attributed - the reported rise minus the subtree total, floored at zero and capped at the rise in the running total. This can only make a line more accurate. It can never report more than the log claims. The pass runs after `aggregateTotals`, over the elements in reverse registration order, so descendants settle before their ancestors and a nested subflow is not counted twice. CPU time and heap size are measures, not counters, so they are not attributed. `parseTotalLimit` also keeps a head with no leading count, at `delta: 0`. Before, such a line lost its `limitUsage`. Needs `WORKFLOW` at `FINER` or above. At `FINE` the parser fabricates nothing. ## Notes - Two commits: the port, then a refactor that maps metrics to counter fields instead of a switch and walks each ancestor chain once. - No changeset. `0.1.0` is not published yet, so `initial-release.md` covers this. ## Test `pnpm run ci` - 138 tests pass. 10 new cases in `FlowDatabaseAttribution.test.ts` cover bulk and non-bulk elements, delta versus running total, the subtree residual, a full-subtree cover, a repeated line, a nested subflow, truncation, and `FINE` level.
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.
Closes #871.
The problem
Salesforce emits no
SOQL_EXECUTE_BEGINorDML_BEGINfor the database work a Flow or Process Builder element does itself. The only record is the count the element reports:Without this, that work is invisible in every table and column view.
What this does
The reported count is the rise in the transaction's governor counter across the element, so it also covers anything the element's subtree logged for itself — Apex it called, a trigger its DML fired, elements inside a subflow. Attributing the whole count would double-count that work.
So only the residual is attributed: the reported count less what the subtree already logged, floored at zero. Every line either becomes accurate or stays as it is today; none can report more than the log itself claims for the element.
applyFlowDbResidualsruns afteraggregateTotals, because the residual needs the subtree totals to exist. Elements register inparser.flowDbElementsat parse time, so an element the log truncated before itsENDline is still counted. Elements are visited innermost first, so a subflow does not re-count what its children reported.Needs
WORKFLOWatFINERor above — atFINEthe log reports no flow usage at all.The known limitation
The parser cannot tell a limit-consuming statement from a free one. Where a subtree statement consumed no limit — custom metadata SOQL, a managed-package describe — the residual subtracts it anyway and understates the element. That is the same direction as today's behaviour, never an overstatement.
Validation
Against a corpus of real logs, over the 16 flow-delta logs that carry a
CUMULATIVE_LIMIT_USAGEblock:total 3 out of 150DML while its cumulative block reports 0 and 1 across two namespaces. No attribution scheme satisfies both numbers.So the guarantee is per element, not per transaction: a transaction total can still pass a snapshot where free statements were logged or namespaces split. That gap is pre-existing and stays visible in the Database tab's found-vs-counted row.
Tests
apex-log-parser/__tests__/FlowDatabaseAttribution.test.tscovers bulk and non-bulk elements, delta-not-running-total, subtree residual, subtree covering the whole reported count reconciled against the snapshot, nested subflow, a truncated element, andFINElevel fabricating nothing.