feat(observability): instrument event and websocket handlers with OTEL#661
Merged
Merged
Conversation
…L metrics Signed-off-by: ABHAY PANDEY <pandeyabhay967@gmail.com>
🦋 Changeset detectedLatest commit: cb768e6 The changes in this PR will be included in the next version bump. This PR includes changesets to release 1 package
Not sure what this means? Click here to learn what changesets are. Click here if you're a maintainer who wants to add another changeset to this PR |
Collaborator
There was a problem hiding this comment.
Pull request overview
Adds OpenTelemetry metric instrumentation to key relay “event publish” OK responses and WebSocket connection lifecycle, building on the existing OTEL metrics bootstrap.
Changes:
- Introduces a telemetry helper to increment accepted/rejected event counters and to track active WebSocket connections.
- Routes event OK responses across event strategies and the main event handler through the new telemetry helper.
- Emits WebSocket connection open/close metrics from the WebSocket adapter.
Reviewed changes
Copilot reviewed 13 out of 13 changed files in this pull request and generated 3 comments.
Show a summary per file
| File | Description |
|---|---|
| src/telemetry/event-metrics.ts | Adds helpers to increment event accepted/rejected counters and WebSocket connection up/down counter. |
| src/handlers/event-strategies/vanish-event-strategy.ts | Switches OK responses to telemetry-wrapped command result. |
| src/handlers/event-strategies/timestamp-event-strategy.ts | Switches accept/reject OK responses to telemetry-wrapped command result. |
| src/handlers/event-strategies/replaceable-event-strategy.ts | Switches OK responses to telemetry-wrapped command result (incl. rejection path). |
| src/handlers/event-strategies/parameterized-replaceable-event-strategy.ts | Switches OK responses to telemetry-wrapped command result. |
| src/handlers/event-strategies/group-event-strategy.ts | Switches accept/reject OK responses to telemetry-wrapped command result. |
| src/handlers/event-strategies/gift-wrap-event-strategy.ts | Switches accept/reject OK responses to telemetry-wrapped command result. |
| src/handlers/event-strategies/ephemeral-event-strategy.ts | Switches OK response to telemetry-wrapped command result. |
| src/handlers/event-strategies/delete-event-strategy.ts | Switches OK response to telemetry-wrapped command result. |
| src/handlers/event-strategies/default-event-strategy.ts | Switches OK response to telemetry-wrapped command result. |
| src/handlers/event-message-handler.ts | Switches all rejection OK responses to telemetry-wrapped command result; minor formatting change in recursion guard. |
| src/adapters/web-socket-adapter.ts | Emits connection open/close metrics on connect/close. |
| .changeset/admin-metrics-handler-instrumentation.md | Declares a minor release for the instrumentation feature. |
💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.
| } | ||
|
|
||
| this.webSocket.emit(WebSocketAdapterEvent.Message, createCommandResult(event.id, false, 'error: ')) | ||
| this.webSocket.emit(WebSocketAdapterEvent.Message, createEventCommandResult(event.id, false, 'error: ')) |
Comment on lines
+17
to
+23
| export const recordWebsocketConnectionOpened = (): void => { | ||
| getRelayMetricInstruments().websocketConnections.add(1) | ||
| } | ||
|
|
||
| export const recordWebsocketConnectionClosed = (): void => { | ||
| getRelayMetricInstruments().websocketConnections.add(-1) | ||
| } |
Comment on lines
34
to
67
| @@ -63,13 +63,13 @@ export class EventMessageHandler implements IMessageHandler { | |||
| let reason = await this.isEventValid(event) | |||
| if (reason) { | |||
| logger('event %s rejected: %s', event.id, reason) | |||
| this.webSocket.emit(WebSocketAdapterEvent.Message, createCommandResult(event.id, false, reason)) | |||
| this.webSocket.emit(WebSocketAdapterEvent.Message, createEventCommandResult(event.id, false, reason)) | |||
| return | |||
cameri
approved these changes
Jul 5, 2026
Owner
|
thank you! |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Description
Wire OpenTelemetry counters into event publish paths and WebSocket lifecycle.
createEventCommandResult(NIP-20 OK unchanged)Related Issue
Fixes - #654
Motivation and Context
How Has This Been Tested?
Screenshots (if appropriate):
Types of changes
Checklist: