Skip to content

chore: add new websocket event handling#1108

Draft
Todai88 wants to merge 1 commit intomasterfrom
feat/add-client-lifecycle-metrics
Draft

chore: add new websocket event handling#1108
Todai88 wants to merge 1 commit intomasterfrom
feat/add-client-lifecycle-metrics

Conversation

@Todai88
Copy link
Copy Markdown
Contributor

@Todai88 Todai88 commented Apr 14, 2026

The purpose of this change is to improve our overall telemetry surface.

The new metric has a human-readable event as a label, rather than the "raw" websocket event. This hopefully makes it clearer for our downstream users what's specifically going on.

Compare "closing" to "server_requested_close".

Also:

  • renames the closeHandler to reportWebSocketClosureEvent - this is much closer to what we actually are doing. The code isn't handling any events.
  • implements the reportWebSocketClosureEvent function to emit new telemetry
  • adds tests to ensure existing and current functionality continues working

@snyk-io
Copy link
Copy Markdown
Contributor

snyk-io bot commented Apr 14, 2026

Snyk checks have passed. No issues have been found so far.

Status Scan Engine Critical High Medium Low Total (0)
Open Source Security 0 0 0 0 0 issues
Licenses 0 0 0 0 0 issues

💻 Catch issues earlier using the plugins for VS Code, JetBrains IDEs, Visual Studio, and Eclipse.

@snyk-io
Copy link
Copy Markdown
Contributor

snyk-io bot commented Apr 14, 2026

Snyk checks have passed. No issues have been found so far.

Status Scan Engine Critical High Medium Low Total (0)
Open Source Security 0 0 0 0 0 issues
Licenses 0 0 0 0 0 issues
Code Security 0 0 0 0 0 issues

💻 Catch issues earlier using the plugins for VS Code, JetBrains IDEs, Visual Studio, and Eclipse.

@Todai88 Todai88 force-pushed the feat/add-client-lifecycle-metrics branch 4 times, most recently from 76b75d9 to 649200c Compare April 14, 2026 14:46
openHandler(websocket, localClientOps, identifyingMetadata, metricsClient),
);
websocket.on('open', () => {
openHandler(websocket, localClientOps, identifyingMetadata, metricsClient);
Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Is it intentional that the open event is not considered a lifecycle event?

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

We should standardise on lifecycleEvent, but the openHandler already emits other connection-related metrics.


websocket.on('close', () => {
closeHandler(websocket, localClientOps, identifyingMetadata, metricsClient);
reportWebSocketClosureEvent(websocket, localClientOps, identifyingMetadata, metricsClient, 'connection_lost');
Copy link
Copy Markdown
Contributor

@mikedevelops mikedevelops Apr 14, 2026

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

How did we get to these human readable names? Are we introducing a layer of confusion by not sticking with the events the websocket client uses? They already seem pretty human readable to me...

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Unfortunately, some of the events can be slightly misleading.
Like closing -- one could be excused if one believed it was emitted as a "client is intending to close", but it's actually an event emitted by the server ahead of actually closing the connection.

The purpose of this change is to improve our overall telemetry surface.

The new metric has a human-readable event as a label, rather than the
"raw" websocket event. This hopefully makes it clearer for our
downstream users what's specifically going on.

Compare "closing" to "server_requested_close".

Also:
- renames the closeHandler to reportWebSocketClosureEvent - this is much closer
to what we actually are doing. The code isn't handling any events.
- implements the reportWebSocketClosureEvent function to emit new telemetry
- adds tests to ensure existing and current functionality continues working
@Todai88 Todai88 force-pushed the feat/add-client-lifecycle-metrics branch from 649200c to 2e285df Compare April 14, 2026 20:31
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants