diff --git a/packages/dd-trace/src/config.js b/packages/dd-trace/src/config.js index 7a92a611fcb..14bdd84b94d 100644 --- a/packages/dd-trace/src/config.js +++ b/packages/dd-trace/src/config.js @@ -145,7 +145,7 @@ function maybeFile (filepath) { try { return fs.readFileSync(filepath, 'utf8') } catch (e) { - log.error(e) + log.error('Error reading file %s', filepath, e) return undefined } } @@ -378,7 +378,7 @@ class Config { } catch (e) { // Only log error if the user has set a git.properties path if (process.env.DD_GIT_PROPERTIES_FILE) { - log.error(e) + log.error('Error reading DD_GIT_PROPERTIES_FILE: %s', DD_GIT_PROPERTIES_FILE, e) } } if (gitPropertiesString) { diff --git a/packages/dd-trace/src/datastreams/writer.js b/packages/dd-trace/src/datastreams/writer.js index f8c9e021ecc..5f789f2e056 100644 --- a/packages/dd-trace/src/datastreams/writer.js +++ b/packages/dd-trace/src/datastreams/writer.js @@ -45,13 +45,13 @@ class DataStreamsWriter { zlib.gzip(encodedPayload, { level: 1 }, (err, compressedData) => { if (err) { - log.error(err) + log.error('Error zipping datastream', err) return } makeRequest(compressedData, this._url, (err, res) => { log.debug(`Response from the agent: ${res}`) if (err) { - log.error(err) + log.error('Error sending datastream', err) } }) }) diff --git a/packages/dd-trace/src/dogstatsd.js b/packages/dd-trace/src/dogstatsd.js index ba84de71341..a396c9e98a4 100644 --- a/packages/dd-trace/src/dogstatsd.js +++ b/packages/dd-trace/src/dogstatsd.js @@ -71,7 +71,7 @@ class DogStatsDClient { const buffer = Buffer.concat(queue) request(buffer, this._httpOptions, (err) => { if (err) { - log.error('HTTP error from agent: ' + err.stack) + log.error('DogStatsDClient: HTTP error from agent: %s', err.message, err) if (err.status === 404) { // Inside this if-block, we have connectivity to the agent, but // we're not getting a 200 from the proxy endpoint. If it's a 404, @@ -89,7 +89,7 @@ class DogStatsDClient { this._sendUdpFromQueue(queue, this._host, this._family) } else { lookup(this._host, (err, address, family) => { - if (err) return log.error(err) + if (err) return log.error('DogStatsDClient: Host not found', err) this._sendUdpFromQueue(queue, address, family) }) } diff --git a/packages/dd-trace/src/exporters/agent/writer.js b/packages/dd-trace/src/exporters/agent/writer.js index 82a28647778..8fac323e614 100644 --- a/packages/dd-trace/src/exporters/agent/writer.js +++ b/packages/dd-trace/src/exporters/agent/writer.js @@ -41,17 +41,17 @@ class Writer extends BaseWriter { startupLog({ agentError: err }) if (err) { - log.error(err) + log.error('Error sending payload to the agent (status code: %s)', err.status, err) done() return } - log.debug(`Response from the agent: ${res}`) + log.debug('Response from the agent: %s', res) try { this._prioritySampler.update(JSON.parse(res).rate_by_service) } catch (e) { - log.error(e) + log.error('Error updating prioritySampler rates', e) runtimeMetrics.increment(`${METRIC_PREFIX}.errors`, true) runtimeMetrics.increment(`${METRIC_PREFIX}.errors.by.name`, `name:${e.name}`, true) diff --git a/packages/dd-trace/src/exporters/span-stats/writer.js b/packages/dd-trace/src/exporters/span-stats/writer.js index 3ece6d221b4..37cd6c77d5e 100644 --- a/packages/dd-trace/src/exporters/span-stats/writer.js +++ b/packages/dd-trace/src/exporters/span-stats/writer.js @@ -16,7 +16,7 @@ class Writer extends BaseWriter { _sendPayload (data, _, done) { makeRequest(data, this._url, (err, res) => { if (err) { - log.error(err) + log.error('Error sending span stats', err) done() return } diff --git a/packages/dd-trace/src/opentracing/tracer.js b/packages/dd-trace/src/opentracing/tracer.js index 2d854442cc3..4ae30ca93ac 100644 --- a/packages/dd-trace/src/opentracing/tracer.js +++ b/packages/dd-trace/src/opentracing/tracer.js @@ -91,7 +91,7 @@ class DatadogTracer { } this._propagators[format].inject(context, carrier) } catch (e) { - log.error(e) + log.error('Error injecting trace', e) runtimeMetrics.increment('datadog.tracer.node.inject.errors', true) } } @@ -100,7 +100,7 @@ class DatadogTracer { try { return this._propagators[format].extract(carrier) } catch (e) { - log.error(e) + log.error('Error extracting trace', e) runtimeMetrics.increment('datadog.tracer.node.extract.errors', true) return null } diff --git a/packages/dd-trace/src/proxy.js b/packages/dd-trace/src/proxy.js index 5c113399601..7a6027f90f1 100644 --- a/packages/dd-trace/src/proxy.js +++ b/packages/dd-trace/src/proxy.js @@ -182,7 +182,7 @@ class Tracer extends NoopProxy { } } } catch (e) { - log.error(e) + log.error('Error initialising tracer', e) } return this @@ -193,7 +193,7 @@ class Tracer extends NoopProxy { try { return require('./profiler').start(config) } catch (e) { - log.error(e) + log.error('Error starting profiler', e) } } diff --git a/packages/dd-trace/src/runtime_metrics.js b/packages/dd-trace/src/runtime_metrics.js index b2711879a05..49e724eb11c 100644 --- a/packages/dd-trace/src/runtime_metrics.js +++ b/packages/dd-trace/src/runtime_metrics.js @@ -32,7 +32,7 @@ module.exports = { nativeMetrics = require('@datadog/native-metrics') nativeMetrics.start() } catch (e) { - log.error(e) + log.error('Error starting native metrics', e) nativeMetrics = null } diff --git a/packages/dd-trace/src/telemetry/send-data.js b/packages/dd-trace/src/telemetry/send-data.js index 813fa427812..81406910c27 100644 --- a/packages/dd-trace/src/telemetry/send-data.js +++ b/packages/dd-trace/src/telemetry/send-data.js @@ -57,7 +57,7 @@ function sendData (config, application, host, reqType, payload = {}, cb = () => try { url = url || new URL(getAgentlessTelemetryEndpoint(config.site)) } catch (err) { - log.error(err) + log.error('Telemetry endpoint url is invalid', err) // No point to do the request if the URL is invalid return cb(err, { payload, reqType }) } @@ -100,7 +100,7 @@ function sendData (config, application, host, reqType, payload = {}, cb = () => path: '/api/v2/apmtelemetry' } if (backendUrl) { - request(data, backendOptions, (error) => { log.error(error) }) + request(data, backendOptions, (error) => { log.error('Error sending telemetry data', error) }) } else { log.error('Invalid Telemetry URL') } diff --git a/packages/dd-trace/test/config.spec.js b/packages/dd-trace/test/config.spec.js index 9c255d722bd..1eba985d04b 100644 --- a/packages/dd-trace/test/config.spec.js +++ b/packages/dd-trace/test/config.spec.js @@ -1781,9 +1781,12 @@ describe('Config', () => { }) expect(log.error).to.be.callCount(3) - expect(log.error.firstCall).to.have.been.calledWithExactly(error) - expect(log.error.secondCall).to.have.been.calledWithExactly(error) - expect(log.error.thirdCall).to.have.been.calledWithExactly(error) + expect(log.error.firstCall) + .to.have.been.calledWithExactly('Error reading file %s', 'DOES_NOT_EXIST.json', error) + expect(log.error.secondCall) + .to.have.been.calledWithExactly('Error reading file %s', 'DOES_NOT_EXIST.html', error) + expect(log.error.thirdCall) + .to.have.been.calledWithExactly('Error reading file %s', 'DOES_NOT_EXIST.json', error) expect(config.appsec.enabled).to.be.true expect(config.appsec.rules).to.eq('path/to/rules.json') diff --git a/packages/dd-trace/test/exporters/agent/writer.spec.js b/packages/dd-trace/test/exporters/agent/writer.spec.js index ce7a62d49bf..aad8749ef37 100644 --- a/packages/dd-trace/test/exporters/agent/writer.spec.js +++ b/packages/dd-trace/test/exporters/agent/writer.spec.js @@ -149,6 +149,7 @@ function describeWriter (protocolVersion) { it('should log request errors', done => { const error = new Error('boom') + error.status = 42 request.yields(error) @@ -156,7 +157,8 @@ function describeWriter (protocolVersion) { writer.flush() setTimeout(() => { - expect(log.error).to.have.been.calledWith(error) + expect(log.error) + .to.have.been.calledWith('Error sending payload to the agent (status code: %s)', error.status, error) done() }) }) diff --git a/packages/dd-trace/test/exporters/span-stats/writer.spec.js b/packages/dd-trace/test/exporters/span-stats/writer.spec.js index d65d480409d..f8e65500e04 100644 --- a/packages/dd-trace/test/exporters/span-stats/writer.spec.js +++ b/packages/dd-trace/test/exporters/span-stats/writer.spec.js @@ -106,7 +106,7 @@ describe('span-stats writer', () => { encoder.count.returns(1) writer.flush(() => { - expect(log.error).to.have.been.calledWith(error) + expect(log.error).to.have.been.calledWith('Error sending span stats', error) done() }) }) diff --git a/packages/dd-trace/test/proxy.spec.js b/packages/dd-trace/test/proxy.spec.js index 4836e99787f..dd145390245 100644 --- a/packages/dd-trace/test/proxy.spec.js +++ b/packages/dd-trace/test/proxy.spec.js @@ -520,8 +520,9 @@ describe('TracerProxy', () => { const profilerImportFailureProxy = new ProfilerImportFailureProxy() profilerImportFailureProxy.init() + sinon.assert.calledOnce(log.error) const expectedErr = sinon.match.instanceOf(Error).and(sinon.match.has('code', 'MODULE_NOT_FOUND')) - sinon.assert.calledWith(log.error, sinon.match(expectedErr)) + sinon.assert.match(log.error.firstCall.lastArg, sinon.match(expectedErr)) }) it('should start telemetry', () => {