Skip to content

Commit 87b1aee

Browse files
authored
fix(internal): properly convert PEP 440 version to SemVer for RCM client [backport #4910 to 1.7] (#4911)
## Description Backport of #4910 The fix for ensuring RCM used a SemVer compliant version string only took into account ddtrace versions that match `x.y.zrc2` or `x.y.zrc2.dev3+gf344hg`, but not `x.y.z.dev3+gf344hg`. This fix ensures that if we have a `.dev` without `rc` that we properly convert `.dev` -> `-dev` which will make it SemVer compliant. Since the tests rely heavily on the version of `ddtrace.__version__` writing a test is challenging. We should revisit this in the future so we can mock the version and parametrize the test to ensure all variations are tested. ## Checklist - [ ] Followed the [library release note guidelines](https://ddtrace.readthedocs.io/en/stable/contributing.html#Release-Note-Guidelines) when writing a release note. - [ ] Add additional sections for `feat` and `fix` pull requests. - [ ] [Library documentation](https://github.com/DataDog/dd-trace-py/tree/1.x/docs) and/or [Datadog's documentation site](https://github.com/DataDog/documentation/) is updated. Link to doc PR in description. ## Reviewer Checklist - [ ] Title is accurate. - [ ] Description motivates each change. - [ ] No unnecessary changes were introduced in this PR. - [ ] Avoid breaking [API](https://ddtrace.readthedocs.io/en/stable/versioning.html#interfaces) changes unless absolutely necessary. - [ ] Tests provided or description of manual testing performed is included in the code or PR. - [ ] Release note has been added and follows the [library release note guidelines](https://ddtrace.readthedocs.io/en/stable/contributing.html#Release-Note-Guidelines), or else `changelog/no-changelog` label added. - [ ] All relevant GitHub issues are correctly linked. - [ ] Backports are identified and tagged with Mergifyio.
1 parent ced65df commit 87b1aee

File tree

1 file changed

+24
-6
lines changed

1 file changed

+24
-6
lines changed

ddtrace/internal/remoteconfig/client.py

Lines changed: 24 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -199,15 +199,33 @@ def __init__(self):
199199
if container_id is not None:
200200
self._headers["Datadog-Container-Id"] = container_id
201201

202+
# The library uses a PEP 440-compliant versioning scheme, but the
203+
# RCM spec requires that we use a SemVer-compliant version.
204+
#
205+
# However, we may have versions like:
206+
#
207+
# - 1.7.1.dev3+gf258c7d9
208+
# - 1.7.1rc2.dev3+gf258c7d9
209+
#
210+
# Which are not Semver-compliant.
211+
#
212+
# The easiest fix is to replace the first occurrence of "rc" or
213+
# ".dev" with "-rc" or "-dev" to make them compliant.
214+
#
215+
# Other than X.Y.Z, we are allowed `-<dot separated pre-release>+<build identifier>`
216+
# https://semver.org/#backusnaur-form-grammar-for-valid-semver-versions
217+
#
218+
# e.g. 1.7.1-rc2.dev3+gf258c7d9 is valid
219+
tracer_version = ddtrace.__version__
220+
if "rc" in tracer_version:
221+
tracer_version = tracer_version.replace("rc", "-rc", 1)
222+
elif ".dev" in tracer_version:
223+
tracer_version = tracer_version.replace(".dev", "-dev", 1)
224+
202225
self._client_tracer = dict(
203226
runtime_id=runtime.get_runtime_id(),
204227
language="python",
205-
# The library uses a PEP 440-compliant versioning scheme, but the
206-
# RCM spec requires that we use a SemVer-compliant version. We only
207-
# expect that the first occurrence of "rc" in the version string to
208-
# break the SemVer format, so we replace it with "-rc" for
209-
# simplicity.
210-
tracer_version=ddtrace.__version__.replace("rc", "-rc", 1),
228+
tracer_version=tracer_version,
211229
service=ddtrace.config.service,
212230
env=ddtrace.config.env,
213231
app_version=ddtrace.config.version,

0 commit comments

Comments
 (0)