diff --git a/index.d.ts b/index.d.ts index 1fb94bfe52b..4f1ee96d644 100644 --- a/index.d.ts +++ b/index.d.ts @@ -827,7 +827,7 @@ 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): void + increment(stat: string, value?: number, tags?: Record>): void /** * Decrements a metric by the specified value, optionally specifying tags. @@ -835,7 +835,7 @@ declare namespace tracer { * @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): void + decrement(stat: string, value?: number, tags?: Record>): void /** * Sets a distribution value, optionally specifying tags. @@ -843,7 +843,7 @@ 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. */ - distribution(stat: string, value?: number, tags?: Record): void + distribution(stat: string, value?: number, tags?: Record>): void /** * Sets a gauge value, optionally specifying tags. @@ -851,7 +851,7 @@ 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. */ - gauge(stat: string, value?: number, tags?: Record): void + gauge(stat: string, value?: number, tags?: Record>): void /** * Sets a histogram value, optionally specifying tags. @@ -859,7 +859,7 @@ 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. */ - histogram(stat: string, value?: number, tags?: Record): void + histogram(stat: string, value?: number, tags?: Record>): void /** * Forces any unsent metrics to be sent diff --git a/packages/dd-trace/src/dogstatsd.js b/packages/dd-trace/src/dogstatsd.js index a8e60782d90..5e4404fa21f 100644 --- a/packages/dd-trace/src/dogstatsd.js +++ b/packages/dd-trace/src/dogstatsd.js @@ -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 diff --git a/packages/dd-trace/test/dogstatsd.spec.js b/packages/dd-trace/test/dogstatsd.spec.js index 67525a1024d..bac402efcc2 100644 --- a/packages/dd-trace/test/dogstatsd.spec.js +++ b/packages/dd-trace/test/dogstatsd.spec.js @@ -378,6 +378,7 @@ 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() @@ -385,6 +386,7 @@ describe('dogstatsd', () => { 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') }) @@ -415,6 +417,7 @@ 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() @@ -422,6 +425,7 @@ describe('dogstatsd', () => { 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') }) @@ -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() @@ -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') })