From 1740079c97289ac2344229714fea01fb61fb9196 Mon Sep 17 00:00:00 2001 From: Thomas Watson Date: Tue, 7 Jan 2025 10:51:34 +0100 Subject: [PATCH] Send tags, including git metadata, to RC endpoint (#5070) In requests to the RC endpoint, add dd tags, including dd tags containing git metadata. --- .../src/appsec/remote_config/manager.js | 12 +++++++++++- .../test/appsec/remote_config/manager.spec.js | 17 ++++++++++++++++- 2 files changed, 27 insertions(+), 2 deletions(-) diff --git a/packages/dd-trace/src/appsec/remote_config/manager.js b/packages/dd-trace/src/appsec/remote_config/manager.js index 75c72690503..19ed709b27f 100644 --- a/packages/dd-trace/src/appsec/remote_config/manager.js +++ b/packages/dd-trace/src/appsec/remote_config/manager.js @@ -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() @@ -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() @@ -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()` }, diff --git a/packages/dd-trace/test/appsec/remote_config/manager.spec.js b/packages/dd-trace/test/appsec/remote_config/manager.spec.js index 2a32e834e06..8d0c82d0dc9 100644 --- a/packages/dd-trace/test/appsec/remote_config/manager.spec.js +++ b/packages/dd-trace/test/appsec/remote_config/manager.spec.js @@ -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==' }, @@ -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)