Component timings as span
```
--------------------------------
### Observe Agent Events
Source: https://github.com/elastic/apm-agent-rum-js/blob/main/docs/reference/agent-api.md
Use this method to listen for RUM agent internal events, such as transaction start and end. The callback function receives the transaction object, which can be modified.
```javascript
apm.observe(name, callback)
```
```javascript
apm.observe('transaction:start', function (transaction) {
if (transaction.type === 'custom') {
transaction.name = window.document.title
transaction.addLabels({ 'custom-label': 'custom-value' })
}
})
```
--------------------------------
### Mark Transaction Point with transaction.mark(key)
Source: https://github.com/elastic/apm-agent-rum-js/blob/main/docs/reference/transaction-api.md
Marks the current point in time relative to the start of the transaction. Use this method to mark significant events that happen while the transaction is active. Special characters in the key will be replaced by underscores.
```javascript
transaction.mark(key)
```
--------------------------------
### Get and Block Active Transaction
Source: https://github.com/elastic/apm-agent-rum-js/blob/main/docs/reference/transaction-api.md
Retrieves the current active transaction and blocks it from automatic closure. This is useful when dealing with uninstrumented asynchronous tasks. Remember to unblock the transaction when these tasks are complete.
```javascript
// get the current active autoinstrumented transaction (page-load, route-change, etc.)
const activeTransaction = apm.getCurrentTransaction()
if (activeTransaction) {
activeTransaction.block(true)
}
// Perform some more async tasks and unblock it
activeTransaction.block(false)
```
--------------------------------
### transaction.block
Source: https://github.com/elastic/apm-agent-rum-js/blob/main/docs/reference/transaction-api.md
Blocks the currently running auto-instrumented or custom transactions from getting automatically closed once the associated spans are ended. This is useful when auto-instrumented code misses important activity.
```APIDOC
## `transaction.block(flag)`
### Description
Blocks the currently running auto-instrumented or custom transactions from getting automatically closed once the associated spans are ended.
### Arguments
* `flag` - Boolean. Defaults to false.
### Request Example
```js
// get the current active autoinstrumented transaction (page-load, route-change, etc.)
const activeTransaction = apm.getCurrentTransaction()
if (activeTransaction) {
activeTransaction.block(true)
}
// Perform some more async tasks and unblock it
activeTransaction.block(false)
```
```
--------------------------------
### apm.init([config])
Source: https://github.com/elastic/apm-agent-rum-js/blob/main/docs/reference/agent-api.md
Initializes the agent with the given configuration and returns itself. It registers global listeners for errors and page load metrics.
```APIDOC
## apm.init([config])
Initializes the agent with the given configuration and returns itself. Under the hood, init does the following:
* Registers a global `error` listener to track JavaScript errors on the page.
* Adds a `onload` event listener to collect the page load metrics.
When the agent is inactive, both `error` and `onload` listeners will not be registered on the page.
Both XHR and Fetch API are patched as soon as the agent script is executed on the page and does not get changed even if the agent is inactive. The reason is to allow users to initialize the agent asynchronously on the page.
```
--------------------------------
### Manually Release Artifacts to GitHub
Source: https://github.com/elastic/apm-agent-rum-js/blob/main/RELEASE.md
Execute this command in the root directory to package and create a GitHub release for '@elastic/apm-rum' using the previous annotated tag. Ensure GITHUB_TOKEN with push access is set.
```bash
npm run github-release
```
--------------------------------
### Initialize RUM Agent with Trace Context
Source: https://github.com/elastic/apm-agent-rum-js/blob/main/docs/reference/distributed-tracing.md
Use this when your backend service generates HTML dynamically. Inject the trace ID, parent span ID, and sampled status to ensure the page load is the root of the trace. Refer to your backend agent's API for methods to extract this information.
```javascript
var apm = initApm({
...
pageLoadTraceId: