Skip to content

Commit

Permalink
fix: improved debug logs in agent sending spans (#1259)
Browse files Browse the repository at this point in the history
- refs INSTA-5316
  • Loading branch information
abhilash-sivan committed Aug 8, 2024
1 parent bf471ed commit 55ee69e
Showing 1 changed file with 43 additions and 0 deletions.
43 changes: 43 additions & 0 deletions packages/collector/src/agentConnection.js
Original file line number Diff line number Diff line change
Expand Up @@ -266,6 +266,10 @@ exports.sendSpans = function sendSpans(spans, cb) {
const callback = util.atMostOnce('callback for sendSpans', err => {
if (err && !maxContentErrorHasBeenLogged && err instanceof PayloadTooLargeError) {
logLargeSpans(spans);
} else if (err) {
logger.debug('Failed to send: %s', getSpanLengthInfo(spans));
} else {
logger.debug('Successfully sent: %s', getSpanLengthInfo(spans));
}
cb(err);
});
Expand Down Expand Up @@ -486,3 +490,42 @@ function logLargeSpans(spans) {
)}`
);
}

/**
* @typedef {InstanaBaseSpan} Span Span
* @property {number} [k] kind
*/

/**
* Returning type for the function getSpanLengthInfo
* @typedef {Object.<string, number>} CountBySpanType
*/

/**
* @param {Span[]} spans
* @returns {CountBySpanType}
*/
function getSpanLengthInfo(spans) {
/** @type {Object.<number, string>} */
const spanMapping = {
1: 'entrySpans',
2: 'exitSpans',
3: 'intermediateSpans'
};

/**
* @param {CountBySpanType} acc
* @param {Span} item
*/
const reducer = (acc, item) => {
const label = spanMapping[item?.k];
if (label) {
acc[label] = (acc[label] || 0) + 1;
}
return acc;
};

const countBySpanType = spans.reduce(reducer, {});

return countBySpanType;
}

0 comments on commit 55ee69e

Please sign in to comment.