Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

add tracer metrics for the agent exporter #748

Merged
merged 9 commits into from
Nov 18, 2019
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions LICENSE-3rdparty.csv
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@ require,@types/node,MIT,Copyright Authors
require,bowser,MIT,Copyright 2015 Dustin Diaz
require,container-info,MIT,Copyright 2018 Stephen Belanger
require,core-js,MIT,Copyright 2014-2019 Denis Pushkarev
require,hdr-histogram-js,BSD-2-Clause,Copyright 2016 Alexandre Victoor
require,int64-buffer,MIT,Copyright 2015-2016 Yusuke Kawasaki
require,koalas,MIT,Copyright 2013-2017 Brian Woodward
require,limiter,MIT,Copyright 2011 John Hurliman
Expand Down
7 changes: 7 additions & 0 deletions benchmark/core.js
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,8 @@ const format = require('../packages/dd-trace/src/format')
const encode = require('../packages/dd-trace/src/encode')
const config = new Config('benchmark', { service: 'benchmark' })
const id = require('../packages/dd-trace/src/id')
const Histogram = require('../packages/dd-trace/src/histogram')
const histogram = new Histogram()

const suite = benchmark('core')

Expand Down Expand Up @@ -99,5 +101,10 @@ suite
id()
}
})
.add('Histogram', {
fn () {
histogram.record(Math.round(Math.random() * 3e12))
}
})

suite.run()
1 change: 1 addition & 0 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -52,6 +52,7 @@
"bowser": "^2.5.3",
"container-info": "^1.0.1",
"core-js": "^3.3.4",
"hdr-histogram-js": "^1.1.4",
"int64-buffer": "^0.1.9",
"koalas": "^1.0.2",
"limiter": "^1.1.4",
Expand Down
20 changes: 19 additions & 1 deletion packages/dd-trace/src/exporters/agent/writer.js
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,8 @@ class Writer {

log.debug(() => `Adding encoded trace to buffer: ${buffer.toString('hex').match(/../g).join(' ')}`)

platform.metrics().histogram('datadog.tracer.node.exporter.agent.trace_size', buffer.length)

if (buffer.length + this._size > MAX_SIZE) {
this.flush()
}
Expand All @@ -37,9 +39,12 @@ class Writer {
flush () {
if (this._queue.length > 0) {
const data = platform.msgpack.prefix(this._queue)
const size = data.reduce((prev, next) => prev + next.length, 0)

this._request(data, this._queue.length)

platform.metrics().histogram('datadog.tracer.node.exporter.agent.payload_size', size)

this._queue = []
this._size = 0
}
Expand Down Expand Up @@ -70,7 +75,20 @@ class Writer {

log.debug(() => `Request to the agent: ${JSON.stringify(options)}`)

platform.request(Object.assign({ data }, options), (err, res) => {
platform.metrics().increment('datadog.tracer.node.exporter.agent.requests')

platform.request(Object.assign({ data }, options), (err, res, status) => {
if (status) {
platform.metrics().increment('datadog.tracer.node.exporter.agent.responses')
platform.metrics().increment('datadog.tracer.node.exporter.agent.responses.by.status', `status:${status}`)
} else {
platform.metrics().increment('datadog.tracer.node.exporter.agent.errors')

if (err && err.code) {
platform.metrics().increment('datadog.tracer.node.exporter.agent.errors.by.code', `code:${err.code}`)
brettlangdon marked this conversation as resolved.
Show resolved Hide resolved
}
}

if (err) return log.error(err)

log.debug(`Response from the agent: ${res}`)
Expand Down
52 changes: 52 additions & 0 deletions packages/dd-trace/src/histogram.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,52 @@
'use strict'

const hdr = require('hdr-histogram-js')

const highestTrackableValue = 3.6e12 // 1 hour

class Histogram {
constructor () {
this._histogram = hdr.build({
highestTrackableValue
})

this.reset()
}

get min () { return this._min }
get max () { return this._max }
get avg () { return this._count === 0 ? 0 : this._sum / this._count }
get sum () { return this._sum }
get count () { return this._count }
get median () { return this.percentile(50) }
get p95 () { return this.percentile(95) }

percentile (percentile) {
return this._histogram.getValueAtPercentile(percentile)
}

record (value) {
if (this._count === 0) {
this._min = this._max = value
} else {
this._min = Math.min(this._min, value)
this._max = Math.max(this._max, value)
}

this._count++
this._sum += value

this._histogram.recordValue(value)
}

reset () {
this._min = 0
this._max = 0
this._sum = 0
this._count = 0

this._histogram.reset()
}
}

module.exports = Histogram
2 changes: 2 additions & 0 deletions packages/dd-trace/src/platform/browser/metrics.js
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,8 @@ module.exports = function () {
}
},

histogram () {},

count () {},

increment () {},
Expand Down
Loading