For the complete documentation index, see llms.txt. This page is also available as Markdown.

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() and TritonCacheManager).

  • 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:

  1. A user clicks a button in an LWC.

  2. The LWC calls an Apex controller.

  3. The controller performs DML.

  4. 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:

Approach
How the id travels
Best for

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.

Why does this even work across the DML → Flow boundary? The autolaunched Flow runs inside the same Apex transaction as your controller's DML. Because Triton keeps TRANSACTION_ID as static state for the life of that Apex transaction, the Flow's Log action inherits the id automatically — you don't have to pass it. The two approaches below are really about getting the id from the browser into Apex in the first place.

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) sets TRANSACTION_ID to the LWC's id. From here, every Apex log — and every log the Flow produces during the update — carries that id.

  • We buffer with Triton.debug(...) / Triton.error(...) and publish once with Triton.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:

When the LWC's logs are saved, TritonLwc.saveComponentLogs calls Triton.withCache() first. If an id is already cached for the user (within the Cache TTL), that cached id wins and the LWC's own id is not used; otherwise it resumes the LWC's id and writes it into platform Org cache. That's what makes it available to a later Apex call without any parameter passing. The full sequence is spelled out in Transactions & Platform Cache.

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.

Set the Transaction ID parameter only when the Flow starts the chain, or when you're correlating a Flow that runs in a separate transaction from the Apex that set the id. In that case, pass the id into the Flow and map it to the Log action's Transaction ID — it will resumeTransaction for you.

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

Last updated