Skip to content

Commit 68dc67c

Browse files
authored
feat: process tags for client trace statistics (#7177)
1 parent 4236d96 commit 68dc67c

5 files changed

Lines changed: 19 additions & 8 deletions

File tree

packages/dd-trace/src/encode/span-stats.js

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -95,7 +95,7 @@ class SpanStatsEncoder extends AgentEncoder {
9595
}
9696

9797
_encode (bytes, stats) {
98-
this._encodeMapPrefix(bytes, 8)
98+
this._encodeMapPrefix(bytes, stats.ProcessTags ? 9 : 8)
9999

100100
this._encodeString(bytes, 'Hostname')
101101
this._encodeString(bytes, stats.Hostname)
@@ -123,6 +123,11 @@ class SpanStatsEncoder extends AgentEncoder {
123123

124124
this._encodeString(bytes, 'Sequence')
125125
this._encodeLong(bytes, stats.Sequence)
126+
127+
if (stats.ProcessTags) {
128+
this._encodeString(bytes, 'ProcessTags')
129+
this._encodeString(bytes, stats.ProcessTags)
130+
}
126131
}
127132
}
128133

packages/dd-trace/src/process-tags/index.js

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -66,8 +66,7 @@ module.exports.DYNAMIC_INSTRUMENTATION_FIELD_NAME = 'process_tags'
6666
module.exports.TELEMETRY_FIELD_NAME = 'process_tags'
6767
module.exports.REMOTE_CONFIG_FIELD_NAME = 'process_tags'
6868
module.exports.CRASH_TRACKING_FIELD_NAME = 'process_tags'
69-
70-
// TODO: CLIENT_TRACE_STATISTICS_FIELD_NAME process_tags
69+
module.exports.CLIENT_TRACE_STATISTICS_FIELD_NAME = 'ProcessTags'
7170

7271
/**
7372
* Sanitize a process tag value

packages/dd-trace/src/span_stats.js

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
'use strict'
22

3-
const os = require('os')
3+
const os = require('node:os')
44
const pkg = require('../../../package.json')
55

66
const { LogCollapsingLowestDenseDDSketch } = require('../../../vendor/dist/@datadog/sketches-js')
@@ -13,6 +13,7 @@ const {
1313
} = require('../../../ext/tags')
1414
const { ORIGIN_KEY, TOP_LEVEL_KEY } = require('./constants')
1515
const { version } = require('./pkg')
16+
const processTags = require('./process-tags')
1617

1718
const { SpanStatsExporter } = require('./exporters/span-stats')
1819

@@ -176,7 +177,8 @@ class SpanStatsProcessor {
176177
Lang: 'javascript',
177178
TracerVersion: pkg.version,
178179
RuntimeID: this.tags['runtime-id'],
179-
Sequence: ++this.sequence
180+
Sequence: ++this.sequence,
181+
ProcessTags: processTags.serialized
180182
})
181183
}
182184

packages/dd-trace/test/encode/span-stats.spec.js

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -17,6 +17,7 @@ const {
1717
DEFAULT_SPAN_NAME,
1818
DEFAULT_SERVICE_NAME
1919
} = require('../../src/encode/tags-processors')
20+
const processTags = require('../../src/process-tags')
2021

2122
describe('span-stats-encode', () => {
2223
let encoder
@@ -71,7 +72,8 @@ describe('span-stats-encode', () => {
7172
Lang: 'javascript',
7273
TracerVersion: '1.2.3',
7374
RuntimeID: 'some-runtime-id',
74-
Sequence: 1
75+
Sequence: 1,
76+
ProcessTags: processTags.serialized
7577
}
7678
})
7779

packages/dd-trace/test/span_stats.spec.js

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -24,6 +24,7 @@ const {
2424
DEFAULT_SPAN_NAME,
2525
DEFAULT_SERVICE_NAME
2626
} = require('../src/encode/tags-processors')
27+
const processTags = require('../src/process-tags')
2728

2829
// Mock spans
2930
const basicSpan = {
@@ -388,7 +389,8 @@ describe('SpanStatsProcessor', () => {
388389
Lang: 'javascript',
389390
TracerVersion: pkg.version,
390391
RuntimeID: processor.tags['runtime-id'],
391-
Sequence: processor.sequence
392+
Sequence: processor.sequence,
393+
ProcessTags: processTags.serialized
392394
}))
393395
})
394396

@@ -406,7 +408,8 @@ describe('SpanStatsProcessor', () => {
406408
Lang: 'javascript',
407409
TracerVersion: pkg.version,
408410
RuntimeID: processor.tags['runtime-id'],
409-
Sequence: processor.sequence
411+
Sequence: processor.sequence,
412+
ProcessTags: processTags.serialized
410413
}))
411414
})
412415
})

0 commit comments

Comments
 (0)