diff --git a/index.ts b/index.ts index 3b543f5..46bfb69 100644 --- a/index.ts +++ b/index.ts @@ -65,7 +65,8 @@ Bun.serve<{key: string}>({ } // Get data from Substreams metadata const { clock, manifest, session } = json; - const moduleHash = manifest?.moduleHash; + const { moduleHash } = manifest; + const { traceId } = session; // publish message to subscribers const bytes = server.publish(moduleHash, body); @@ -81,20 +82,12 @@ Bun.serve<{key: string}>({ prometheus.published_messages.inc(1); } // Metrics for incoming WebHook - prometheus.webhook_module_hash.labels({moduleHash}).inc(1); - prometheus.webhook_messages.inc(1); - - //Metrics for trace id - const traceId = session.traceId; - const traceTimestamp = session.timestamp; - console.log(traceId, traceTimestamp) - if (traceId) { - prometheus.trace_id.inc(1); - } + prometheus.webhook_messages.labels({moduleHash}).inc(1); + prometheus.trace_id.labels({traceId}).inc(1); // Upsert moduleHash into SQLite DB sqlite.replace(db, "moduleHash", moduleHash, timestamp); - sqlite.replace(db, "traceId", traceId, traceTimestamp); + sqlite.replace(db, "traceId", traceId, timestamp); return new Response("OK"); } diff --git a/src/prometheus.ts b/src/prometheus.ts index ef3b0b6..6177a6b 100644 --- a/src/prometheus.ts +++ b/src/prometheus.ts @@ -28,8 +28,8 @@ export async function getSingleMetric(name: string) { } // Webhook metrics -export const webhook_messages = registerCounter('webhook_messages', 'Total Webhook messages received'); -export const webhook_module_hash = registerCounter('webhook_module_hash', 'Total Webhook module hashes message received', ['moduleHash']); +export const webhook_messages = registerCounter('webhook_messages', 'Total Webhook messages received', ['moduleHash']); +export const trace_id = registerGauge('trace_id', 'Total trace ids', ['traceId']); // WebSocket metrics export const active_connections = registerGauge('active_connections', 'All active connections'); @@ -37,5 +37,4 @@ export const connected = registerCounter('connected', 'Total connected clients') export const published_messages = registerCounter('published_messages', 'Total published messages'); export const bytes_published = registerCounter('bytes_published', 'Total bytes published'); export const disconnects = registerCounter('disconnects', 'Total disconnects'); -export const total_pings = registerCounter('total_pings', 'Total pings'); -export const trace_id = registerGauge('trace_id', 'Total trace ids') \ No newline at end of file +export const total_pings = registerCounter('total_pings', 'Total pings'); \ No newline at end of file