remove spans

This commit is contained in:
Luke Berndt
2024-02-06 07:59:44 -05:00
parent c0a81f82f8
commit d44638e32f
2 changed files with 154 additions and 173 deletions

View File

@@ -70,16 +70,15 @@ exports.upload = async function (req, res, next) {
} }
let item = null; let item = null;
const ctx = propagation.setBaggage( const span = opentelemetry.trace.getActiveSpan();
context.active(), span.setAttribute('call.shortName', shortName);
propagation.createBaggage({ span.setAttribute('call.talkgroupNum', talkgroupNum);
for_the_children: { shortName: shortName, talkgroupNum: talkgroupNum, startTime: startTime }, span.setAttribute('call.startTime', startTime);
}),
);
// Validate that the system exists and the API key is correct // Validate that the system exists and the API key is correct
context.with(ctx, () => {
tracer.startActiveSpan('validate-system', async (span) => {
try { try {
item = await System.findOne({ 'shortName': shortName }, ["key", "ignoreUnknownTalkgroup"]); item = await System.findOne({ 'shortName': shortName }, ["key", "ignoreUnknownTalkgroup"]);
} catch (err) { } catch (err) {
@@ -90,7 +89,6 @@ exports.upload = async function (req, res, next) {
console.warn("[" + req.params.shortName + "] Error /:shortName/upload - Error: " + err); console.warn("[" + req.params.shortName + "] Error /:shortName/upload - Error: " + err);
res.status(500); res.status(500);
res.send("Error, invalid shortName:\n" + err); res.send("Error, invalid shortName:\n" + err);
span.end();
return; return;
} }
@@ -102,7 +100,6 @@ exports.upload = async function (req, res, next) {
console.info("[" + req.params.shortName + "] Error /:shortName/upload ShortName does not exist"); console.info("[" + req.params.shortName + "] Error /:shortName/upload ShortName does not exist");
res.status(500); res.status(500);
res.send("ShortName does not exist: " + shortName + "\n"); res.send("ShortName does not exist: " + shortName + "\n");
span.end();
return; return;
} }
if (apiKey != item.key) { if (apiKey != item.key) {
@@ -113,7 +110,6 @@ exports.upload = async function (req, res, next) {
console.warn("[" + req.params.shortName + "] Error /:shortName/upload API Key Mismatch - Provided key: " + apiKey); console.warn("[" + req.params.shortName + "] Error /:shortName/upload API Key Mismatch - Provided key: " + apiKey);
res.status(500); res.status(500);
res.send("API Keys do not match!\n"); res.send("API Keys do not match!\n");
span.end();
return; return;
} }
@@ -124,7 +120,6 @@ exports.upload = async function (req, res, next) {
message: "Sensitive Talkgroup", message: "Sensitive Talkgroup",
}); });
res.status(200).end(); res.status(200).end();
span.end();
return; return;
} }
@@ -148,7 +143,7 @@ exports.upload = async function (req, res, next) {
code: opentelemetry.SpanStatusCode.ERROR, code: opentelemetry.SpanStatusCode.ERROR,
message: "Ignore Unknown Talkgroup Set - Talkgroup does not exist: " + talkgroupNum + " ShortName: " + shortName, message: "Ignore Unknown Talkgroup Set - Talkgroup does not exist: " + talkgroupNum + " ShortName: " + shortName,
}); });
span.end();
return; return;
} }
} }
@@ -157,9 +152,7 @@ exports.upload = async function (req, res, next) {
res.status(200).end(); res.status(200).end();
span.end();
});
});
var local_path = "/" + shortName + "/" + time.getFullYear() + "/" + (time.getMonth() + 1) + "/" + time.getDate() + "/"; var local_path = "/" + shortName + "/" + time.getFullYear() + "/" + (time.getMonth() + 1) + "/" + time.getDate() + "/";
var object_key = "media/" + shortName + "-" + talkgroupNum + "-" + startTime + path.extname(req.file.originalname); var object_key = "media/" + shortName + "-" + talkgroupNum + "-" + startTime + path.extname(req.file.originalname);
@@ -186,9 +179,7 @@ exports.upload = async function (req, res, next) {
len: -1 len: -1
}); });
// Upload the file to S3
context.with(ctx, () => {
tracer.startActiveSpan('upload-call', async (span) => {
try { try {
if (req.body.call_length) { if (req.body.call_length) {
call.len = parseFloat(req.body.call_length); call.len = parseFloat(req.body.call_length);
@@ -207,7 +198,6 @@ exports.upload = async function (req, res, next) {
code: opentelemetry.SpanStatusCode.ERROR, code: opentelemetry.SpanStatusCode.ERROR,
message: "Unable to open file: " + req.file.path + " Error: " + err, message: "Unable to open file: " + req.file.path + " Error: " + err,
}); });
span.end();
console.error("[" + call.shortName + "] Unable to open file: " + req.file.path + " Error: " + err); console.error("[" + call.shortName + "] Unable to open file: " + req.file.path + " Error: " + err);
return; return;
} }
@@ -236,13 +226,7 @@ exports.upload = async function (req, res, next) {
error: "File Upload" error: "File Upload"
}));*/ }));*/
} }
span.end();
});
});
// Save Call to the database
context.with(ctx, () => {
tracer.startActiveSpan('save-call', async (span) => {
try { try {
await call.save(); await call.save();
sysStats.addCall(call.toObject()); sysStats.addCall(call.toObject());
@@ -272,12 +256,5 @@ exports.upload = async function (req, res, next) {
} catch (err) { } catch (err) {
console.warn("There was an Error uploading an deleting: " + req.file.path); console.warn("There was an Error uploading an deleting: " + req.file.path);
}; };
span.end();
}); });
});
});
} }

View File

@@ -33,6 +33,10 @@ services:
- ${PWD}/data/certbot/www/:/var/www/certbot/:rw - ${PWD}/data/certbot/www/:/var/www/certbot/:rw
- ${PWD}/data/certbot/conf/:/etc/letsencrypt/:rw - ${PWD}/data/certbot/conf/:/etc/letsencrypt/:rw
entrypoint: "/bin/sh -c 'trap exit TERM; while :; do certbot renew; sleep 12h & wait $${!}; done;'" entrypoint: "/bin/sh -c 'trap exit TERM; while :; do certbot renew; sleep 12h & wait $${!}; done;'"
logging:
driver: syslog
options:
tag: "mongo"
mongo: mongo:
build: build: