Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.
function SentryLogger(options) {
if (!(this instanceof SentryLogger)) {
return new SentryLogger(options);
}
winston.Transport.call(this, options);
this.name = 'SentryLogger';
this.level = options.level || 'error';
this.enabled = typeof(options.enabled) === 'boolean' ?
options.enabled : true;
this.dsn = options.dsn;
this.defaultTags = options.tags || {};
this.computeErrLoc = options.computeErrLoc || computeErrLoc;
if (!this.defaultTags.pid) {
this.defaultTags.pid = process.pid;
}
var ravenErrorHandler = typeof options.onRavenError === 'function' ?
options.onRavenError : function (e) {
// do not warn() on 429 errors
if (e.message.indexOf('429') >= 0) {
// furnished to do so, subject to the following conditions:
//
// The above copyright notice and this permission notice shall be included in
// all copies or substantial portions of the Software.
//
// THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
// IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
// FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
// AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
// LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
// OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
// THE SOFTWARE.
/* jshint forin: false */
var util = require('util');
var Transport = require('winston-uber').Transport;
var KafkaRestClient = require('kafka-rest-client');
var hostName = require('os').hostname();
var extend = require('xtend');
function KafkaLogger(options) {
if (!(this instanceof KafkaLogger)) {
return new KafkaLogger(options);
}
var self = this;
function onConnect(err) {
if (!err) {
if (self.logger) {
self.logger.info('KafkaClient connected to kafka');
}
this.captureMessage = this.ravenClient.captureMessage
.bind(this.ravenClient);
this.sentryProber = options.sentryProber || null;
this.sentryProberCallbackImmediately = !options.sentryProberDetectFailuresBy;
this.sentryProberDetectFailuresByCallback = options.sentryProberDetectFailuresBy === SentryLogger.detectBy.CALLBACK;
this.sentryProberDetectFailuresByEvent = options.sentryProberDetectFailuresBy === SentryLogger.detectBy.EVENT;
this.sentryProberDetectFailuresByEventSuccessEvent = options.sentryProberDetectFailuresByEventSuccessEvent;
this.sentryProberDetectFailuresByEventFailureEvent = options.sentryProberDetectFailuresByEventFailureEvent;
}
SentryLogger.detectBy = {
CALLBACK: 'callback',
EVENT: 'event'
};
util.inherits(SentryLogger, winston.Transport);
SentryLogger.prototype.name = 'SentryLogger';
SentryLogger.prototype.log = function(level, msg, meta, callback) {
var thunk;
if (!meta || typeof meta !== 'object') {
meta = {};
}
// store original meta because we might serialize it
var originalMeta = meta;
var stringMeta = stringify(meta);
// To avoid sending circular data to sentry we check
// whether its circular using json-stringify-safe and then
// stringify(parse(meta)) to make it not circular