Skip to content

Commit

Permalink
update traceId
Browse files Browse the repository at this point in the history
  • Loading branch information
DenisCarriere committed Oct 4, 2023
1 parent 76ffca4 commit 8c32443
Show file tree
Hide file tree
Showing 2 changed files with 8 additions and 16 deletions.
17 changes: 5 additions & 12 deletions index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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);
Expand All @@ -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");
}
Expand Down
7 changes: 3 additions & 4 deletions src/prometheus.ts
Original file line number Diff line number Diff line change
Expand Up @@ -28,14 +28,13 @@ 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');
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')
export const total_pings = registerCounter('total_pings', 'Total pings');

0 comments on commit 8c32443

Please sign in to comment.