Skip to content

Commit

Permalink
Add a message to some log.error(err)
Browse files Browse the repository at this point in the history
  • Loading branch information
iunanua committed Nov 22, 2024
1 parent b576603 commit 89976b9
Show file tree
Hide file tree
Showing 13 changed files with 29 additions and 23 deletions.
4 changes: 2 additions & 2 deletions packages/dd-trace/src/config.js
Original file line number Diff line number Diff line change
Expand Up @@ -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
}
}
Expand Down Expand Up @@ -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) {
Expand Down
4 changes: 2 additions & 2 deletions packages/dd-trace/src/datastreams/writer.js
Original file line number Diff line number Diff line change
Expand Up @@ -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)
}
})
})
Expand Down
4 changes: 2 additions & 2 deletions packages/dd-trace/src/dogstatsd.js
Original file line number Diff line number Diff line change
Expand Up @@ -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,
Expand All @@ -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)
})
}
Expand Down
6 changes: 3 additions & 3 deletions packages/dd-trace/src/exporters/agent/writer.js
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand Down
2 changes: 1 addition & 1 deletion packages/dd-trace/src/exporters/span-stats/writer.js
Original file line number Diff line number Diff line change
Expand Up @@ -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
}
Expand Down
4 changes: 2 additions & 2 deletions packages/dd-trace/src/opentracing/tracer.js
Original file line number Diff line number Diff line change
Expand Up @@ -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)
}
}
Expand All @@ -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
}
Expand Down
4 changes: 2 additions & 2 deletions packages/dd-trace/src/proxy.js
Original file line number Diff line number Diff line change
Expand Up @@ -182,7 +182,7 @@ class Tracer extends NoopProxy {
}
}
} catch (e) {
log.error(e)
log.error('Error initialising tracer', e)
}

return this
Expand All @@ -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)
}
}

Expand Down
2 changes: 1 addition & 1 deletion packages/dd-trace/src/runtime_metrics.js
Original file line number Diff line number Diff line change
Expand Up @@ -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
}

Expand Down
4 changes: 2 additions & 2 deletions packages/dd-trace/src/telemetry/send-data.js
Original file line number Diff line number Diff line change
Expand Up @@ -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 })
}
Expand Down Expand Up @@ -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')
}
Expand Down
9 changes: 6 additions & 3 deletions packages/dd-trace/test/config.spec.js
Original file line number Diff line number Diff line change
Expand Up @@ -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')
Expand Down
4 changes: 3 additions & 1 deletion packages/dd-trace/test/exporters/agent/writer.spec.js
Original file line number Diff line number Diff line change
Expand Up @@ -149,14 +149,16 @@ function describeWriter (protocolVersion) {

it('should log request errors', done => {
const error = new Error('boom')
error.status = 42

request.yields(error)

encoder.count.returns(1)
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()
})
})
Expand Down
2 changes: 1 addition & 1 deletion packages/dd-trace/test/exporters/span-stats/writer.spec.js
Original file line number Diff line number Diff line change
Expand Up @@ -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()
})
})
Expand Down
3 changes: 2 additions & 1 deletion packages/dd-trace/test/proxy.spec.js
Original file line number Diff line number Diff line change
Expand Up @@ -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', () => {
Expand Down

0 comments on commit 89976b9

Please sign in to comment.