# WebSocketInstrumentationConfig

**Kind**: interface | **Module**: [Insights](https://docs.interop.io/browser/reference/javascript/insights/index.md)

**Source**: https://docs.interop.io/browser/reference/javascript/insights/websocketinstrumentationconfig/index.html

Configuration for the WebSocket instrumentation.

## Properties

- **`bytesMetric`** (`boolean | string | null`, optional) default: `false`
  If `true` or a string, a counter summing WebSocket payload bytes is published
  ("io.insights.websocket.bytes" unless a string names it), tagged with
  direction ("send" / "receive") and server.address/server.port.
- **`connectDurationMetric`** (`boolean | string | null`, optional) default: `false`
  If `true` or a string, the connection establishment time (construction until
  the open event) is published as a histogram metric
  ("io.insights.websocket.connect.duration" unless a string names it).
  Successful connections only.
- **`connectDurationMetricBuckets`** (`number[]`, optional) default: `[0.01, 0.025, 0.05, 0.1, 0.25, 0.5, 1, 2.5, 5, 10]`
  Explicit histogram bucket boundaries for connectDurationMetric, in seconds, ascending.
- **`enabled`** (`boolean`, required)
  Whether the WebSocket instrumentation is enabled.
- **`ignoreGateway`** (`boolean`, optional) default: `false`
  If `true`, the io.Connect gateway connection is excluded from instrumentation.
  By default the gateway socket IS tracked: its connection lifecycle (connects,
  drops, close codes, reconnect attempts) is core platform-health telemetry. The
  gateway is recognized via the platform-provided connection URL
  (window.glue42gd.gwURL, compared by origin and path); where that is unavailable
  the flag has no effect - use ignorePattern to exclude infrastructure sockets
  explicitly.

  A second socket to the gateway - to that URL, or handed over by the io.Connect
  API itself - is a reconnect: its spans carry `reconnect: true` and start a trace
  of their own, linked to the span they would have nested under (`linkToParent`),
  so that a reconnect at shutdown does not stretch the trace the first connection
  was made in - the platform's startup - to the end of the session.

  Cost note: with the message/byte metrics enabled, the gateway socket
  contributes a sample per gateway message - volume that describes io.Connect
  itself rather than the application. Enable those metrics deliberately, or set
  this flag to exclude the gateway.

  Sockets explicitly handed to the pre-init recorder via its trackWebSocket hook
  (e.g. the core-js gateway transport handing over its own connection) bypass
  this flag even when set - explicit handover is a deliberate opt-in.
  ignorePattern still applies to them and remains the veto.
- **`ignorePattern`** (`string`, optional)
  Optional regex pattern for WebSocket URLs that should be excluded from
  instrumentation - e.g. infrastructure sockets beyond the gateway connection
  (which can be excluded using ignoreGateway).
- **`matchPattern`** (`string`, optional)
  Optional regex pattern; if specified, only matching WebSocket URLs are
  instrumented.
- **`messagesMetric`** (`boolean | string | null`, optional) default: `false`
  If `true` or a string, a counter of WebSocket messages is published
  ("io.insights.websocket.messages" unless a string names it), tagged with
  direction ("send" / "receive") and server.address/server.port.
- **`platform`** (`boolean`, optional) default: `false`
  If `true`, the io.Connect Desktop platform also tracks its OWN main-process
  WebSocket connections - most importantly its gateway connection, which is
  created before the platform's io.Insights initializes: the platform's
  bootstrap installs the pre-init recorder (with WebSocket tracking enabled)
  early enough that the connection is observed from construction, and the
  platform's io.Insights instance adopts it at initialization. Read by the
  platform's bootstrap; has no effect outside the platform process.
- **`preInit`** (`boolean`, optional) default: `true`
  Unless `false`, the pre-init recorder (installEarlyInstrumentation from
- **`trace`** (`boolean`, optional) default: `true`
  If `true` (the default), each WebSocket connection that opens is published as a
  span ("interopio.api.instrumentation.webSocket.lifetime") covering construction
  until close - created at the open, backdated to the construction - with
  connectMs, the negotiated protocol, close code/reason/wasClean, message and
  byte totals in both directions, and the connection duration. Abnormal closures
  (1006) mark the span as ERROR.

  The handshake of each connection is a span of its own besides,
  "interopio.api.instrumentation.webSocket.connect": from the construction to the
  open event, with connectMs, the negotiated protocol and extensions. A connection
  that never opens ends it at its close, with ERROR and the close code - and it is
  the only span then: the failure is the handshake's, and there was no lifetime. It
  is published where the socket was opened - under the current tracing state, like
  the lifetime span - and is exported at the open, where the wait happened: the
  lifetime span is exported at the close, which for a long-lived connection (the
  gateway's) is far away, or never. The two point at each other with span links
  (link attribute webSocket: "lifetime" / "connect"). Sockets tracked from page
  start by the pre-init recorder get theirs with the recorded times.

  If `false`, no spans are published - neither of the two - metrics-only mode: the
  message/byte counters and the connect-duration histogram keep reporting.
