Skip to content

Commit

Permalink
Use DD_VERSION as version for tracer computed stats if available (#4720)
Browse files Browse the repository at this point in the history
* use DD_VERSION as version for tracer computed stats if available

* test version for tracer computed stats
  • Loading branch information
duncanpharvey committed Sep 26, 2024
1 parent 1d2543c commit c0ffabd
Show file tree
Hide file tree
Showing 2 changed files with 26 additions and 4 deletions.
6 changes: 4 additions & 2 deletions packages/dd-trace/src/span_stats.js
Original file line number Diff line number Diff line change
Expand Up @@ -127,7 +127,8 @@ class SpanStatsProcessor {
url,
env,
tags,
appsec
appsec,
version
} = {}) {
this.exporter = new SpanStatsExporter({
hostname,
Expand All @@ -143,6 +144,7 @@ class SpanStatsProcessor {
this.env = env
this.tags = tags || {}
this.sequence = 0
this.version = version

if (this.enabled) {
this.timer = setInterval(this.onInterval.bind(this), interval * 1e3)
Expand All @@ -157,7 +159,7 @@ class SpanStatsProcessor {
this.exporter.export({
Hostname: this.hostname,
Env: this.env,
Version: version,
Version: this.version || version,
Stats: serialized,
Lang: 'javascript',
TracerVersion: pkg.version,
Expand Down
24 changes: 22 additions & 2 deletions packages/dd-trace/test/span_stats.spec.js
Original file line number Diff line number Diff line change
Expand Up @@ -234,7 +234,8 @@ describe('SpanStatsProcessor', () => {
port: 8126,
url: new URL('http://127.0.0.1:8126'),
env: 'test',
tags: { tag: 'some tag' }
tags: { tag: 'some tag' },
version: '1.0.0'
}

it('should construct', () => {
Expand All @@ -253,6 +254,7 @@ describe('SpanStatsProcessor', () => {
expect(processor.enabled).to.equal(config.stats.enabled)
expect(processor.env).to.equal(config.env)
expect(processor.tags).to.deep.equal(config.tags)
expect(processor.version).to.equal(config.version)
})

it('should construct a disabled instance if appsec standalone is enabled', () => {
Expand Down Expand Up @@ -306,7 +308,7 @@ describe('SpanStatsProcessor', () => {
expect(exporter.export).to.be.calledWith({
Hostname: hostname(),
Env: config.env,
Version: version,
Version: config.version,
Stats: [{
Start: 12340000000000,
Duration: 10000000000,
Expand All @@ -331,4 +333,22 @@ describe('SpanStatsProcessor', () => {
Sequence: processor.sequence
})
})

it('should export on interval with default version', () => {
const versionlessConfig = { ...config }
delete versionlessConfig.version
const processor = new SpanStatsProcessor(versionlessConfig)
processor.onInterval()

expect(exporter.export).to.be.calledWith({
Hostname: hostname(),
Env: config.env,
Version: version,
Stats: [],
Lang: 'javascript',
TracerVersion: pkg.version,
RuntimeID: processor.tags['runtime-id'],
Sequence: processor.sequence
})
})
})

0 comments on commit c0ffabd

Please sign in to comment.