Skip to content

Commit 3798033

Browse files
authored
[DI] Attach ddtags to probe results (#5042)
The following extra information is added to each probe result: - `env` - From the `DD_ENV` environment variable - `version` - From the `DD_VERSION` environment variable - `debugger_version` - The version of the tracing lib - `host_name` - The hostname that application is running on The `agent_version` is not added in this commit, but will be come later.
1 parent 4f87373 commit 3798033

File tree

5 files changed

+79
-15
lines changed

5 files changed

+79
-15
lines changed

integration-tests/debugger/basic.spec.js

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -428,7 +428,7 @@ describe('Dynamic Instrumentation', function () {
428428
})
429429

430430
describe('DD_TRACING_ENABLED=true, DD_TRACE_128_BIT_TRACEID_GENERATION_ENABLED=true', function () {
431-
const t = setup({ DD_TRACING_ENABLED: true, DD_TRACE_128_BIT_TRACEID_GENERATION_ENABLED: true })
431+
const t = setup({ env: { DD_TRACING_ENABLED: true, DD_TRACE_128_BIT_TRACEID_GENERATION_ENABLED: true } })
432432

433433
describe('input messages', function () {
434434
it(
@@ -439,7 +439,7 @@ describe('Dynamic Instrumentation', function () {
439439
})
440440

441441
describe('DD_TRACING_ENABLED=true, DD_TRACE_128_BIT_TRACEID_GENERATION_ENABLED=false', function () {
442-
const t = setup({ DD_TRACING_ENABLED: true, DD_TRACE_128_BIT_TRACEID_GENERATION_ENABLED: false })
442+
const t = setup({ env: { DD_TRACING_ENABLED: true, DD_TRACE_128_BIT_TRACEID_GENERATION_ENABLED: false } })
443443

444444
describe('input messages', function () {
445445
it(
@@ -450,7 +450,7 @@ describe('Dynamic Instrumentation', function () {
450450
})
451451

452452
describe('DD_TRACING_ENABLED=false', function () {
453-
const t = setup({ DD_TRACING_ENABLED: false })
453+
const t = setup({ env: { DD_TRACING_ENABLED: false } })
454454

455455
describe('input messages', function () {
456456
it(
Lines changed: 56 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,56 @@
1+
'use strict'
2+
3+
const os = require('os')
4+
5+
const { assert } = require('chai')
6+
const { setup } = require('./utils')
7+
const { version } = require('../../package.json')
8+
9+
describe('Dynamic Instrumentation', function () {
10+
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+
})
20+
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()
51+
})
52+
53+
t.agent.addRemoteConfig(t.rcConfig)
54+
})
55+
})
56+
})

integration-tests/debugger/utils.js

Lines changed: 14 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -18,9 +18,9 @@ module.exports = {
1818
setup
1919
}
2020

21-
function setup (env) {
21+
function setup ({ env, testApp } = {}) {
2222
let sandbox, cwd, appPort
23-
const breakpoints = getBreakpointInfo(1) // `1` to disregard the `setup` function
23+
const breakpoints = getBreakpointInfo({ file: testApp, stackIndex: 1 }) // `1` to disregard the `setup` function
2424
const t = {
2525
breakpoint: breakpoints[0],
2626
breakpoints,
@@ -108,16 +108,18 @@ function setup (env) {
108108
return t
109109
}
110110

111-
function getBreakpointInfo (stackIndex = 0) {
112-
// First, get the filename of file that called this function
113-
const testFile = new Error().stack
114-
.split('\n')[stackIndex + 2] // +2 to skip this function + the first line, which is the error message
115-
.split(' (')[1]
116-
.slice(0, -1)
117-
.split(':')[0]
118-
119-
// Then, find the corresponding file in which the breakpoint(s) exists
120-
const file = join('target-app', basename(testFile).replace('.spec', ''))
111+
function getBreakpointInfo ({ file, stackIndex = 0 }) {
112+
if (!file) {
113+
// First, get the filename of file that called this function
114+
const testFile = new Error().stack
115+
.split('\n')[stackIndex + 2] // +2 to skip this function + the first line, which is the error message
116+
.split(' (')[1]
117+
.slice(0, -1)
118+
.split(':')[0]
119+
120+
// Then, find the corresponding file in which the breakpoint(s) exists
121+
file = join('target-app', basename(testFile).replace('.spec', ''))
122+
}
121123

122124
// Finally, find the line number(s) of the breakpoint(s)
123125
const lines = readFileSync(join(__dirname, file), 'utf8').split('\n')

integration-tests/helpers/fake-agent.js

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -326,6 +326,7 @@ function buildExpressServer (agent) {
326326
res.status(200).send()
327327
agent.emit('debugger-input', {
328328
headers: req.headers,
329+
query: req.query,
329330
payload: req.body
330331
})
331332
})

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

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,7 @@ const { stringify } = require('querystring')
66
const config = require('./config')
77
const request = require('../../exporters/common/request')
88
const { GIT_COMMIT_SHA, GIT_REPOSITORY_URL } = require('../../plugins/util/tags')
9+
const { version } = require('../../../../../package.json')
910

1011
module.exports = send
1112

@@ -16,6 +17,10 @@ const hostname = getHostname()
1617
const service = config.service
1718

1819
const ddtags = [
20+
['env', process.env.DD_ENV],
21+
['version', process.env.DD_VERSION],
22+
['debugger_version', version],
23+
['host_name', hostname],
1924
[GIT_COMMIT_SHA, config.commitSHA],
2025
[GIT_REPOSITORY_URL, config.repositoryUrl]
2126
].map((pair) => pair.join(':')).join(',')

0 commit comments

Comments
 (0)