Skip to content

Commit 11e33bf

Browse files
authored
Fix: updating remote config manager to send process_tags as an array (#7180)
* updating remote config manager to use tagsArray and test to expect an array * removing serialize function and corresponding tests since it is no longer used.
1 parent d401472 commit 11e33bf

5 files changed

Lines changed: 26 additions & 119 deletions

File tree

integration-tests/remote_config.spec.js

Lines changed: 7 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -56,22 +56,17 @@ describe('Remote config client id', () => {
5656

5757
const processTags = client.client_tracer.process_tags
5858

59-
// Verify process_tags is an object
60-
assert.strictEqual(typeof processTags, 'object')
59+
// Verify process_tags is an array of strings
60+
assert.ok(Array.isArray(processTags), 'process_tags should be an array')
6161

6262
// Verify required process tags are present
63-
assert.ok('entrypoint.basedir' in processTags)
64-
assert.ok('entrypoint.name' in processTags)
65-
assert.ok('entrypoint.type' in processTags)
66-
assert.ok('entrypoint.workdir' in processTags)
63+
assert.ok(processTags.some(tag => tag.startsWith('entrypoint.basedir:')))
64+
assert.ok(processTags.some(tag => tag.startsWith('entrypoint.name:')))
65+
assert.ok(processTags.some(tag => tag.startsWith('entrypoint.type:')))
66+
assert.ok(processTags.some(tag => tag.startsWith('entrypoint.workdir:')))
6767

6868
// Verify entrypoint.type has the expected value
69-
assert.strictEqual(processTags['entrypoint.type'], 'script')
70-
71-
// Verify values are strings (not undefined)
72-
assert.strictEqual(typeof processTags['entrypoint.name'], 'string')
73-
assert.strictEqual(typeof processTags['entrypoint.workdir'], 'string')
74-
assert.strictEqual(typeof processTags['entrypoint.basedir'], 'string')
69+
assert.ok(processTags.some(tag => tag === 'entrypoint.type:script'))
7570
done()
7671
} catch (err) {
7772
done(err)

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

Lines changed: 11 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -35,19 +35,24 @@ function getProcessTags () {
3535
['package.json.name', pkg.name || undefined]
3636
]
3737

38-
const serialized = serialize(tags)
38+
const tagsArray = []
39+
const tagsObject = {}
3940

40-
const tagsObject = tags.reduce((acc, [key, value]) => {
41+
for (const [key, value] of tags) {
4142
if (value !== undefined) {
42-
acc[key] = value
43+
const sanitizedValue = sanitize(value)
44+
tagsArray.push(`${key}:${sanitizedValue}`)
45+
tagsObject[key] = sanitizedValue
4346
}
44-
return acc
45-
}, {})
47+
}
48+
49+
const serialized = tagsArray.join(',')
4650

4751
return {
4852
tags,
4953
serialized,
50-
tagsObject
54+
tagsObject,
55+
tagsArray
5156
}
5257
}
5358

@@ -64,17 +69,6 @@ module.exports.CRASH_TRACKING_FIELD_NAME = 'process_tags'
6469

6570
// TODO: CLIENT_TRACE_STATISTICS_FIELD_NAME process_tags
6671

67-
function serialize (tags) {
68-
const intermediary = []
69-
for (const [name, value] of tags) {
70-
if (value === undefined) continue
71-
intermediary.push(`${name}:${sanitize(value)}`)
72-
}
73-
return intermediary.join(',')
74-
}
75-
76-
module.exports.serialize = serialize
77-
7872
/**
7973
* Sanitize a process tag value
8074
*

packages/dd-trace/src/remote_config/manager.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -89,7 +89,7 @@ class RemoteConfigManager extends EventEmitter {
8989
app_version: config.version,
9090
extra_services: [],
9191
tags: Object.entries(tags).map((pair) => pair.join(':')),
92-
[processTags.REMOTE_CONFIG_FIELD_NAME]: processTags.tagsObject
92+
[processTags.REMOTE_CONFIG_FIELD_NAME]: processTags.tagsArray
9393
},
9494
capabilities: DEFAULT_CAPABILITY // updated by `updateCapabilities()`
9595
},

packages/dd-trace/test/process-tags.spec.js

Lines changed: 1 addition & 83 deletions
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,7 @@ require('./setup/core')
99

1010
describe('process-tags', () => {
1111
const processTags = require('../src/process-tags')
12-
const { serialize, sanitize } = require('../src/process-tags')
12+
const { sanitize } = require('../src/process-tags')
1313

1414
describe('field name constants', () => {
1515
it('should define field names for different subsystems', () => {
@@ -125,88 +125,6 @@ describe('process-tags', () => {
125125
})
126126
})
127127

128-
describe('serialize', () => {
129-
it('should serialize tags as name:value pairs joined by commas', () => {
130-
const tags = [
131-
['tag1', 'value1'],
132-
['tag2', 'value2'],
133-
['tag3', 'value3']
134-
]
135-
136-
const result = serialize(tags)
137-
138-
assert.strictEqual(result, 'tag1:value1,tag2:value2,tag3:value3')
139-
})
140-
141-
it('should filter out tags with undefined values', () => {
142-
const tags = [
143-
['tag1', 'value1'],
144-
['tag2', undefined],
145-
['tag3', 'value3'],
146-
['tag4', undefined]
147-
]
148-
149-
const result = serialize(tags)
150-
151-
assert.strictEqual(result, 'tag1:value1,tag3:value3')
152-
assert.doesNotMatch(result, /undefined/)
153-
})
154-
155-
it('should sanitize tag values', () => {
156-
const tags = [
157-
['tag1', 'Value With Spaces'],
158-
['tag2', 'UPPERCASE'],
159-
['tag3', 'special@chars!']
160-
]
161-
162-
const result = serialize(tags)
163-
164-
assert.strictEqual(result, 'tag1:value_with_spaces,tag2:uppercase,tag3:special_chars_')
165-
})
166-
167-
it('should return empty string when all values are undefined', () => {
168-
const tags = [
169-
['tag1', undefined],
170-
['tag2', undefined]
171-
]
172-
173-
const result = serialize(tags)
174-
175-
assert.strictEqual(result, '')
176-
})
177-
178-
it('should handle empty tags array', () => {
179-
const result = serialize([])
180-
181-
assert.strictEqual(result, '')
182-
})
183-
184-
it('should handle numeric values', () => {
185-
const tags = [
186-
['tag1', 123],
187-
['tag2', 456]
188-
]
189-
190-
const result = serialize(tags)
191-
192-
assert.strictEqual(result, 'tag1:123,tag2:456')
193-
})
194-
195-
it('should handle mixed defined and undefined values', () => {
196-
const tags = [
197-
['tag1', 'value1'],
198-
['tag2', undefined],
199-
['tag3', 'value3'],
200-
['tag4', undefined],
201-
['tag5', 'value5']
202-
]
203-
204-
const result = serialize(tags)
205-
206-
assert.strictEqual(result, 'tag1:value1,tag3:value3,tag5:value5')
207-
})
208-
})
209-
210128
describe('sanitize', () => {
211129
it('should convert to lowercase', () => {
212130
assert.strictEqual(sanitize('UPPERCASE'), 'uppercase')

packages/dd-trace/test/remote_config/manager.spec.js

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -132,16 +132,16 @@ describe('RemoteConfigManager', () => {
132132
const clientTracer = rc.state.client.client_tracer
133133

134134
assert.ok(clientTracer.process_tags, 'process_tags should exist')
135-
assert.strictEqual(typeof clientTracer.process_tags, 'object')
135+
assert.ok(Array.isArray(clientTracer.process_tags), 'process_tags should be an array')
136136

137137
// Verify expected process tag keys are present
138-
assert.ok('entrypoint.basedir' in clientTracer.process_tags)
139-
assert.ok('entrypoint.name' in clientTracer.process_tags)
140-
assert.ok('entrypoint.type' in clientTracer.process_tags)
141-
assert.ok('entrypoint.workdir' in clientTracer.process_tags)
138+
assert.ok(clientTracer.process_tags.some(tag => tag.startsWith('entrypoint.basedir:')))
139+
assert.ok(clientTracer.process_tags.some(tag => tag.startsWith('entrypoint.name:')))
140+
assert.ok(clientTracer.process_tags.some(tag => tag.startsWith('entrypoint.type:')))
141+
assert.ok(clientTracer.process_tags.some(tag => tag.startsWith('entrypoint.workdir:')))
142142

143143
// Verify entrypoint.type has expected value
144-
assert.strictEqual(clientTracer.process_tags['entrypoint.type'], 'script')
144+
assert.ok(clientTracer.process_tags.some(tag => tag === 'entrypoint.type:script'))
145145
})
146146

147147
it('should add git metadata to tags if present', () => {

0 commit comments

Comments
 (0)