diff --git a/ddtrace/internal/remoteconfig/client.py b/ddtrace/internal/remoteconfig/client.py index f622a367ac5..d01da373a72 100644 --- a/ddtrace/internal/remoteconfig/client.py +++ b/ddtrace/internal/remoteconfig/client.py @@ -199,15 +199,33 @@ def __init__(self): if container_id is not None: self._headers["Datadog-Container-Id"] = container_id + # The library uses a PEP 440-compliant versioning scheme, but the + # RCM spec requires that we use a SemVer-compliant version. + # + # However, we may have versions like: + # + # - 1.7.1.dev3+gf258c7d9 + # - 1.7.1rc2.dev3+gf258c7d9 + # + # Which are not Semver-compliant. + # + # The easiest fix is to replace the first occurrence of "rc" or + # ".dev" with "-rc" or "-dev" to make them compliant. + # + # Other than X.Y.Z, we are allowed `-+` + # https://semver.org/#backusnaur-form-grammar-for-valid-semver-versions + # + # e.g. 1.7.1-rc2.dev3+gf258c7d9 is valid + tracer_version = ddtrace.__version__ + if "rc" in tracer_version: + tracer_version = tracer_version.replace("rc", "-rc", 1) + elif ".dev" in tracer_version: + tracer_version = tracer_version.replace(".dev", "-dev", 1) + self._client_tracer = dict( runtime_id=runtime.get_runtime_id(), language="python", - # The library uses a PEP 440-compliant versioning scheme, but the - # RCM spec requires that we use a SemVer-compliant version. We only - # expect that the first occurrence of "rc" in the version string to - # break the SemVer format, so we replace it with "-rc" for - # simplicity. - tracer_version=ddtrace.__version__.replace("rc", "-rc", 1), + tracer_version=tracer_version, service=ddtrace.config.service, env=ddtrace.config.env, app_version=ddtrace.config.version,