diff --git a/src/nostrMiddleware.ts b/src/nostrMiddleware.ts index 407783ff..f33d7c5c 100644 --- a/src/nostrMiddleware.ts +++ b/src/nostrMiddleware.ts @@ -10,7 +10,8 @@ export default (serverMethods: Types.ServerMethods, mainHandler: Main, nostrSett const app = await mainHandler.storage.applicationStorage.GetApplication(appId || "") let nostrUser = await mainHandler.storage.applicationStorage.GetOrCreateNostrAppUser(app, pub || "") return { user_id: nostrUser.user.user_id, app_user_id: nostrUser.identifier, app_id: appId || "" } - } + }, + metricsCallback: metrics => mainHandler.metricsManager.AddMetrics(metrics) }) const nostr = new Nostr(nostrSettings, event => { let j: NostrRequest @@ -22,7 +23,7 @@ export default (serverMethods: Types.ServerMethods, mainHandler: Main, nostrSett } nostrTransport({ ...j, appId: event.appId }, res => { nostr.Send(event.appId, { type: 'content', pub: event.pub, content: JSON.stringify({ ...res, requestId: j.requestId }) }) - }) + }, event.startAtNano) }) return { Stop: () => nostr.Stop, Send: (...args) => nostr.Send(...args) } } diff --git a/src/services/nostr/handler.ts b/src/services/nostr/handler.ts index a96c08a8..be4c8c54 100644 --- a/src/services/nostr/handler.ts +++ b/src/services/nostr/handler.ts @@ -16,6 +16,7 @@ export type NostrEvent = { pub: string content: string appId: string + startAtNano: bigint } type SettingsRequest = { type: 'settings' @@ -141,9 +142,10 @@ export default class Handler { return } handledEvents.push(eventId) + const startAtNano = process.hrtime.bigint() const decoded = decodePayload(e.content) const content = await decryptData(decoded, getSharedSecret(app.privateKey, e.pubkey)) - this.eventCallback({ id: eventId, content, pub: e.pubkey, appId: app.appId }) + this.eventCallback({ id: eventId, content, pub: e.pubkey, appId: app.appId, startAtNano }) })