> 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-org.md).

# Instrument the Org

The instrument-org skill runs the Apex, LWC, and Flow skills across a Salesforce project — inventory, prioritize, instrument, deploy — in reviewed batches.

The **instrument-org** skill is the "instrument everything" entry point. Point it at a project (or a subtree of it) and it inventories every Apex class, trigger, LWC, and Flow, prioritizes the backlog the way the [Legacy Code Logging Rollout](https://triton.pharos.ai/triton-best-practices/legacy-migration.md) strategy recommends, and then drives [`instrument-apex`](https://triton.pharos.ai/instrumentation-skills/instrument-apex.md), [`instrument-lwc`](https://triton.pharos.ai/instrumentation-skills/instrument-lwc.md), and [`instrument-flows`](https://triton.pharos.ai/instrumentation-skills/instrument-flows.md) across it — feature by feature, with one Area per feature and a review checkpoint at every batch boundary. When it's done, it hands you a coverage report.

It is not a new instrumentation engine — it's an **orchestrator** over the three primitives. Every file it touches is instrumented by exactly the same skill, following exactly the same conventions, that you'd run by hand.

{% hint style="info" %}
**Invocation is agent-specific.** In agents that support slash commands (Claude Code, Cursor) you invoke it as `/pharos:instrument-org <path>`; in others you point the agent at this skill and a directory. See [Running these in your agent](https://triton.pharos.ai/instrumentation-skills.md#running-these-in-your-agent). For a hands-off, "point at an org" experience, run it through [The Triton Instrumentation Agent](https://triton.pharos.ai/instrumentation-skills/instrumentation-agent.md).
{% endhint %}

{% hint style="warning" %}
**Run** [**`audit-logging`**](https://triton.pharos.ai/instrumentation-skills/audit-logging.md) **first.** The audit is read-only and gives you the map — how much code exists, where the gaps are, and a suggested order — before `instrument-org` starts writing. `instrument-org` can run the audit itself as Step 1, but seeing it on its own first is the safer habit on a large org.
{% endhint %}

## Usage

{% code lineNumbers="true" %}

```bash
/pharos:instrument-org [<path>] [--area-map <file>] [--phase <n>] [--tech apex,lwc,flow] [--batch-size <n>] [--deploy] [--dry-run]
```

{% endcode %}

| Argument       | Required | Meaning                                                                                                                                     |
| -------------- | :------: | ------------------------------------------------------------------------------------------------------------------------------------------- |
| `<path>`       |          | Project root or a subtree (e.g. `force-app/main/default/`). Defaults to the detected project root.                                          |
| `--area-map`   |          | A file (or inline list) mapping folders/features to Area strings, so the skill doesn't have to infer every Area. Inference is the fallback. |
| `--phase`      |          | Run only one rollout phase (see [The rollout phases](#the-rollout-phases)). Omit to run phases in order with checkpoints between them.      |
| `--tech`       |          | Restrict to some technologies, e.g. `--tech apex,flow`. Defaults to all three.                                                              |
| `--batch-size` |          | How many files to instrument before pausing for a batch review. Defaults to a feature or folder boundary.                                   |
| `--deploy`     |          | Deploy each batch after you accept it. Without it, the skill asks per batch.                                                                |
| `--dry-run`    |          | Inventory and plan only — produce the report and the proposed order, write nothing.                                                         |

## How it works

### Step 1 — Inventory

The skill walks the project and catalogs everything instrumentable:

* Apex classes and triggers (skipping `@isTest` classes).
* LWCs (component directories under `lwc/`).
* Flows (`.flow-meta.xml`), noting `<processType>`.

For each item it records the current instrumentation state — already-instrumented, partially instrumented, or untouched — so a re-run only fills gaps and never double-instruments. This is the same signal [`audit-logging`](https://triton.pharos.ai/instrumentation-skills/audit-logging.md) produces.

### Step 2 — Group into features

Raw files aren't the unit of work; **features** are. The skill clusters related code so a whole feature's logs share one Area and one correlated transaction:

* A trigger, its handler class, and the service classes it calls.
* An LWC and the Apex controller it calls (and any Flow that controller invokes).
* A screen Flow and the subflows/record operations beneath it.

It resolves the Area for each cluster **once** — from your `--area-map`, from an Area already used by related code, or by inference — and reuses it across every file in the cluster. This is what keeps a feature's logs grouping cleanly in Pharos.

### Step 3 — Prioritize (the rollout phases)

The backlog is ordered by value and risk, not alphabetically — mirroring the [Legacy Code Logging Rollout](https://triton.pharos.ai/triton-best-practices/legacy-migration.md) phasing:

1. **Edge entry points.** Public `@AuraEnabled` controllers, REST endpoints, Queueables, Batch `start`/`finish`, global callouts, and the LWCs/Flows that call them. Highest visibility, well-understood boundaries — and where cross-boundary transaction correlation gets established.
2. **High-value internals.** Trigger handlers and core service classes.
3. **Broad sweep.** Low-risk utilities and everything remaining; retire the last `System.debug`.

The skill also respects the **comfort tiers** from the rollout guide: it flags business-critical, low-comfort code (old, untested, no author) and proposes *minimal* instrumentation there — or defers it for a human — rather than aggressively rewriting code nobody understands.

### Step 4 — Instrument, batch by batch

For each batch (a feature, a folder, or `--batch-size` files), the skill runs the matching per-technology skill on every file, threading the cluster's shared Area and stitching transactions across the LWC → Apex → Flow legs. Then it pauses:

{% code lineNumbers="true" %}

```
Batch 3/17 — Opportunity Management (Area: OpportunityManagement)
  ✎ OpportunityController.cls        @AuraEnabled  · txn resume + 2 catches + flush
  ✎ opportunityCard (LWC)            timeBackendCall · stitches via transactionId
  ✎ Recalc_Opportunity.flow-meta.xml 1 fault path + flow entry
Review: [yes] apply & continue · [modify] · [skip file] · [pause]
```

{% endcode %}

You review the batch as a unit — the same `yes` / `modify` / `skip` choices as a single-file run, plus `pause` to stop and resume later. Nothing in the batch is written until you accept it.

### Step 5 — Deploy (optional, per batch)

With `--deploy` (or on confirmation), each accepted batch deploys before the next one starts, so instrumented code lands incrementally and you can watch logs appear in Pharos as you go. A failed deploy stops the run without reverting files, exactly like the single-file skills.

### Step 6 — Coverage report

At the end (or on `pause`), the skill writes a summary: how many files of each type were instrumented, skipped, or deferred; the Areas assigned; transactions correlated; and what's left. Re-running picks up where it left off.

{% code lineNumbers="true" %}

```
Triton instrumentation coverage — force-app/main/default
  Apex     124/141 instrumented · 9 tests skipped · 8 deferred (low-comfort)
  LWC       38/40  instrumented · 2 deferred
  Flows     19/22  instrumented · 3 deferred (managed)
  Areas assigned: 11 · Transactions correlated across 27 LWC→Apex chains
  Deferred items and reasons: see report.md
```

{% endcode %}

## Staying in control at scale

The point of the human-in-the-loop diff doesn't disappear just because you're running org-wide — it moves to the **batch** boundary:

* **Checkpoints, not a firehose.** You approve a feature at a time, not hundreds of files at once.
* **Resumable.** `pause` and re-run; the inventory tracks what's done.
* **`--dry-run` first.** See the full plan and Area assignments before a single write.
* **Defers instead of guesses.** Low-comfort, business-critical code is surfaced for a human rather than rewritten blindly.

{% hint style="success" %}
**This is the "instrument everywhere" button — with a seatbelt.** You get the leverage of one command across an entire org, but the tedious 90% is what's automated, not the judgment. Every change still passes a review before it's written or deployed.
{% endhint %}

## Where to go next

* [Audit Logging Coverage](https://triton.pharos.ai/instrumentation-skills/audit-logging.md) — the read-only map to run before you start.
* [Instrument Apex](https://triton.pharos.ai/instrumentation-skills/instrument-apex.md) · [Instrument LWC](https://triton.pharos.ai/instrumentation-skills/instrument-lwc.md) · [Instrument Flows](https://triton.pharos.ai/instrumentation-skills/instrument-flows.md) — the primitives this skill orchestrates.
* [Legacy Code Logging Rollout](https://triton.pharos.ai/triton-best-practices/legacy-migration.md) — the strategy the phasing is built on.
* [The Triton Instrumentation Agent](https://triton.pharos.ai/instrumentation-skills/instrumentation-agent.md) — package this behind a persona for a "point at an org" experience.
* [Set Up Standards](https://triton.pharos.ai/instrumentation-skills/setup-standards.md) — lock in CI guardrails so instrumented code stays instrumented.
