> For the complete documentation index, see [llms.txt](https://triton.pharos.ai/llms.txt). Markdown versions of documentation pages are available by appending `.md` to page URLs; this page is available as [Markdown](https://triton.pharos.ai/instrumentation-skills/instrument-flows.md).

# Instrument Flows

The instrument-flows skill inserts Triton Log actions into a Flow's metadata XML at entry, fault paths, and record operations, then optionally deploys it.

The **instrument-flows** skill reads a Flow's metadata XML, parses its elements, and inserts Triton **Log** actions at the moments that matter — flow entry, every fault connector, negative decision branches, record operations, and subflow boundaries — using the `TritonFlow` invocable. Then it shows you the diff and, if you want, deploys.

{% hint style="info" %}
**Invocation is agent-specific.** In agents that support slash commands (Claude Code, Cursor) you invoke it as `/pharos:instrument-flows <path>`; in others you point the agent at this skill and give it the path. See [Running these in your agent](https://triton.pharos.ai/instrumentation-skills.md#running-these-in-your-agent).
{% endhint %}

## Usage

{% code lineNumbers="true" %}

```bash
/pharos:instrument-flows <path> [--area <Area>] [--level <Level>] [--deploy]
```

{% endcode %}

| Argument   | Required | Meaning                                                                                                                                              |
| ---------- | :------: | ---------------------------------------------------------------------------------------------------------------------------------------------------- |
| `<path>`   |     ✅    | The `.flow-meta.xml` file to instrument. If omitted, the skill asks.                                                                                 |
| `--area`   |          | The business/functional Area (a free String, required on every log action). Inferred from the flow's purpose and matched to related code if omitted. |
| `--level`  |          | Default level for informational checkpoints. Defaults to `INFO`. Fault paths always use `ERROR`.                                                     |
| `--deploy` |          | Deploy the flow after you accept the diff.                                                                                                           |

{% hint style="warning" %}
**Extra prerequisite: Triton must be in the target org.** On top of the shared Salesforce-CLI-and-default-org check, this skill verifies that the `TritonFlow` invocable actually exists in the connected org (it runs a tiny anonymous-Apex probe). If Triton isn't installed there, the skill stops and tells you to deploy the Triton package first — otherwise the Log actions wouldn't save or deploy.
{% endhint %}

## How Flow logging works — individual named inputs

Flow logging calls the `TritonFlow` invocable — an Apex action labeled **Log**, under the **TritonLogging** category. The crucial detail: the log record is built **in Apex**, and the Flow supplies **individual named String inputs**. Each field is its own `<inputParameters>` element.

{% hint style="danger" %}
**Never pass a collection or an SObject — this is a hard constraint.** There is no `flowLogs` collection input and no `pharos__Log__c` / SObject input; those parameters don't exist, and a Flow that references them won't save or deploy. Every log point is a single `<actionCalls>` with individual primitive inputs.
{% endhint %}

### Required inputs on every log action

| Input           | Required | Notes                                                               |
| --------------- | :------: | ------------------------------------------------------------------- |
| `area`          |     ✅    | Area string (free-form; matched to related code).                   |
| `summary`       |     ✅    | The log's one-line headline.                                        |
| `interviewGUID` |     ✅    | Always `{!$Flow.InterviewGuid}` — **exact casing `interviewGUID`**. |

Optional inputs the skill sets where relevant: `category` (recommend `Flow`; invalid values fall back to `Flow`), `type` (from `<processType>`, e.g. `Screen Flow`), `level`, `details`, `operation`, `flowApiName` (the plain API name — no version suffix), `flowVersion`, `transactionId`, `additionalFields` (a JSON string), and `stacktrace` / `fullStacktrace` for chaining.

{% hint style="info" %}
**Split the name and the version.** `flowApiName` takes the **plain** API name; the version number goes in `flowVersion`. Component-scoped `Log_Level__mdt` rules match the Flow API Name in full, so `My_Flow-4` won't match a rule naming `My_Flow`. See [Logging in Flow](https://triton.pharos.ai/flows.md#flow-api-name-and-flow-version).
{% endhint %}

{% hint style="info" %}
**Chaining stack traces.** The `fullStacktrace` **output** is populated; the `stacktrace` output is **always null — don't rely on it.** To carry context forward, assign `fullStacktrace` to a variable and pass it as the `fullStacktrace` **input** of a later action.
{% endhint %}

### The canonical log action

{% code lineNumbers="true" %}

```xml
<actionCalls>
    <name>Triton_Log_FlowStart</name>
    <label>Triton Log — Flow Start</label>
    <locationX>50</locationX>
    <locationY>120</locationY>
    <actionName>TritonFlow</actionName>
    <actionType>apex</actionType>
    <connector>
        <targetReference>Next_Element</targetReference>
    </connector>
    <inputParameters>
        <name>area</name>
        <value><stringValue>PartnerIntake</stringValue></value>
    </inputParameters>
    <inputParameters>
        <name>summary</name>
        <value><stringValue>Flow started: Partner_Intake</stringValue></value>
    </inputParameters>
    <inputParameters>
        <name>interviewGUID</name>
        <value><elementReference>$Flow.InterviewGuid</elementReference></value>
    </inputParameters>
    <inputParameters>
        <name>category</name>
        <value><stringValue>Flow</stringValue></value>
    </inputParameters>
    <inputParameters>
        <name>level</name>
        <value><stringValue>INFO</stringValue></value>
    </inputParameters>
</actionCalls>
```

{% endcode %}

## What it instruments

After parsing the flow's `<processType>`, elements, fault connectors, start node, and any existing `TritonFlow` actions (already-instrumented elements are skipped), the skill adds:

* **Flow entry** — an INFO log after the start connector's first target: `Flow started: <FlowApiName>`.
* **Fault paths (most critical)** — for **every** element with a `<faultConnector>`, an `ERROR` log as the first element on the fault path, with `details` = `{!$Flow.FaultMessage}`. This is how Pharos surfaces unhandled Flow errors, and an `ERROR` level auto-creates an issue — so fault instrumentation is non-negotiable.
* **Negative decision branches** — a `WARNING` log on `<decisions>` outcomes representing error states or empty results (happy paths stay at `DEBUG` to keep noise down).
* **Record operations** — a `DEBUG` log after `<recordCreates>` / `<recordUpdates>` / `<recordDeletes>` success paths.
* **Subflow boundaries** — an INFO log before each `<subflows>` element.

The skill never removes existing elements or connectors — it only inserts new `<actionCalls>` — and it never adds logs inside `<loops>` (log before/after the loop, not per iteration).

### Fault-path logging

{% code lineNumbers="true" %}

```xml
<actionCalls>
    <name>Triton_Log_Create_Lead_Fault</name>
    <label>Triton Log — Create Lead fault</label>
    <locationX>350</locationX>
    <locationY>480</locationY>
    <actionName>TritonFlow</actionName>
    <actionType>apex</actionType>
    <inputParameters>
        <name>area</name>
        <value><stringValue>PartnerIntake</stringValue></value>
    </inputParameters>
    <inputParameters>
        <name>summary</name>
        <value><stringValue>Create_Lead fault</stringValue></value>
    </inputParameters>
    <inputParameters>
        <name>interviewGUID</name>
        <value><elementReference>$Flow.InterviewGuid</elementReference></value>
    </inputParameters>
    <inputParameters>
        <name>details</name>
        <value><elementReference>$Flow.FaultMessage</elementReference></value>
    </inputParameters>
    <inputParameters>
        <name>level</name>
        <value><stringValue>ERROR</stringValue></value>
    </inputParameters>
</actionCalls>
```

{% endcode %}

### Transaction stitching

To tie the Flow into an existing LWC/Apex transaction, the skill passes the id as the `transactionId` input on **every** log action. If the flow already has a transaction-id input variable, it references it; otherwise, when the flow is invoked from Apex/LWC, it adds an input variable and passes it:

{% code lineNumbers="true" %}

```xml
<variables>
    <name>TritonTransactionId</name>
    <dataType>String</dataType>
    <isCollection>false</isCollection>
    <isInput>true</isInput>
    <isOutput>false</isOutput>
</variables>
```

{% endcode %}

If no id is supplied, `TritonFlow` starts/uses one automatically and correlates via the Interview GUID — so `transactionId` is optional.

## Review the diff

The skill summarizes what it added — flow entry, fault paths, decision branches, record operations, subflow calls, the `category`/`type` it set, and the transaction-id approach — plus the key XML. Answer **`yes`** to apply, **`modify`** for corrections, or **`skip`** to write nothing. On write, the modified XML goes back to the original `.flow-meta.xml`, preserving existing indentation and structure.

## Deploy

{% code lineNumbers="true" %}

```bash
sf project deploy start --source-dir <path-to-flow-xml> --json
# or:
sfdx force:source:deploy -p <path-to-flow-xml> --json
```

{% endcode %}

{% hint style="warning" %}
**Draft-version activation reminder.** Deploying a Flow creates a **new version in Draft state** — it isn't live yet. After a successful deploy, activate it: **Setup → Flows → `<FlowApiName>` → Activate.**
{% endhint %}

## Where to go next

* [Logging in Flow](https://triton.pharos.ai/flows.md) — the no-code walkthrough of the same Log action.
* [Instrument Apex](https://triton.pharos.ai/instrumentation-skills/instrument-apex.md) · [Instrument LWC](https://triton.pharos.ai/instrumentation-skills/instrument-lwc.md) — the other legs of a stitched, cross-technology trace.
* [Instrument the Org](https://triton.pharos.ai/instrumentation-skills/instrument-org.md) — run this skill across every flow at once.
* [End-to-End Logging](https://triton.pharos.ai/end-to-end.md) — how the Flow leg folds into one transaction with LWC and Apex.
