Skip to content

Commit 3da675e

Browse files
authored
[DI] Don't set empty dd tags as query params (#5624)
When sending collected data to the agent, we augment it by setting dd-tags on the URL as query params. Some of these dd-tags are fetched from environment variables, which might not be set. If that's the case, don't set the corresponding dd-tags as they are just wasting space in the URL and might lead to hard to debug issues in the backend/UI.
1 parent 2b1cb78 commit 3da675e

File tree

2 files changed

+70
-41
lines changed

2 files changed

+70
-41
lines changed

integration-tests/debugger/ddtags.spec.js

Lines changed: 69 additions & 40 deletions
Original file line numberDiff line numberDiff line change
@@ -8,49 +8,78 @@ const { version } = require('../../package.json')
88

99
describe('Dynamic Instrumentation', function () {
1010
describe('ddtags', function () {
11-
const t = setup({
12-
env: {
13-
DD_ENV: 'test-env',
14-
DD_VERSION: 'test-version',
15-
DD_GIT_COMMIT_SHA: 'test-commit-sha',
16-
DD_GIT_REPOSITORY_URL: 'test-repository-url'
17-
},
18-
testApp: 'target-app/basic.js'
19-
})
11+
describe('basic case', function () {
12+
const t = setup({
13+
env: {
14+
DD_ENV: 'test-env',
15+
DD_VERSION: 'test-version',
16+
DD_GIT_COMMIT_SHA: 'test-commit-sha',
17+
DD_GIT_REPOSITORY_URL: 'test-repository-url'
18+
},
19+
testApp: 'target-app/basic.js'
20+
})
21+
22+
it('should add the expected ddtags as a query param to /debugger/v1/input', function (done) {
23+
t.triggerBreakpoint()
24+
25+
t.agent.on('debugger-input', ({ query }) => {
26+
assert.property(query, 'ddtags')
27+
28+
const ddtags = extractDDTagsFromQuery(query)
2029

21-
it('should add the expected ddtags as a query param to /debugger/v1/input', function (done) {
22-
t.triggerBreakpoint()
23-
24-
t.agent.on('debugger-input', ({ query }) => {
25-
assert.property(query, 'ddtags')
26-
27-
// Before: "a:b,c:d"
28-
// After: { a: 'b', c: 'd' }
29-
const ddtags = query.ddtags
30-
.split(',')
31-
.map((tag) => tag.split(':'))
32-
.reduce((acc, [k, v]) => { acc[k] = v; return acc }, {})
33-
34-
assert.hasAllKeys(ddtags, [
35-
'env',
36-
'version',
37-
'debugger_version',
38-
'host_name',
39-
'git.commit.sha',
40-
'git.repository_url'
41-
])
42-
43-
assert.strictEqual(ddtags.env, 'test-env')
44-
assert.strictEqual(ddtags.version, 'test-version')
45-
assert.strictEqual(ddtags.debugger_version, version)
46-
assert.strictEqual(ddtags.host_name, os.hostname())
47-
assert.strictEqual(ddtags['git.commit.sha'], 'test-commit-sha')
48-
assert.strictEqual(ddtags['git.repository_url'], 'test-repository-url')
49-
50-
done()
30+
assert.hasAllKeys(ddtags, [
31+
'env',
32+
'version',
33+
'debugger_version',
34+
'host_name',
35+
'git.commit.sha',
36+
'git.repository_url'
37+
])
38+
39+
assert.strictEqual(ddtags.env, 'test-env')
40+
assert.strictEqual(ddtags.version, 'test-version')
41+
assert.strictEqual(ddtags.debugger_version, version)
42+
assert.strictEqual(ddtags.host_name, os.hostname())
43+
assert.strictEqual(ddtags['git.commit.sha'], 'test-commit-sha')
44+
assert.strictEqual(ddtags['git.repository_url'], 'test-repository-url')
45+
46+
done()
47+
})
48+
49+
t.agent.addRemoteConfig(t.rcConfig)
5150
})
51+
})
5252

53-
t.agent.addRemoteConfig(t.rcConfig)
53+
describe('with undefined values', function () {
54+
const t = setup({ testApp: 'target-app/basic.js' })
55+
56+
it('should not include undefined values in the ddtags query param', function (done) {
57+
t.triggerBreakpoint()
58+
59+
t.agent.on('debugger-input', ({ query }) => {
60+
assert.property(query, 'ddtags')
61+
62+
const ddtags = extractDDTagsFromQuery(query)
63+
64+
assert.hasAllKeys(ddtags, [
65+
'debugger_version',
66+
'host_name'
67+
])
68+
69+
done()
70+
})
71+
72+
t.agent.addRemoteConfig(t.rcConfig)
73+
})
5474
})
5575
})
5676
})
77+
78+
// Before: "a:b,c:d"
79+
// After: { a: 'b', c: 'd' }
80+
function extractDDTagsFromQuery (query) {
81+
return query.ddtags
82+
.split(',')
83+
.map((tag) => tag.split(':'))
84+
.reduce((acc, [k, v]) => { acc[k] = v; return acc }, {})
85+
}

packages/dd-trace/src/debugger/devtools_client/send.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -26,7 +26,7 @@ const ddtags = [
2626
['host_name', hostname],
2727
[GIT_COMMIT_SHA, config.commitSHA],
2828
[GIT_REPOSITORY_URL, config.repositoryUrl]
29-
].map((pair) => pair.join(':')).join(',')
29+
].filter(([, value]) => value !== undefined).map((pair) => pair.join(':')).join(',')
3030

3131
const path = `/debugger/v1/input?${stringify({ ddtags })}`
3232

0 commit comments

Comments
 (0)