---
title: Automatically monitor your websockets
source: https://docs.newrelic.com/docs/browser/new-relic-browser/browser-pro-features/websockets
---

The [WebSocket API](https://developer.mozilla.org/en-US/docs/Web/API/WebSockets_API) allows opening a two-way interactive communication session between the user's browser and a server. This session allows sending and receiving data without polling for a server response. With New Relic browser monitoring, you can monitor and track the traffic and health of your websocket sessions.

Websockets data from the API are recorded as [WebSocket](https://docs.newrelic.com/attribute-dictionary/?dataSource=Browser+agent&event=WebSocket) events by the browser agent. These events include metrics about the connection, messages received, data sent, and how the connection was closed during the lifecycle of the websocket.

## Why use websockets monitoring?

Automatic tracking of websockets with New Relic provides the tools and insights into making sure your websockets work as expected. With `WebSocket` events, you can:

-   Monitor bytes sent and received of your network connections
-   Examine whether websockets close successfully or not and the reason as to why
-   Troubleshoot JavaScript errors that occur during the lifecycle of your websockets
-   Build custom dashboards and alerts based on websockets

## Prerequisites [#prerequisites]

-   A **Pro** or **Pro + SPA** browser agent, version 1.318.0 or higher.

> #### ⚠️ IMPORTANT
>
> Websockets monitoring is not available for the Lite browser agent.

## Enable automatic collection [#enable-collection]

Enhance your application's observability and debugging capabilities by following these simple setup instructions.

1.  Go to **[one.newrelic.com](https://one.newrelic.com) > All Capabilities > Browser**.
2.  Select your browser app.
3.  In the left-hand menu, click **Application settings**.
4.  Ensure the **Pro** or **Pro + SPA** browser agent is selected.
5.  Turn on **Enable websockets**.

![screenshot of the websockets settings panel in browser application settings](https://docs.newrelic.com/images/websockets-settings.webp "Websockets settings")

## Disable websockets collection [#disable-websockets]

To disable websockets for an existing browser app:

1.  Go to **[one.newrelic.com](https://one.newrelic.com) > All Capabilities > Browser**.
2.  Select your browser app.
3.  In the left-hand menu, click **Application settings**.
4.  To disable websockets, turn off **Enable websockets**.

## Data consumption

`WebSocket` events follow the same consumption pricing as your other browser bytes. The amount of bytes produced depends on the count and attributes of the data.

Once enabled, the agent will automatically capture websockets as they occur in your application.

## Find your data in New Relic [#find-data]

Websockets are stored as `WebSocket` events in New Relic. See the [data dictionary](https://docs.newrelic.com/attribute-dictionary/?dataSource=Browser+agent&event=WebSocket) for more information on the fields available for use with `WebSocket` events. For a quick and useful dashboard, see this [quickstart](https://newrelic.com/instant-observability/browser-web-sockets). You can query and visualize this data to gain insights into your application's performance:

**Measure total amount of websocket instances over time**

```nrql
FROM WebSocket
SELECT count(*)
TIMESERIES
```

**View reasons why websockets close unexpectedly**

```nrql
FROM WebSocket
SELECT count(*)
FACET closeReason
```

**Track websockets with errors**

```nrql
FROM WebSocket
SELECT count(*) AS 'Errors'
WHERE hasErrors IS true
TIMESERIES
```

**View average bytes sent and received**

```nrql
FROM WebSocket
SELECT average(sendBytes), average(messageBytes)
WHERE messageCount IS NOT null
TIMESERIES 
```

**Monitor websocket average duration**

```nrql
FROM WebSocket
SELECT average(connectedDuration)
FACET cases(
  WHERE closeWasClean IS true AS 'Connected - Clean',
  WHERE closeWasClean IS NOT true AS 'Connected - Dirty'
)
TIMESERIES
```

Use these queries or create your own to build custom dashboards, set up alerts, and monitor the real-world performance of your web applications with precision.

> #### 💡 TIP
>
> Need help or want to learn more about using websockets in New Relic? Visit our [documentation](https://docs.newrelic.com/) or reach out to [support.newrelic.com](https://support.newrelic.com).
