End-to-End Logging
How Triton stitches one user action — starting in an LWC, hopping into Apex, and fanning out into a Flow — into a single correlated trace.
A single click in the UI almost never stays in one context. The user presses a button in a Lightning Web Component, that calls an Apex controller, the controller commits a record, and the DML kicks off an autolaunched Flow. Four contexts, one intent — and, without help, four disconnected piles of logs.
This section is about making those four piles into one story. Triton correlates logs across LWC, Apex, and Flow using a shared transaction id, so when you open a log in Pharos you can follow the whole chain from the button press to the Flow that failed three hops later.
Three pages make up this section:
This page — the full LWC → Apex → Flow walkthrough.
Transactions & Platform Cache — how the transaction id is created, resumed, and shared across contexts (including
Triton.withCache()andTritonCacheManager).Spans & Distributed Tracing — how spans (
spanId/parentSpanId) add parent-child structure within a transaction, and how that maps to OpenTelemetry concepts.
If you haven't yet, skim Logging in LWC and Logging in Flow first — this page assumes you know the basics of each and focuses on wiring them together.
The scenario
We'll trace one interaction all the way through:
A user clicks a button in an LWC.
The LWC calls an Apex controller.
The controller performs DML.
The DML fires an autolaunched Flow, which logs its own progress.
Our goal: every log from all four steps shares one transaction id, so they group together in Pharos.
Transaction: 7fb8c320-e8f9-4f1b-9742-1a5768b9e0d2
├── LWC "Flow Demo - Start" (Frontend)
├── Apex "Performing DML" (Backend)
└── Flow Log actions (Flow)
└── Unhandled Flow error (auto-captured)What "correlation" actually means
The correlation id is the transaction id. In Apex it lives statically on Triton.TRANSACTION_ID; in LWC it lives on your logger instance as this.triton.transactionId; in Flow it rides along as the Transaction ID parameter of the Log action. When two logs carry the same transaction id, Pharos groups them.
The interesting question is how that one id makes it from the browser, into Apex, and on into the Flow. There are two ways to do it, and they're not mutually exclusive:
Explicit passing
You read this.triton.transactionId in the LWC and pass it to Apex as a parameter; Apex calls Triton.resumeTransaction(id).
Simple, linear call paths where you control every hop.
Platform cache
Triton.withCache() stashes the id in platform Org cache under a per-user key. Later Apex that calls Triton.withCache() as the same user resumes it within the Cache TTL. A Flow in the same transaction inherits it; a Flow in a separate transaction needs the id passed to its Transaction ID input.
Multi-component or multi-call scenarios where passing the id everywhere is painful.
Both produce the exact same grouped result. The rest of this page walks each one. For the full mechanics of transactions and the cache, see Transactions & Platform Cache.
Approach 1 — Explicit parameter passing
The most transparent option: read the transaction id in the LWC and hand it to Apex directly.
The LWC
this.triton.transactionId is the id the LWC logger generated (or resumed) for this session. Passing it as a plain method argument is all it takes.
The Apex controller
Two things to notice:
Triton.resumeTransaction(transactionId)setsTRANSACTION_IDto the LWC's id. From here, every Apex log — and every log the Flow produces during theupdate— carries that id.We buffer with
Triton.debug(...)/Triton.error(...)and publish once withTriton.flush(). See Buffering, Flushing & Deferred Publishing for why that's the right default.
Approach 2 — Platform cache
When threading a parameter through every layer gets tedious, let the platform cache carry the id for you.
The LWC
The LWC barely changes — it doesn't need to pass anything:
The Apex controller
Triton.withCache() does the work: if a transaction id is sitting in Org cache, it resumes it; if not, it starts a fresh one and caches it. Either way, the Flow triggered by the update inherits the same id.
The Flow leg
The Flow side is exactly as described in Logging in Flow — add the Log action, pass $Flow.InterviewGuid as the Interview GUID, and configure Area / Summary / Details. You do not need to set the Transaction ID parameter for this scenario: because the Flow runs inside the same Apex transaction that already called resumeTransaction or withCache, it picks up TRANSACTION_ID automatically.
Flow logs publish a little later
There's one behavioral detail worth knowing for end-to-end debugging. Flow logs aren't published inline like Apex logs. The Log invocable drains Triton's buffer and hands the records to TritonFlowFlushBatch, a singleton batch that publishes them shortly after (buffered in Org cache, flushed via a short-delayed batch). This keeps high-volume Flows from burning platform-event allocations on the hot path.
The practical upshot: the LWC and Apex logs may appear in Pharos a beat before the Flow logs. They'll all land under the same transaction id — the Flow leg just arrives fashionably late. This is the drain() path described in Buffering, Flushing & Deferred Publishing.
Unhandled Flow errors come along for free
If the Flow throws an unhandled error, you don't need a fault path to capture it. Because you passed $Flow.InterviewGuid to your Log action, Pharos correlates the automatically-captured Flow error with your transaction. Let's force one by clearing a required field:
The resulting trace in Pharos:
Do / Don't
Where to go next
Transactions & Platform Cache — the mechanics behind
resumeTransaction,withCache, and the cache manager.Spans & Distributed Tracing — add parent-child structure inside a single transaction.
Coming from 1.x? The transaction methods are unchanged in spirit but now static — see Migration.
Last updated