refactor to remove Redis

- prevent drachtio from auto passing the non-success response
This commit is contained in:
rhonda hollis
2026-05-15 11:07:09 -07:00
parent ac7f8c4424
commit f567049bfb
4 changed files with 19 additions and 26 deletions
-9
View File
@@ -28,7 +28,6 @@ module.exports = function(srf, logger) {
registrar,
lookupClientByAccountAndUsername
} = srf.locals.dbHelpers;
const {addKey} = srf.locals.dbHelpers;
const {
writeAlerts,
AlertType
@@ -143,14 +142,6 @@ module.exports = function(srf, logger) {
rootSpan
};
/* write a short-lived Redis key mapping the original Call-ID (X-CID) to the traceId,
so sbc-inbound can look it up for CDRs even when a CANCEL is sent to sbc-inbound */
const externalCallId = req.get('X-CID');
if (externalCallId) {
addKey(`callid:${externalCallId}`, traceId, 300)
.catch((err) => logger.error(err, 'createRootSpan: error writing traceId to Redis'));
}
/**
* end the span on final failure or cancel from caller;
* otherwise it will be closed when sip dialog is destroyed
+11 -8
View File
@@ -192,6 +192,15 @@ class CallSession extends Emitter {
return this.callInfo.applicationSid;
}
get _traceHeaders() {
const traceId = this.req?.locals?.traceId;
const applicationSid = this.applicationSid;
return {
...(traceId && {'X-Trace-ID': traceId}),
...(applicationSid && {'X-Application-Sid': applicationSid})
};
}
get callStatus() {
return this.callInfo.callStatus;
}
@@ -1495,12 +1504,7 @@ class CallSession extends Emitter {
else if (opts.call_status === CallStatus.NoAnswer) {
if (this.direction === CallDirection.Inbound) {
if (this.res && !this.res.finalResponseSent) {
const traceId = this.req?.locals?.traceId;
this.res.send(503, {
headers: {
...(traceId && {'X-Trace-ID': traceId})
}
});
this.res.send(503, {headers: this._traceHeaders});
this._callReleased();
}
}
@@ -2535,12 +2539,11 @@ Duration=${duration} `
// Send SIP error response immediately for inbound calls
if (this.res && !this.res.finalResponseSent) {
this.logger.info(`Sending ${err.status} response to SBC due to SipError`);
const traceId = this.req?.locals?.traceId;
this.res.send(err.status, {
headers: {
'X-Reason': `endpoint allocation failure: ${err.reason || 'Endpoint Allocation Failed'}`,
...(sipReasonHeader && {'Reason': sipReasonHeader}),
...(traceId && {'X-Trace-ID': traceId})
...this._traceHeaders
}
});
this._notifyCallStatusChange({
+3 -8
View File
@@ -51,14 +51,13 @@ class InboundCallSession extends CallSession {
_onTasksDone() {
if (!this.res.finalResponseSent) {
const traceId = this.req.locals.traceId;
if (this._mediaServerFailure) {
this.rootSpan.setAttributes({'call.termination': 'media server failure'});
this.logger.info('InboundCallSession:_onTasksDone generating 480 due to media server failure');
this.res.send(480, {
headers: {
'X-Reason': 'crankback: media server failure',
...(traceId && {'X-Trace-ID': traceId})
...this._traceHeaders
}
});
}
@@ -72,18 +71,14 @@ class InboundCallSession extends CallSession {
headers: {
'X-Reason': `endpoint allocation failure: ${reason}`,
...(sipReasonHeader && {'Reason': sipReasonHeader}),
...(traceId && {'X-Trace-ID': traceId})
...this._traceHeaders
}
});
}
else {
this.rootSpan.setAttributes({'call.termination': 'tasks completed without answering call'});
this.logger.info('InboundCallSession:_onTasksDone auto-generating non-success response to invite');
this.res.send(603, {
headers: {
...(traceId && {'X-Trace-ID': traceId})
}
});
this.res.send(603, {headers: this._traceHeaders});
}
}
this.req.removeAllListeners('cancel');
+5 -1
View File
@@ -17,7 +17,11 @@ class TaskSipDecline extends Task {
async exec(cs, {res}) {
super.exec(cs);
res.send(this.data.status, this.data.reason, {
headers: {'X-Reason': 'SIP Decline Verb', ...this.headers}
headers: {
'X-Reason': 'SIP Decline Verb',
...this.headers,
...cs._traceHeaders
}
}, (err) => {
if (!err) {
// Call was successfully declined