Skip to content
This repository has been archived by the owner on Jun 13, 2023. It is now read-only.

Commit

Permalink
feat(sql): collecting response data (#385)
Browse files Browse the repository at this point in the history
  • Loading branch information
henperez authored Nov 8, 2020
1 parent e69e6f6 commit f859787
Show file tree
Hide file tree
Showing 2 changed files with 17 additions and 2 deletions.
14 changes: 13 additions & 1 deletion src/events/sql.js
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,8 @@ const errorCode = require('../proto/error_code_pb.js');

const MAX_QUERY_SIZE = 2048;
const MAX_PARAMS_LENGTH = 5;
const MAX_QUERY_ELEMENTS = 100;


/**
* Parse query arguments - get the callback and params
Expand Down Expand Up @@ -96,11 +98,21 @@ module.exports.wrapSqlQuery = function wrapSqlQuery(queryString, params, callbac
if (err) {
eventInterface.setException(dbapiEvent, err);
} else {
let { rowCount } = res;
let { rowCount, rows } = res;
if (!rowCount && res instanceof Array) {
rowCount = res.length;
rows = res;
}
eventInterface.addToMetadata(dbapiEvent, { rowCount });
if (rowCount && rows instanceof Array && rows.length) {
if (rows.length > MAX_QUERY_ELEMENTS) {
eventInterface.addToMetadata(dbapiEvent, { is_trimmed: true });
}
eventInterface.addToMetadata(
dbapiEvent,
{ 'sql.rows': rows.slice(0, MAX_QUERY_ELEMENTS) }
);
}
}

resolve();
Expand Down
5 changes: 4 additions & 1 deletion src/tracer.js
Original file line number Diff line number Diff line change
Expand Up @@ -182,7 +182,7 @@ module.exports.restart = function restart() {
function getTrimmedMetadata(eventMetadata, isRunner) {
let trimmedEventMetadata;
Object.keys(eventMetadata).forEach((eventKey) => {
if (!isStrongId(eventKey) && (isRunner && eventKey !== 'labels')) {
if (!(isStrongId(eventKey) || (isRunner && eventKey === 'labels'))) {
if (!trimmedEventMetadata) {
trimmedEventMetadata = eventMetadata;
trimmedEventMetadata.is_trimmed = true;
Expand Down Expand Up @@ -228,6 +228,7 @@ function getTrimmedTrace(traceSize, jsTrace) {
totalTrimmedExceptions = totalTrimmed;
trimmedTrace.exceptions = [firstException];
}
utils.debugLog(`Epsagon - Pre metadata trim: current trace size ${currentTraceSize}`);
// Trimming trace events metadata.
if (currentTraceSize >= consts.MAX_TRACE_SIZE_BYTES) {
trimmedTrace.events = jsTrace.events.sort(event => (['runner', 'trigger'].includes(event.origin) ? -1 : 1));
Expand All @@ -250,6 +251,7 @@ function getTrimmedTrace(traceSize, jsTrace) {
}
}
}
utils.debugLog(`Epsagon - After metadata trim: current trace size ${currentTraceSize}`);
// Trimming trace events.
if (currentTraceSize >= consts.MAX_TRACE_SIZE_BYTES) {
for (let i = jsTrace.events.length - 1; i >= 0; i -= 1) {
Expand All @@ -264,6 +266,7 @@ function getTrimmedTrace(traceSize, jsTrace) {
}
}
}
utils.debugLog(`Epsagon - After events trim: current trace size ${currentTraceSize}`);
if (totalTrimmedEvents || totalTrimmedExceptions) {
utils.debugLog(`Epsagon - Trace size is larger than maximum size, ${totalTrimmedEvents} events and ${totalTrimmedExceptions} exceptions were trimmed.`);
}
Expand Down

0 comments on commit f859787

Please sign in to comment.