Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.
const trackExceptionStub = sinon.stub(AppInsights.defaultClient, "trackException");
const trackTraceStub = sinon.stub(AppInsights.defaultClient, "trackTrace");
disable();
enable(true, AppInsights.defaultClient);
const logEvent: console.IConsoleData = {
message: "test log",
stderr: true // should log as MessageData regardless of this setting
};
const dummyError = new Error("test error");
const errorEvent: console.IConsoleData = {
message: dummyError as any,
stderr: false, // log() should still log as ExceptionData
};
channel.publish("console", logEvent);
assert.ok(trackExceptionStub.notCalled);
assert.ok(trackTraceStub.calledOnce);
assert.deepEqual(trackTraceStub.args[0][0].message, "test log");
trackExceptionStub.reset();
trackTraceStub.reset();
channel.publish("console", errorEvent);
assert.ok(trackExceptionStub.calledOnce);
assert.ok(trackTraceStub.notCalled);
assert.deepEqual(trackExceptionStub.args[0][0].exception, dummyError);
disable();
trackExceptionStub.restore();
trackTraceStub.restore();
});
});
stderr: true // should log as MessageData regardless of this setting
};
const dummyError = new Error("test error");
const errorEvent: console.IConsoleData = {
message: dummyError as any,
stderr: false, // log() should still log as ExceptionData
};
channel.publish("console", logEvent);
assert.ok(trackExceptionStub.notCalled);
assert.ok(trackTraceStub.calledOnce);
assert.deepEqual(trackTraceStub.args[0][0].message, "test log");
trackExceptionStub.reset();
trackTraceStub.reset();
channel.publish("console", errorEvent);
assert.ok(trackExceptionStub.calledOnce);
assert.ok(trackTraceStub.notCalled);
assert.deepEqual(trackExceptionStub.args[0][0].exception, dummyError);
disable();
trackExceptionStub.restore();
trackTraceStub.restore();
});
});
const trackingCallback = channel.bindToContext(function(err: Error, res: IPostgresResult): any {
const end = process.hrtime(start);
data.result = res && { rowCount: res.rowCount, command: res.command };
data.error = err;
data.duration = Math.ceil((end[0] * 1e3) + (end[1] / 1e6));
channel.publish("postgres", data);
// emulate weird internal behavior in pg@6
// on success, the callback is called *before* query events are emitted
// on failure, the callback is called *instead of* the query emitting events
// with no events, that means no promises (since the promise is resolved/rejected in an event handler)
// since we are always inserting ourselves as a callback, we have to restore the original
// behavior if the user didn't provide one themselves
if (err) {
if (cb) {
return cb.apply(this, arguments);
} else if (queryResult && queryResult instanceof EventEmitter) {
queryResult.emit("error", err);
}
} else if (cb) {
cb.apply(this, arguments);
}
return function(err) {
const hrDuration = process.hrtime(resultContainer.startTime);
/* tslint:disable-next-line:no-bitwise */
const duration = (hrDuration[0] * 1e3 + hrDuration[1] / 1e6) | 0;
channel.publish("mysql", {query: resultContainer.result, callbackArgs: arguments, err, duration});
cb.apply(this, arguments);
};
});
commandObj.callback = channel.bindToContext(function(err, result) {
const hrDuration = process.hrtime(startTime);
/* tslint:disable-next-line:no-bitwise */
const duration = (hrDuration[0] * 1e3 + hrDuration[1] / 1e6) | 0;
channel.publish("redis", {duration, address, commandObj, err, result});
if (typeof cb === "function") {
cb.apply(this, arguments);
}
});
commandObj.callback.pubsubBound = true;
const loggingFilter = (level, message, meta) => {
let levelKind: string;
if (curLevels === originalWinston.config.npm.levels) {
levelKind = "npm";
} else if (curLevels === originalWinston.config.syslog.levels) {
levelKind = "syslog";
} else {
levelKind = "unknown";
}
channel.publish("winston", {level, message, meta, levelKind});
return message;
};
public onEnd(span: coreTracingTypes.Span): void {
channel.publish("azure-coretracing", span);
}
originalBunyan.prototype._emit = function(rec, noemit) {
const ret = originalEmit.apply(this, arguments);
if (!noemit) {
let str = ret;
if (!str) {
str = originalEmit.call(this, rec, true);
}
channel.publish("bunyan", {level: rec.level, result: str});
}
return ret;
};
contextMap[event.requestId](() => channel.publish("mongodb", {startedData, event, succeeded: false}));
delete contextMap[event.requestId];
return channel.bindToContext(function(err: Error | null, rowCount?: number | null, rows?: any) {
const end = process.hrtime(start);
data = { ...data,
database: {
host: this.connection.config.server,
port: this.connection.config.options.port,
},
result: !err && { rowCount, rows },
query: {
text: this.parametersByName.statement.value,
},
error: err,
duration: Math.ceil((end[0] * 1e3) + (end[1] / 1e6)),
};
channel.publish("tedious", data);
origCallback.call(this, err, rowCount, rows);
});
}