Skip to content

Commit e4bf59a

Browse files
IlyasShabisimon-id
andauthored
report rc.client_id tag when rc is enabled (#5467)
* report rc.client_id tag when rc is enabled * report client id within rc manager * add integration test * linter * remove getClientId from test * Update packages/dd-trace/test/remote_config/rc-client_id.spec.js --------- Co-authored-by: simon-id <simon.id@datadoghq.com>
1 parent 762e2cf commit e4bf59a

File tree

4 files changed

+125
-0
lines changed

4 files changed

+125
-0
lines changed

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

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -10,6 +10,7 @@ const { getExtraServices } = require('../service-naming/extra-services')
1010
const { UNACKNOWLEDGED, ACKNOWLEDGED, ERROR } = require('./apply_states')
1111
const Scheduler = require('./scheduler')
1212
const { GIT_REPOSITORY_URL, GIT_COMMIT_SHA } = require('../plugins/util/tags')
13+
const tagger = require('../tagger')
1314

1415
const clientId = uuid()
1516

@@ -34,6 +35,10 @@ class RemoteConfigManager extends EventEmitter {
3435
port: config.port
3536
}))
3637

38+
tagger.add(config.tags, {
39+
'_dd.rc.client_id': clientId
40+
})
41+
3742
const tags = config.repositoryUrl
3843
? {
3944
...config.tags,

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

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -15,6 +15,7 @@ describe('RemoteConfigManager', () => {
1515
let RemoteConfigManager
1616
let config
1717
let rc
18+
let tagger
1819

1920
beforeEach(() => {
2021
uuid = sinon.stub().returns('1234-5678')
@@ -32,6 +33,10 @@ describe('RemoteConfigManager', () => {
3233
error: sinon.spy()
3334
}
3435

36+
tagger = {
37+
add: sinon.stub()
38+
}
39+
3540
extraServices = []
3641

3742
RemoteConfigManager = proxyquire('../src/remote_config/manager', {
@@ -40,6 +45,7 @@ describe('RemoteConfigManager', () => {
4045
'../../../../../package.json': { version: '3.0.0' },
4146
'../../exporters/common/request': request,
4247
'../../log': log,
48+
'../tagger': tagger,
4349
'../../service-naming/extra-services': {
4450
getExtraServices: () => extraServices
4551
}
@@ -78,6 +84,10 @@ describe('RemoteConfigManager', () => {
7884

7985
expect(rc.url).to.deep.equal(config.url)
8086

87+
expect(tagger.add).to.have.been.calledOnceWithExactly(config.tags, {
88+
'_dd.rc.client_id': '1234-5678'
89+
})
90+
8191
expect(rc.state).to.deep.equal({
8292
client: {
8393
state: {
Lines changed: 91 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,91 @@
1+
'use strict'
2+
3+
const { createSandbox, FakeAgent, spawnProc } = require('../../../../integration-tests/helpers')
4+
const getPort = require('get-port')
5+
const path = require('path')
6+
const Axios = require('axios')
7+
const { assert } = require('chai')
8+
9+
describe('Remote config client id', () => {
10+
let axios, sandbox, cwd, appPort, appFile
11+
12+
before(async function () {
13+
this.timeout(process.platform === 'win32' ? 90000 : 30000)
14+
15+
sandbox = await createSandbox(
16+
['express'],
17+
false,
18+
[path.join(__dirname, 'resources')]
19+
)
20+
21+
appPort = await getPort()
22+
cwd = sandbox.folder
23+
appFile = path.join(cwd, 'resources', 'index.js')
24+
25+
axios = Axios.create({
26+
baseURL: `http://localhost:${appPort}`
27+
})
28+
})
29+
30+
after(async function () {
31+
this.timeout(60000)
32+
await sandbox.remove()
33+
})
34+
35+
describe('enabled', () => {
36+
let agent, proc
37+
38+
beforeEach(async () => {
39+
agent = await new FakeAgent().start()
40+
proc = await spawnProc(appFile, {
41+
cwd,
42+
env: {
43+
DD_TRACE_AGENT_PORT: agent.port,
44+
APP_PORT: appPort
45+
}
46+
})
47+
})
48+
49+
afterEach(async () => {
50+
proc.kill()
51+
await agent.stop()
52+
})
53+
54+
it('should add client_id tag when remote config is enabled', async () => {
55+
await axios.get('/')
56+
57+
return agent.assertMessageReceived(({ payload }) => {
58+
assert.exists(payload[0][0].meta['_dd.rc.client_id'])
59+
})
60+
})
61+
})
62+
63+
describe('disabled', () => {
64+
let agent, proc
65+
66+
beforeEach(async () => {
67+
agent = await new FakeAgent().start()
68+
proc = await spawnProc(appFile, {
69+
cwd,
70+
env: {
71+
DD_TRACE_AGENT_PORT: agent.port,
72+
APP_PORT: appPort,
73+
DD_REMOTE_CONFIGURATION_ENABLED: false
74+
}
75+
})
76+
})
77+
78+
afterEach(async () => {
79+
proc.kill()
80+
await agent.stop()
81+
})
82+
83+
it('should not add client_id tag when remote config is disbaled', async () => {
84+
await axios.get('/')
85+
86+
return agent.assertMessageReceived(({ payload }) => {
87+
assert.notExists(payload[0][0].meta['_dd.rc.client_id'])
88+
})
89+
})
90+
})
91+
})
Lines changed: 19 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,19 @@
1+
'use strict'
2+
3+
const tracer = require('dd-trace')
4+
tracer.init({
5+
flushInterval: 1
6+
})
7+
8+
const express = require('express')
9+
10+
const app = express()
11+
const port = process.env.APP_PORT || 3000
12+
13+
app.get('/', async (req, res) => {
14+
res.end('OK')
15+
})
16+
17+
app.listen(port, () => {
18+
process.send({ port })
19+
})

0 commit comments

Comments
 (0)