atatus-nodejs
Version:
Atatus APM agent for Node.js
93 lines (71 loc) • 2.97 kB
JavaScript
var AtatusHTTPClient = require('./http-client')
function Transporter(agent) {
this.agent = agent
this._methods = {
hostInfo: new AtatusHTTPClient('hostinfo', agent),
transactions: new AtatusHTTPClient('txn', agent),
errorEvents: new AtatusHTTPClient('error', agent),
errorMetrics: new AtatusHTTPClient('error_metric', agent),
traces: new AtatusHTTPClient('trace', agent),
metrics: new AtatusHTTPClient('metric', agent),
dtTraces: new AtatusHTTPClient('traces/spans', agent),
analytics: new AtatusHTTPClient('analytics/txn', agent, agent._conf.serverAnalyticsUrl, true),
}
}
Transporter.prototype.sendHostInfo = function sendHostInfo(callback) {
var agent = this.agent
var payload = {
environment: {
node_modules: agent._conf.dependencies || {},
settings: {
nodejs: agent._conf.nodeVersion,
framework: agent._conf.frameworkName,
frameworkVersion: agent._conf.frameworkVersion,
agentVersion: agent._conf.agentVersion,
appName: agent._conf.appName,
environment: agent._conf.environment,
logLevel: agent._conf.logLevel,
metricsInterval: agent._conf.metricsInterval,
traceThreshold: agent._conf.traceThreshold,
captureExceptions: agent._conf.captureExceptions,
asyncHooks: agent._conf.asyncHooks,
ignoreStatusCodes: agent._conf.ignoreStatusCodes,
analytics: agent._conf.analytics,
analyticsCaptureOutgoing: agent._conf.analyticsCaptureOutgoing,
// serverTimeout: agent._conf.serverTimeout,
},
host: agent._conf.hostDetails || {}
},
timestamp: Date.now()
}
payload.environment.host.containerId = agent._conf.containerId;
payload.environment.host.version = payload.environment.host.release;
this._methods.hostInfo.request(payload, function cb_invoke(error, config, body) {
if (error) return callback(error, config, body)
agent._conf.backendConfig = config || {}
callback(null, config, body)
})
}
Transporter.prototype.send = function send(name, body, callback) {
if (this.agent._conf.blocked && (name !== 'analytics')) {
// Dont show the message if analytics is set true
let analytics = this.agent._conf.analytics && !!(this.agent._conf.backendConfig && this.agent._conf.backendConfig.analytics)
let level = analytics ? 'debug' : 'error'
this.agent.logger[level]('Sending APM data to Atatus is blocked. Contact us!')
return callback(null)
}
let agent = this.agent
this._methods[name].request(body, function requestHandler(error, returned, json) {
if (!error) return callback(error, returned, json)
let level = error.dontShowErrorMessage ? 'debug' : 'error'
agent.logger[level](
error.message || error,
"Sending data to Atatus failed: ",
name,
error.class || ''
)
return callback(error, returned, json)
})
}
module.exports = Transporter