Skip to content

Commit 0db0d25

Browse files
github-actions[bot]P403n1x87mabdinur
authored
fix(rcm): add git metadata to requests [backport 1.20] (#7152)
Backport 251e611 from #7119 to 1.20. We make sure that git metadata is added to the tags when making requests for configuration to the agent. This allows SCI to work as expected with services that rely on the git metadata to be transmitted with RC requests. We also add the tags to every DI upload. ## Testing strategy This will be covered by system tests. ## Checklist - [x] Change(s) are motivated and described in the PR description. - [x] Testing strategy is described if automated tests are not included in the PR. - [x] Risk is outlined (performance impact, potential for breakage, maintainability, etc). - [x] Change is maintainable (easy to change, telemetry, documentation). - [x] [Library release note guidelines](https://ddtrace.readthedocs.io/en/stable/releasenotes.html) are followed. If no release note is required, add label `changelog/no-changelog`. - [x] Documentation is included (in-code, generated user docs, [public corp docs](https://github.com/DataDog/documentation/)). - [x] Backport labels are set (if [applicable](https://ddtrace.readthedocs.io/en/latest/contributing.html#backporting)) ## Reviewer Checklist - [x] Title is accurate. - [x] No unnecessary changes are introduced. - [x] Description motivates each change. - [x] Avoids breaking [API](https://ddtrace.readthedocs.io/en/stable/versioning.html#interfaces) changes unless absolutely necessary. - [x] Testing strategy adequately addresses listed risk(s). - [x] Change is maintainable (easy to change, telemetry, documentation). - [x] Release note makes sense to a user of the library. - [x] Reviewer has explicitly acknowledged and discussed the performance implications of this PR as reported in the benchmarks PR comment. - [x] Backport labels are set in a manner that is consistent with the [release branch maintenance policy](https://ddtrace.readthedocs.io/en/latest/contributing.html#backporting) - [x] If this PR touches code that signs or publishes builds or packages, or handles credentials of any kind, I've requested a review from `@DataDog/security-design-and-guidance`. - [x] This PR doesn't touch any of that. Co-authored-by: Gabriele N. Tornetta <[email protected]> Co-authored-by: Munir Abdinur <[email protected]>
1 parent 1784e67 commit 0db0d25

File tree

4 files changed

+28
-1
lines changed

4 files changed

+28
-1
lines changed

ddtrace/internal/gitmetadata.py

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -124,3 +124,15 @@ def clean_tags(tags):
124124
tags.pop(COMMIT_SHA, None)
125125

126126
return tags
127+
128+
129+
def add_tags(tags):
130+
clean_tags(tags)
131+
132+
repository_url, commit_sha = get_git_tags()
133+
134+
if repository_url:
135+
tags[REPOSITORY_URL] = repository_url
136+
137+
if commit_sha:
138+
tags[COMMIT_SHA] = commit_sha

ddtrace/internal/remoteconfig/client.py

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -21,6 +21,7 @@
2121
import ddtrace
2222
from ddtrace.appsec._capabilities import _appsec_rc_capabilities
2323
from ddtrace.internal import agent
24+
from ddtrace.internal import gitmetadata
2425
from ddtrace.internal import runtime
2526
from ddtrace.internal.hostname import get_hostname
2627
from ddtrace.internal.logger import get_logger
@@ -176,6 +177,10 @@ def __init__(self):
176177
self._headers["Datadog-Container-Id"] = container_id
177178

178179
tags = ddtrace.config.tags.copy()
180+
181+
# Add git metadata tags, if available
182+
gitmetadata.add_tags(tags)
183+
179184
if ddtrace.config.env:
180185
tags["env"] = ddtrace.config.env
181186
if ddtrace.config.version:

ddtrace/settings/dynamic_instrumentation.py

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,8 @@
11
from envier import En
22

3+
from ddtrace.internal import gitmetadata
34
from ddtrace.internal.agent import get_trace_url
5+
from ddtrace.internal.compat import ensure_str
46
from ddtrace.internal.constants import DEFAULT_SERVICE_NAME
57
from ddtrace.internal.utils.config import get_application_name
68
from ddtrace.settings import _config as ddconfig
@@ -16,7 +18,10 @@ def _derive_tags(c):
1618
_tags = dict(env=ddconfig.env, version=ddconfig.version, debugger_version=get_version())
1719
_tags.update(ddconfig.tags)
1820

19-
return ",".join([":".join((k, v)) for (k, v) in _tags.items() if v is not None])
21+
# Add git metadata tags, if available
22+
gitmetadata.add_tags(_tags)
23+
# ensure_str is needed for Python 2 compatibility
24+
return ensure_str(",".join([":".join((k, v)) for (k, v) in _tags.items() if v is not None]))
2025

2126

2227
class DynamicInstrumentationConfig(En):
Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
---
2+
fixes:
3+
- |
4+
remote config: Add git metadata to configuration requests to ensure Source
5+
Code Integration (SCI) works as expected with services that require it.

0 commit comments

Comments
 (0)