Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Final Code State for MM23 Metrics Lab #12

Open
wants to merge 1 commit into
base: main
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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