Skip to content

Commit

Permalink
Send tags, including git metadata, to RC endpoint (#5070)
Browse files Browse the repository at this point in the history
In requests to the RC endpoint, add dd tags, including dd tags
containing git metadata.
  • Loading branch information
watson authored Jan 7, 2025
1 parent 86c8e26 commit 1e76223
Show file tree
Hide file tree
Showing 2 changed files with 27 additions and 2 deletions.
12 changes: 11 additions & 1 deletion packages/dd-trace/src/appsec/remote_config/manager.js
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@ const log = require('../../log')
const { getExtraServices } = require('../../service-naming/extra-services')
const { UNACKNOWLEDGED, ACKNOWLEDGED, ERROR } = require('./apply_states')
const Scheduler = require('./scheduler')
const { GIT_REPOSITORY_URL, GIT_COMMIT_SHA } = require('../../plugins/util/tags')

const clientId = uuid()

Expand All @@ -33,6 +34,14 @@ class RemoteConfigManager extends EventEmitter {
port: config.port
}))

const tags = config.repositoryUrl
? {
...config.tags,
[GIT_REPOSITORY_URL]: config.repositoryUrl,
[GIT_COMMIT_SHA]: config.commitSHA
}
: config.tags

this._handlers = new Map()
const appliedConfigs = this.appliedConfigs = new Map()

Expand Down Expand Up @@ -67,7 +76,8 @@ class RemoteConfigManager extends EventEmitter {
service: config.service,
env: config.env,
app_version: config.version,
extra_services: []
extra_services: [],
tags: Object.entries(tags).map((pair) => pair.join(':'))
},
capabilities: DEFAULT_CAPABILITY // updated by `updateCapabilities()`
},
Expand Down
17 changes: 16 additions & 1 deletion packages/dd-trace/test/appsec/remote_config/manager.spec.js
Original file line number Diff line number Diff line change
Expand Up @@ -98,7 +98,8 @@ describe('RemoteConfigManager', () => {
service: config.service,
env: config.env,
app_version: config.version,
extra_services: []
extra_services: [],
tags: ['runtime-id:runtimeId']
},
capabilities: 'AA=='
},
Expand All @@ -108,6 +109,20 @@ describe('RemoteConfigManager', () => {
expect(rc.appliedConfigs).to.be.an.instanceOf(Map)
})

it('should add git metadata to tags if present', () => {
const configWithGit = {
...config,
repositoryUrl: 'https://github.com/DataDog/dd-trace-js',
commitSHA: '1234567890'
}
const rc = new RemoteConfigManager(configWithGit)
expect(rc.state.client.client_tracer.tags).to.deep.equal([
'runtime-id:runtimeId',
'git.repository_url:https://github.com/DataDog/dd-trace-js',
'git.commit.sha:1234567890'
])
})

describe('updateCapabilities', () => {
it('should set multiple capabilities to true', () => {
rc.updateCapabilities(Capabilities.ASM_ACTIVATION, true)
Expand Down

0 comments on commit 1e76223

Please sign in to comment.