> 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/tritonutils.md).

# TritonUtils

## Overview

The `tritonUtils` module provides utility functions for stack-trace analysis, transaction ID generation, and runtime information capture. Import the named exports you need:

{% code lineNumbers="true" %}

```javascript
import { isNotTriton, generateTransactionId, captureRuntimeInfo, getFunctionName } from 'c/tritonUtils';
```

{% endcode %}

## Stack Trace Analysis

### isNotTriton(stackTraceLine)

* **Description**: Checks whether a stack-trace line is **not** from an internal Triton file or method — used to filter Triton frames out of captured stacks.
* **Parameters**:
  * `stackTraceLine`: `{string}` Line from a stack trace
* **Returns**: `{boolean}` `true` if the line is not from Triton internals
* **Example**:

{% code lineNumbers="true" %}

```javascript
const isUserCode = isNotTriton('at MyComponent.handleClick (/modules/c/myComponent.js:15:10)');
```

{% endcode %}

### getFunctionName(stackTraceLine)

* **Description**: Extracts the function name from a stack-trace line.
* **Parameters**:
  * `stackTraceLine`: `{string}` Line from a stack trace
* **Returns**: `{string}` The function name, or an empty string if none is found
* **Example**:

{% code lineNumbers="true" %}

```javascript
const fn = getFunctionName('at MyComponent.handleClick (/modules/c/myComponent.js:15:10)');
// Returns: "MyComponent.handleClick"
```

{% endcode %}

## Transaction Management

### generateTransactionId()

* **Description**: Generates a UUID v4 (random UUID). Used for transaction and span IDs.
* **Returns**: `{string}` A UUID in the format `xxxxxxxx-xxxx-4xxx-yxxx-xxxxxxxxxxxx`
* **Example**:

{% code lineNumbers="true" %}

```javascript
const transactionId = generateTransactionId(); // e.g. "550e8400-e29b-41d4-a716-446655440000"
```

{% endcode %}

## Runtime Information

### captureRuntimeInfo()

* **Description**: Captures comprehensive runtime information about the current environment. Each capture group is wrapped in try/catch so a failure in one area never blocks the others.
* **Returns**: `{Object}` Object containing environment, viewport, theme, performance, memory, network, and device details
* **Example**:

{% code lineNumbers="true" %}

```javascript
const runtimeInfo = captureRuntimeInfo();
console.log(runtimeInfo.viewportWidth); // e.g. 1920
console.log(runtimeInfo.platform);      // e.g. "Windows"
```

{% endcode %}

The returned object includes:

{% code lineNumbers="true" %}

```javascript
{
    // Environment
    userAgent, language, platform, mobile, brands, theme,
    viewportWidth, viewportHeight,
    // Performance
    pageLoadTime, domInteractive, domContentLoaded, firstByte, serverTime,
    firstPaint, firstContentfulPaint,
    // Memory
    memoryUsage, memoryLimit,
    // Network
    connectionType, connectionSpeed, connectionRtt, saveData,
    pathname, hostname, isOnline,
    // Device
    formFactor, screenWidth, screenHeight, orientation
}
```

{% endcode %}
