Skip to content

Commit

Permalink
represents end state of metrics lab on second rough draft
Browse files Browse the repository at this point in the history
  • Loading branch information
4141done committed Feb 14, 2023
1 parent 50253ef commit e52c785
Show file tree
Hide file tree
Showing 5 changed files with 1,878 additions and 46 deletions.
38 changes: 33 additions & 5 deletions app/index.mjs
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@ import amqp from "amqplib";
import express from "express";
import Router from "express-promise-router";
import { query } from "./db/index.mjs";
import { trace } from "@opentelemetry/api";

/* =================
SERVER SETUP
Expand Down Expand Up @@ -49,6 +50,7 @@ async function main() {
}

export async function handleMessageConsume(channel, msg, handlers) {
console.log("RABBIT_MQ_MESSAGE: ", msg);
if (msg !== null) {
const handler = handlers[msg.properties.type];

Expand Down Expand Up @@ -87,11 +89,37 @@ export async function handleNewMessageEvent(messageContent) {
);
return;
}
for (let pref of preferences) {
console.log(
`Sending notification of new message via ${pref.address_type} to ${pref.address}`
);
}

const tracer = trace.getTracer("notifier");
tracer.startActiveSpan(
"notification.send_all",
{
attributes: {
user_id: msg.user_id,
},
},
(parentSpan) => {
for (let pref of preferences) {
tracer.startActiveSpan(
"notification.send",
{
attributes: {
notification_type: pref.address_type,
user_id: pref.user_id,
},
},
(span) => {
console.log(
`Sending notification of new message via ${pref.address_type} to ${pref.address}`
);
span.end();
}
);
}

parentSpan.end();
}
);
}

/* =================
Expand Down
Loading

0 comments on commit e52c785

Please sign in to comment.