> 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/methods-reference/lwc/tritonbuilder.md).

# TritonBuilder

## Overview

The `TritonBuilder` class implements a builder pattern for creating structured log entries in LWC and Aura components. It provides a fluent interface for setting log attributes and metadata. Obtain one from [`triton.makeBuilder()`](https://triton.pharos.ai/methods-reference/lwc/triton.md#makebuilder) or a level method, then chain attributes and pass it to `log()` / `logNow()`.

## Classification Methods

### level(level)

* **Description**: Sets the log level.
* **Parameters**:
  * `level`: `{string}` Log level from `LEVEL`
* **Returns**: `{TritonBuilder}` Builder instance for chaining

### category(category)

* **Description**: Sets the log category.
* **Parameters**:
  * `category`: `{string}` Log category from `CATEGORY`
* **Returns**: `{TritonBuilder}` Builder instance for chaining

### type(type)

* **Description**: Sets the log type.
* **Parameters**:
  * `type`: `{string}` Log type from `TYPE`
* **Returns**: `{TritonBuilder}` Builder instance for chaining

### area(area)

* **Description**: Sets the functional area. Pass an `AREA` constant or any string — reuse the area your Apex code uses, so the feature's logs group together. A custom string is kept as sent; leave the area unset and the log lands under `LWC`.
* **Parameters**:
  * `area`: `{string}` An `AREA` constant or a custom area
* **Returns**: `{TritonBuilder}` Builder instance for chaining

## Content Methods

### summary(summary)

* **Description**: Sets the log summary message.
* **Parameters**:
  * `summary`: `{string}` Brief description of the log entry
* **Returns**: `{TritonBuilder}` Builder instance for chaining

### details(details)

* **Description**: Sets detailed log information.
* **Parameters**:
  * `details`: `{string}` Detailed description or additional context
* **Returns**: `{TritonBuilder}` Builder instance for chaining

## Error Handling

### exception(error)

* **Description**: Sets the level to `ERROR` — so the server opens a Pharos issue, as Apex's `.exception(e)` does — and populates error message, stack, and type from a JavaScript `Error` (or an Apex error with a `body`), deriving component details from the stack. A `.level(...)` chained after it wins. A missing error (a promise rejected with no reason) only sets the level.
* **Parameters**:
  * `error`: `{Error|Object}` Error object to process
* **Returns**: `{TritonBuilder}` Builder instance for chaining

### componentDetails(stack)

* **Description**: Extracts the calling function name and cleaned stack trace from a stack string.
* **Parameters**:
  * `stack`: `{string}` Stack trace to process
* **Returns**: `{TritonBuilder}` Builder instance for chaining

## Metadata Methods

### transactionId(transactionId)

* **Description**: Sets the transaction ID for log correlation.
* **Parameters**:
  * `transactionId`: `{string}` Transaction identifier
* **Returns**: `{TritonBuilder}` Builder instance for chaining

### duration(duration)

* **Description**: Sets execution duration in milliseconds.
* **Parameters**:
  * `duration`: `{number}` Duration in milliseconds
* **Returns**: `{TritonBuilder}` Builder instance for chaining

### action(action)

* **Description**: Sets the action name — e.g. a performance mark, backend call, or user-interaction name.
* **Parameters**:
  * `action`: `{string}` Action name
* **Returns**: `{TritonBuilder}` Builder instance for chaining

### spanId(spanId)

* **Description**: Sets the span ID identifying this log's unit of work.
* **Parameters**:
  * `spanId`: `{string}` Span identifier
* **Returns**: `{TritonBuilder}` Builder instance for chaining

### parentSpanId(parentSpanId)

* **Description**: Sets the parent span ID, linking this log into a trace hierarchy.
* **Parameters**:
  * `parentSpanId`: `{string}` Parent span identifier
* **Returns**: `{TritonBuilder}` Builder instance for chaining

### timestamp(timestamp)

* **Description**: Sets the log creation timestamp.
* **Parameters**:
  * `timestamp`: `{number}` Unix timestamp (e.g. `Date.now()`)
* **Returns**: `{TritonBuilder}` Builder instance for chaining

### userId(userId)

* **Description**: Sets the user ID associated with the log.
* **Parameters**:
  * `userId`: `{string}` Salesforce user ID
* **Returns**: `{TritonBuilder}` Builder instance for chaining

### relatedObjects(objectIds)

* **Description**: Sets related object IDs. Accepts a single ID or an array; null/empty values are filtered out.
* **Parameters**:
  * `objectIds`: `{string|string[]}` One or more Salesforce record IDs
* **Returns**: `{TritonBuilder}` Builder instance for chaining

### runtimeInfo(info)

* **Description**: Sets runtime environment information (usually captured automatically via `captureRuntimeInfo()`).
* **Parameters**:
  * `info`: `{Object}` Runtime environment details
* **Returns**: `{TritonBuilder}` Builder instance for chaining

## Utility

### clone()

* **Description**: Creates a deep copy of the builder (used for component templates).
* **Returns**: `{TritonBuilder}` New builder instance with copied properties

### build()

* **Description**: Constructs the final log object from all set properties, ready to send to the server.
* **Returns**: `{Object}` Complete log object
* **Example**:

{% code lineNumbers="true" %}

```javascript
const logEntry = triton.makeBuilder()
    .level(LEVEL.INFO)
    .type(TYPE.FRONTEND)
    .summary('User action completed')
    .build();
```

{% endcode %}
