Skip to content
Closed
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
10 changes: 5 additions & 5 deletions index.d.ts
Original file line number Diff line number Diff line change
Expand Up @@ -827,39 +827,39 @@ declare namespace tracer {
* @param value The amount to increment the stat by.
* @param tags Tags to pass along, such as `{ foo: 'bar' }`. Values are combined with config.tags.
*/
increment(stat: string, value?: number, tags?: Record<string, string|number>): void
increment(stat: string, value?: number, tags?: Record<string, string|number|Array<string|number>>): void

/**
* Decrements a metric by the specified value, optionally specifying tags.
* @param stat The dot-separated metric name.
* @param value The amount to decrement the stat by.
* @param tags Tags to pass along, such as `{ foo: 'bar' }`. Values are combined with config.tags.
*/
decrement(stat: string, value?: number, tags?: Record<string, string|number>): void
decrement(stat: string, value?: number, tags?: Record<string, string|number|Array<string|number>>): void

/**
* Sets a distribution value, optionally specifying tags.
* @param stat The dot-separated metric name.
* @param value The amount to increment the stat by.
* @param tags Tags to pass along, such as `{ foo: 'bar' }`. Values are combined with config.tags.
*/
distribution(stat: string, value?: number, tags?: Record<string, string|number>): void
distribution(stat: string, value?: number, tags?: Record<string, string|number|Array<string|number>>): void

/**
* Sets a gauge value, optionally specifying tags.
* @param stat The dot-separated metric name.
* @param value The amount to increment the stat by.
* @param tags Tags to pass along, such as `{ foo: 'bar' }`. Values are combined with config.tags.
*/
gauge(stat: string, value?: number, tags?: Record<string, string|number>): void
gauge(stat: string, value?: number, tags?: Record<string, string|number|Array<string|number>>): void

/**
* Sets a histogram value, optionally specifying tags.
* @param stat The dot-separated metric name.
* @param value The amount to increment the stat by.
* @param tags Tags to pass along, such as `{ foo: 'bar' }`. Values are combined with config.tags.
*/
histogram(stat: string, value?: number, tags?: Record<string, string|number>): void
histogram(stat: string, value?: number, tags?: Record<string, string|number|Array<string|number>>): void

/**
* Forces any unsent metrics to be sent
Expand Down
9 changes: 8 additions & 1 deletion packages/dd-trace/src/dogstatsd.js
Original file line number Diff line number Diff line change
Expand Up @@ -390,7 +390,14 @@ class CustomMetrics {
if (!objTags) return arrTags

for (const [key, value] of Object.entries(objTags)) {
arrTags.push(`${key}:${value}`)
if (!Array.isArray(value)) {
arrTags.push(`${key}:${value}`)
continue
}

for (const val of value) {
arrTags.push(`${key}:${val}`)
}
}

return arrTags
Expand Down
16 changes: 14 additions & 2 deletions packages/dd-trace/test/dogstatsd.spec.js
Original file line number Diff line number Diff line change
Expand Up @@ -378,13 +378,15 @@ describe('dogstatsd', () => {
client = new CustomMetrics({ dogstatsd: {} })

client.gauge('test.avg', 10, { foo: 'bar' })
client.gauge('test.avg', 10, { foo: ['bar', 'baz'] })
client.gauge('test.avg', 10, { foo: 'bar', baz: 'qux' })
client.gauge('test.avg', 20, { foo: 'bar', baz: 'qux' })
client.flush()

expect(udp4.send).to.have.been.called
expect(udp4.send.firstCall.args[0].toString()).to.equal([
'test.avg:10|g|#foo:bar',
'test.avg:10|g|#foo:bar,foo:baz',
'test.avg:20|g|#foo:bar,baz:qux'
].join('\n') + '\n')
})
Expand Down Expand Up @@ -415,13 +417,15 @@ describe('dogstatsd', () => {
client = new CustomMetrics({ dogstatsd: {} })

client.increment('test.count', 10, { foo: 'bar' })
client.increment('test.count', 10, { foo: ['bar', 'baz'] })
client.increment('test.count', 10, { foo: 'bar', baz: 'qux' })
client.increment('test.count', 10, { foo: 'bar', baz: 'qux' })
client.flush()

expect(udp4.send).to.have.been.called
expect(udp4.send.firstCall.args[0].toString()).to.equal([
'test.count:10|c|#foo:bar',
'test.count:10|c|#foo:bar,foo:baz',
'test.count:20|c|#foo:bar,baz:qux'
].join('\n') + '\n')
})
Expand Down Expand Up @@ -483,6 +487,7 @@ describe('dogstatsd', () => {
client = new CustomMetrics({ dogstatsd: {} })

client.histogram('test.histogram', 10, { foo: 'bar' })
client.histogram('test.histogram', 10, { foo: ['bar', 'baz'] })
client.histogram('test.histogram', 10, { foo: 'bar', baz: 'qux' })
client.histogram('test.histogram', 10, { foo: 'bar', baz: 'qux' })
client.flush()
Expand All @@ -497,14 +502,21 @@ describe('dogstatsd', () => {
'test.histogram.count:1|c|#foo:bar',
'test.histogram.median:10.074696689511441|g|#foo:bar',
'test.histogram.95percentile:10.074696689511441|g|#foo:bar',
'test.histogram.min:10|g|#foo:bar,foo:baz',
'test.histogram.max:10|g|#foo:bar,foo:baz',
'test.histogram.sum:10|c|#foo:bar,foo:baz',
'test.histogram.total:10|c|#foo:bar,foo:baz',
'test.histogram.avg:10|g|#foo:bar,foo:baz',
'test.histogram.count:1|c|#foo:bar,foo:baz',
'test.histogram.median:10.074696689511441|g|#foo:bar,foo:baz',
'test.histogram.95percentile:10.074696689511441|g|#foo:bar,foo:baz',
'test.histogram.min:10|g|#foo:bar,baz:qux',
'test.histogram.max:10|g|#foo:bar,baz:qux',
'test.histogram.sum:20|c|#foo:bar,baz:qux',
'test.histogram.total:20|c|#foo:bar,baz:qux',
'test.histogram.avg:10|g|#foo:bar,baz:qux',
'test.histogram.count:2|c|#foo:bar,baz:qux',
'test.histogram.median:10.074696689511441|g|#foo:bar,baz:qux',
'test.histogram.95percentile:10.074696689511441|g|#foo:bar,baz:qux'
'test.histogram.median:10.074696689511441|g|#foo:bar,baz:qux'
].join('\n') + '\n')
})

Expand Down