mirror of
https://github.com/openmhz/trunk-server.git
synced 2026-11-12 08:47:40 -05:00
upgrading telem
This commit is contained in:
24
backend/agents/otel-tracing.js
Normal file
24
backend/agents/otel-tracing.js
Normal file
@@ -0,0 +1,24 @@
|
||||
'use strict';
|
||||
|
||||
const opentelemetry = require('@opentelemetry/sdk-node');
|
||||
const { TraceIdRatioBasedSampler } = require('@opentelemetry/sdk-trace-node');
|
||||
const { OTLPTraceExporter } = require('@opentelemetry/exporter-trace-otlp-http');
|
||||
const { getNodeAutoInstrumentations } = require('@opentelemetry/auto-instrumentations-node');
|
||||
|
||||
const samplePercentage = 0.05;
|
||||
|
||||
const sdk = new opentelemetry.NodeSDK({
|
||||
traceExporter: new OTLPTraceExporter(),
|
||||
sampler: new TraceIdRatioBasedSampler(samplePercentage),
|
||||
instrumentations: [
|
||||
getNodeAutoInstrumentations({
|
||||
// we recommend disabling fs autoinstrumentation since it can be noisy
|
||||
// and expensive during startup
|
||||
'@opentelemetry/instrumentation-fs': {
|
||||
enabled: false,
|
||||
},
|
||||
}),
|
||||
],
|
||||
});
|
||||
|
||||
sdk.start();
|
||||
@@ -36,7 +36,7 @@ const client = new S3Client({
|
||||
|
||||
exports.upload = async function (req, res, next) {
|
||||
const parentSpan = trace.getActiveSpan();
|
||||
await trace.getTracer('upload-service').startActiveSpan('upload_handler', async (span) => {
|
||||
await trace.getTracer('upload-service').startActiveSpan('upload_handler', { parent: parentSpan }, async (span) => {
|
||||
try {
|
||||
span.setAttribute('call.shortName', req.params.shortName.toLowerCase());
|
||||
span.setAttribute('call.talkgroup_num', req.body.talkgroup_num);
|
||||
@@ -93,9 +93,9 @@ exports.upload = async function (req, res, next) {
|
||||
let item = null;
|
||||
|
||||
|
||||
console.log("Finished parsing request data");
|
||||
// Validate that the system exists and the API key is correct
|
||||
|
||||
await trace.getTracer('upload-service').startActiveSpan('validate_system', async (validateSpan) => {
|
||||
await trace.getTracer('upload-service').startActiveSpan('validate_system', { parent: span }, async (validateSpan) => {
|
||||
|
||||
try {
|
||||
item = await System.findOne({ 'shortName': shortName }, ["key", "ignoreUnknownTalkgroup"]);
|
||||
@@ -136,22 +136,25 @@ exports.upload = async function (req, res, next) {
|
||||
}
|
||||
});
|
||||
|
||||
console.log("Finished validating system API key");
|
||||
// Blocking sensitive talkgroups
|
||||
await trace.getTracer('upload-service').startActiveSpan('check_sensitive_talkgroups', async (sensitiveSpan) => {
|
||||
await trace.getTracer('upload-service').startActiveSpan('check_sensitive_talkgroups', { parent: span }, async (sensitiveSpan) => {
|
||||
|
||||
if ((shortName == "hennearmer") && ((talkgroupNum == 3421) || (talkgroupNum == 3423))) {
|
||||
sensitiveSpan.setStatus({
|
||||
code: opentelemetry.SpanStatusCode.ERROR,
|
||||
message: "Sensitive Talkgroup",
|
||||
});
|
||||
res.status(200).end();
|
||||
//res.status(200).end();
|
||||
return;
|
||||
}
|
||||
sensitiveSpan.end();
|
||||
});
|
||||
|
||||
console.log("Finished checking sensitive talkgroups");
|
||||
|
||||
if (item.ignoreUnknownTalkgroup == true) {
|
||||
await trace.getTracer('upload-service').startActiveSpan('check_talkgroup_exists', async (talkgroupSpan) => {
|
||||
await trace.getTracer('upload-service').startActiveSpan('check_talkgroup_exists', { parent: span }, async (talkgroupSpan) => {
|
||||
|
||||
talkgroupExists = await Talkgroup.exists({
|
||||
'shortName': shortName,
|
||||
@@ -176,15 +179,15 @@ exports.upload = async function (req, res, next) {
|
||||
talkgroupSpan.end();
|
||||
});
|
||||
}
|
||||
// Add in an API Key check
|
||||
|
||||
console.log("Finished checking talkgroup exists");
|
||||
|
||||
|
||||
|
||||
res.status(200).end();
|
||||
|
||||
|
||||
// Prepare call object
|
||||
let call;
|
||||
await trace.getTracer('upload-service').startActiveSpan('prepare_call_object', async (prepareSpan) => {
|
||||
await trace.getTracer('upload-service').startActiveSpan('prepare_call_object', { parent: span }, async (prepareSpan) => {
|
||||
|
||||
var local_path = "/" + shortName + "/" + time.getFullYear() + "/" + (time.getMonth() + 1) + "/" + time.getDate() + "/";
|
||||
var object_key = "media/" + shortName + "-" + talkgroupNum + "-" + startTime + path.extname(req.file.originalname);
|
||||
@@ -226,9 +229,10 @@ exports.upload = async function (req, res, next) {
|
||||
prepareSpan.end();
|
||||
});
|
||||
|
||||
console.log("Finished preparing call object");
|
||||
let fileContent;
|
||||
// Upload file to S3
|
||||
await trace.getTracer('upload-service').startActiveSpan('upload_to_s3', async (uploadSpan) => {
|
||||
await trace.getTracer('upload-service').startActiveSpan('upload_to_s3',{ parent: span }, async (uploadSpan) => {
|
||||
|
||||
try {
|
||||
fileContent = fs.readFileSync(req.file.path);
|
||||
@@ -257,8 +261,9 @@ exports.upload = async function (req, res, next) {
|
||||
}
|
||||
});
|
||||
|
||||
console.log("Finished uploading to S3");
|
||||
// Save call to database
|
||||
await trace.getTracer('upload-service').startActiveSpan('save_call', async (saveSpan) => {
|
||||
await trace.getTracer('upload-service').startActiveSpan('save_call',{ parent: span }, async (saveSpan) => {
|
||||
try {
|
||||
await call.save();
|
||||
sysStats.addCall(call.toObject());
|
||||
@@ -278,8 +283,10 @@ exports.upload = async function (req, res, next) {
|
||||
saveSpan.end();
|
||||
}
|
||||
});
|
||||
|
||||
console.log("Finished saving call to database");
|
||||
// Clean up temporary file
|
||||
await trace.getTracer('upload-service').startActiveSpan('cleanup_temp_file', async (cleanupSpan) => {
|
||||
await trace.getTracer('upload-service').startActiveSpan('cleanup_temp_file',{ parent: span }, async (cleanupSpan) => {
|
||||
try {
|
||||
fs.unlinkSync(req.file.path);
|
||||
cleanupSpan.setAttribute('file.deleted', true);
|
||||
@@ -300,5 +307,7 @@ exports.upload = async function (req, res, next) {
|
||||
} finally {
|
||||
span.end();
|
||||
}
|
||||
|
||||
console.log("Finished processing call upload");
|
||||
});
|
||||
};
|
||||
|
||||
@@ -1,4 +1,4 @@
|
||||
const tracing = require("./agents/honeycomb-tracing");
|
||||
const tracing = require("./agents/otel-tracing");
|
||||
var express = require("express");
|
||||
var configureExpress = require("./config/express");
|
||||
|
||||
|
||||
22
backend/package-lock.json
generated
22
backend/package-lock.json
generated
@@ -14,7 +14,7 @@
|
||||
"@aws-sdk/credential-providers": "^3.309.0",
|
||||
"@honeycombio/opentelemetry-node": "^0.6.1",
|
||||
"@opentelemetry/api": "^1.7.0",
|
||||
"@opentelemetry/auto-instrumentations-node": "^0.41.0",
|
||||
"@opentelemetry/auto-instrumentations-node": "^0.41.1",
|
||||
"@smithy/node-http-handler": "^3.1.4",
|
||||
"adm-zip": "^0.5.10",
|
||||
"aws-sdk": "^2.1353",
|
||||
@@ -1580,14 +1580,14 @@
|
||||
}
|
||||
},
|
||||
"node_modules/@opentelemetry/auto-instrumentations-node": {
|
||||
"version": "0.41.0",
|
||||
"resolved": "https://registry.npmjs.org/@opentelemetry/auto-instrumentations-node/-/auto-instrumentations-node-0.41.0.tgz",
|
||||
"integrity": "sha512-CmVVzphp1eb6Aenrr4B6TDsCNuDvut8NQbosTSdJFfnEX4+3szVQuaJquaicGI5tLvVxrgVbZAv52C7bJgMHkg==",
|
||||
"version": "0.41.1",
|
||||
"resolved": "https://registry.npmjs.org/@opentelemetry/auto-instrumentations-node/-/auto-instrumentations-node-0.41.1.tgz",
|
||||
"integrity": "sha512-gQG0mHlPVBQveuemqNYkrL4IB3T6v2e5sMiDI6FQzFWeLzzFrC04R4fY6AE1YmkhOyteCDpHL/U6CULP2mkt8w==",
|
||||
"dependencies": {
|
||||
"@opentelemetry/instrumentation": "^0.48.0",
|
||||
"@opentelemetry/instrumentation-amqplib": "^0.34.0",
|
||||
"@opentelemetry/instrumentation-aws-lambda": "^0.38.0",
|
||||
"@opentelemetry/instrumentation-aws-sdk": "^0.38.0",
|
||||
"@opentelemetry/instrumentation-aws-sdk": "^0.38.1",
|
||||
"@opentelemetry/instrumentation-bunyan": "^0.35.0",
|
||||
"@opentelemetry/instrumentation-cassandra-driver": "^0.35.0",
|
||||
"@opentelemetry/instrumentation-connect": "^0.33.0",
|
||||
@@ -2153,9 +2153,9 @@
|
||||
}
|
||||
},
|
||||
"node_modules/@opentelemetry/instrumentation-aws-sdk": {
|
||||
"version": "0.38.0",
|
||||
"resolved": "https://registry.npmjs.org/@opentelemetry/instrumentation-aws-sdk/-/instrumentation-aws-sdk-0.38.0.tgz",
|
||||
"integrity": "sha512-q1R+evR1j8sqd5LG+I8fKqP5TAPJEEOmJTvtEDYCVCdtzukI0ABYN8SHEIgDgYZmGBDM0yvC6jH0GmoEwvYuMw==",
|
||||
"version": "0.38.1",
|
||||
"resolved": "https://registry.npmjs.org/@opentelemetry/instrumentation-aws-sdk/-/instrumentation-aws-sdk-0.38.1.tgz",
|
||||
"integrity": "sha512-/Tupb4UfVVkmcopq2H2nr2D/pHLF0riVw2biQQUJ/jGIkfrOgUMMKbShi2RQE4Zy8NFv3xaDn4/pNxzodLBy3w==",
|
||||
"dependencies": {
|
||||
"@opentelemetry/core": "^1.8.0",
|
||||
"@opentelemetry/instrumentation": "^0.48.0",
|
||||
@@ -2810,9 +2810,9 @@
|
||||
}
|
||||
},
|
||||
"node_modules/@opentelemetry/propagation-utils": {
|
||||
"version": "0.30.6",
|
||||
"resolved": "https://registry.npmjs.org/@opentelemetry/propagation-utils/-/propagation-utils-0.30.6.tgz",
|
||||
"integrity": "sha512-qvnYee5I/xrBY5XClUlOASIOdoTbnFGNI6+ViKqdoErF2xKmhysXcmxlJNzQFNDK0muTfjvJMZcFyEielARk7g==",
|
||||
"version": "0.30.10",
|
||||
"resolved": "https://registry.npmjs.org/@opentelemetry/propagation-utils/-/propagation-utils-0.30.10.tgz",
|
||||
"integrity": "sha512-hhTW8pFp9PSyosYzzuUL9rdm7HF97w3OCyElufFHyUnYnKkCBbu8ne2LyF/KSdI/xZ81ubxWZs78hX4S7pLq5g==",
|
||||
"engines": {
|
||||
"node": ">=14"
|
||||
},
|
||||
|
||||
@@ -8,7 +8,7 @@
|
||||
"@aws-sdk/credential-providers": "^3.309.0",
|
||||
"@honeycombio/opentelemetry-node": "^0.6.1",
|
||||
"@opentelemetry/api": "^1.7.0",
|
||||
"@opentelemetry/auto-instrumentations-node": "^0.41.0",
|
||||
"@opentelemetry/auto-instrumentations-node": "^0.41.1",
|
||||
"@smithy/node-http-handler": "^3.1.4",
|
||||
"adm-zip": "^0.5.10",
|
||||
"aws-sdk": "^2.1353",
|
||||
|
||||
@@ -63,6 +63,10 @@ services:
|
||||
image: "backend:${TAG}-${STAGE}"
|
||||
pid: "host"
|
||||
environment:
|
||||
- OTEL_SERVICE_NAME="test"
|
||||
- OTEL_EXPORTER_OTLP_PROTOCOL="http/protobuf"
|
||||
- OTEL_EXPORTER_OTLP_ENDPOINT="https://api.honeycomb.io:443"
|
||||
- OTEL_EXPORTER_OTLP_HEADERS="x-honeycomb-team=${HONEYCOMB_API_KEY}"
|
||||
- MONGO_NODE_DRIVER_HOST=mongo
|
||||
- MAILJET_KEY
|
||||
- MAILJET_SECRET
|
||||
|
||||
Reference in New Issue
Block a user