From 7e7ac2c027048788092ef2d9a064e01ad2980774 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?V=C3=ADtor=20De=20Ara=C3=BAjo?= Date: Wed, 16 Jul 2025 21:14:30 +0000 Subject: [PATCH 1/7] fix(tracer): compute trace times correctly in the presence of freezegun --- .riot/requirements/1192c19.txt | 49 +++++++++++++++++++++++++ .riot/requirements/147a53d.txt | 51 ++++++++++++++++++++++++++ .riot/requirements/152d569.txt | 51 ++++++++++++++++++++++++++ .riot/requirements/16c7dad.txt | 53 ++++++++++++++++++++++++++++ .riot/requirements/1b15b5d.txt | 49 +++++++++++++++++++++++++ .riot/requirements/1d8494f.txt | 49 +++++++++++++++++++++++++ .riot/requirements/3ddc705.txt | 49 +++++++++++++++++++++++++ .riot/requirements/805c8c9.txt | 49 +++++++++++++++++++++++++ .riot/requirements/91810c5.txt | 52 +++++++++++++++++++++++++++ ddtrace/_trace/span.py | 12 +++---- ddtrace/internal/utils/time.py | 30 ++++++++++++---- tests/opentelemetry/test_span.py | 2 +- tests/opentelemetry/test_trace.py | 2 +- tests/opentracer/core/test_tracer.py | 2 +- tests/tracer/test_encoders.py | 2 +- tests/tracer/test_freezegun.py | 49 +++++++++++++++++++++++++ 16 files changed, 534 insertions(+), 17 deletions(-) create mode 100644 .riot/requirements/1192c19.txt create mode 100644 .riot/requirements/147a53d.txt create mode 100644 .riot/requirements/152d569.txt create mode 100644 .riot/requirements/16c7dad.txt create mode 100644 .riot/requirements/1b15b5d.txt create mode 100644 .riot/requirements/1d8494f.txt create mode 100644 .riot/requirements/3ddc705.txt create mode 100644 .riot/requirements/805c8c9.txt create mode 100644 .riot/requirements/91810c5.txt create mode 100644 tests/tracer/test_freezegun.py diff --git a/.riot/requirements/1192c19.txt b/.riot/requirements/1192c19.txt new file mode 100644 index 00000000000..1127d1a1a18 --- /dev/null +++ b/.riot/requirements/1192c19.txt @@ -0,0 +1,49 @@ +# +# This file is autogenerated by pip-compile with Python 3.13 +# by the following command: +# +# pip-compile --allow-unsafe --no-annotate .riot/requirements/1192c19.in +# +annotated-types==0.7.0 +anyio==4.9.0 +attrs==25.3.0 +boto3==1.39.7 +botocore==1.39.7 +certifi==2025.7.14 +coverage[toml]==7.9.2 +fastapi==0.116.1 +freezegun==1.5.3 +h11==0.16.0 +httpcore==1.0.9 +httpretty==1.1.4 +httpx==0.28.1 +hypothesis==6.45.0 +idna==3.10 +iniconfig==2.1.0 +jmespath==1.0.1 +mock==5.2.0 +msgpack==1.1.1 +opentracing==2.4.0 +packaging==25.0 +pluggy==1.6.0 +pydantic==2.11.7 +pydantic-core==2.33.2 +pygments==2.19.2 +pytest==8.4.1 +pytest-cov==6.2.1 +pytest-mock==3.14.1 +pytest-randomly==3.16.0 +python-dateutil==2.9.0.post0 +s3transfer==0.13.0 +six==1.17.0 +sniffio==1.3.1 +sortedcontainers==2.4.0 +starlette==0.47.1 +structlog==25.4.0 +typing-extensions==4.14.1 +typing-inspection==0.4.1 +urllib3==2.5.0 +wheel==0.45.1 + +# The following packages are considered to be unsafe in a requirements file: +setuptools==80.9.0 diff --git a/.riot/requirements/147a53d.txt b/.riot/requirements/147a53d.txt new file mode 100644 index 00000000000..75d28a2eb4f --- /dev/null +++ b/.riot/requirements/147a53d.txt @@ -0,0 +1,51 @@ +# +# This file is autogenerated by pip-compile with Python 3.10 +# by the following command: +# +# pip-compile --allow-unsafe --no-annotate .riot/requirements/147a53d.in +# +annotated-types==0.7.0 +anyio==4.9.0 +attrs==25.3.0 +boto3==1.39.6 +botocore==1.39.6 +certifi==2025.7.14 +coverage[toml]==7.9.2 +exceptiongroup==1.3.0 +fastapi==0.116.1 +freezegun==1.5.3 +h11==0.16.0 +httpcore==1.0.9 +httpretty==1.1.4 +httpx==0.28.1 +hypothesis==6.45.0 +idna==3.10 +iniconfig==2.1.0 +jmespath==1.0.1 +mock==5.2.0 +msgpack==1.1.1 +opentracing==2.4.0 +packaging==25.0 +pluggy==1.6.0 +pydantic==2.11.7 +pydantic-core==2.33.2 +pygments==2.19.2 +pytest==8.4.1 +pytest-cov==6.2.1 +pytest-mock==3.14.1 +pytest-randomly==3.16.0 +python-dateutil==2.9.0.post0 +s3transfer==0.13.0 +six==1.17.0 +sniffio==1.3.1 +sortedcontainers==2.4.0 +starlette==0.47.1 +structlog==25.4.0 +tomli==2.2.1 +typing-extensions==4.14.1 +typing-inspection==0.4.1 +urllib3==2.5.0 +wheel==0.45.1 + +# The following packages are considered to be unsafe in a requirements file: +setuptools==80.9.0 diff --git a/.riot/requirements/152d569.txt b/.riot/requirements/152d569.txt new file mode 100644 index 00000000000..414c18d415e --- /dev/null +++ b/.riot/requirements/152d569.txt @@ -0,0 +1,51 @@ +# +# This file is autogenerated by pip-compile with Python 3.8 +# by the following command: +# +# pip-compile --allow-unsafe --no-annotate .riot/requirements/152d569.in +# +annotated-types==0.7.0 +anyio==4.5.2 +attrs==25.3.0 +boto3==1.37.38 +botocore==1.37.38 +certifi==2025.7.14 +coverage[toml]==7.6.1 +exceptiongroup==1.3.0 +fastapi==0.116.1 +freezegun==1.5.3 +h11==0.16.0 +httpcore==1.0.9 +httpretty==1.1.4 +httpx==0.28.1 +hypothesis==6.45.0 +idna==3.10 +importlib-metadata==8.5.0 +iniconfig==2.1.0 +jmespath==1.0.1 +mock==5.2.0 +msgpack==1.1.1 +opentracing==2.4.0 +packaging==25.0 +pluggy==1.5.0 +pydantic==2.10.6 +pydantic-core==2.27.2 +pytest==8.3.5 +pytest-cov==5.0.0 +pytest-mock==3.14.1 +pytest-randomly==3.15.0 +python-dateutil==2.9.0.post0 +s3transfer==0.11.5 +six==1.17.0 +sniffio==1.3.1 +sortedcontainers==2.4.0 +starlette==0.44.0 +structlog==25.4.0 +tomli==2.2.1 +typing-extensions==4.13.2 +urllib3==1.26.20 +wheel==0.45.1 +zipp==3.20.2 + +# The following packages are considered to be unsafe in a requirements file: +setuptools==75.3.2 diff --git a/.riot/requirements/16c7dad.txt b/.riot/requirements/16c7dad.txt new file mode 100644 index 00000000000..31cb8e7adf8 --- /dev/null +++ b/.riot/requirements/16c7dad.txt @@ -0,0 +1,53 @@ +# +# This file is autogenerated by pip-compile with Python 3.9 +# by the following command: +# +# pip-compile --allow-unsafe --no-annotate .riot/requirements/16c7dad.in +# +annotated-types==0.7.0 +anyio==4.9.0 +attrs==25.3.0 +boto3==1.39.6 +botocore==1.39.6 +certifi==2025.7.14 +coverage[toml]==7.9.2 +exceptiongroup==1.3.0 +fastapi==0.116.1 +freezegun==1.5.3 +h11==0.16.0 +httpcore==1.0.9 +httpretty==1.1.4 +httpx==0.28.1 +hypothesis==6.45.0 +idna==3.10 +importlib-metadata==8.7.0 +iniconfig==2.1.0 +jmespath==1.0.1 +mock==5.2.0 +msgpack==1.1.1 +opentracing==2.4.0 +packaging==25.0 +pluggy==1.6.0 +pydantic==2.11.7 +pydantic-core==2.33.2 +pygments==2.19.2 +pytest==8.4.1 +pytest-cov==6.2.1 +pytest-mock==3.14.1 +pytest-randomly==3.16.0 +python-dateutil==2.9.0.post0 +s3transfer==0.13.0 +six==1.17.0 +sniffio==1.3.1 +sortedcontainers==2.4.0 +starlette==0.47.1 +structlog==25.4.0 +tomli==2.2.1 +typing-extensions==4.14.1 +typing-inspection==0.4.1 +urllib3==1.26.20 +wheel==0.45.1 +zipp==3.23.0 + +# The following packages are considered to be unsafe in a requirements file: +setuptools==80.9.0 diff --git a/.riot/requirements/1b15b5d.txt b/.riot/requirements/1b15b5d.txt new file mode 100644 index 00000000000..822b7cc540e --- /dev/null +++ b/.riot/requirements/1b15b5d.txt @@ -0,0 +1,49 @@ +# +# This file is autogenerated by pip-compile with Python 3.11 +# by the following command: +# +# pip-compile --allow-unsafe --no-annotate .riot/requirements/1b15b5d.in +# +annotated-types==0.7.0 +anyio==4.9.0 +attrs==25.3.0 +boto3==1.39.6 +botocore==1.39.6 +certifi==2025.7.14 +coverage[toml]==7.9.2 +fastapi==0.116.1 +freezegun==1.5.3 +h11==0.16.0 +httpcore==1.0.9 +httpretty==1.1.4 +httpx==0.28.1 +hypothesis==6.45.0 +idna==3.10 +iniconfig==2.1.0 +jmespath==1.0.1 +mock==5.2.0 +msgpack==1.1.1 +opentracing==2.4.0 +packaging==25.0 +pluggy==1.6.0 +pydantic==2.11.7 +pydantic-core==2.33.2 +pygments==2.19.2 +pytest==8.4.1 +pytest-cov==6.2.1 +pytest-mock==3.14.1 +pytest-randomly==3.16.0 +python-dateutil==2.9.0.post0 +s3transfer==0.13.0 +six==1.17.0 +sniffio==1.3.1 +sortedcontainers==2.4.0 +starlette==0.47.1 +structlog==25.4.0 +typing-extensions==4.14.1 +typing-inspection==0.4.1 +urllib3==2.5.0 +wheel==0.45.1 + +# The following packages are considered to be unsafe in a requirements file: +setuptools==80.9.0 diff --git a/.riot/requirements/1d8494f.txt b/.riot/requirements/1d8494f.txt new file mode 100644 index 00000000000..31c3184b399 --- /dev/null +++ b/.riot/requirements/1d8494f.txt @@ -0,0 +1,49 @@ +# +# This file is autogenerated by pip-compile with Python 3.13 +# by the following command: +# +# pip-compile --allow-unsafe --no-annotate .riot/requirements/1d8494f.in +# +annotated-types==0.7.0 +anyio==4.9.0 +attrs==25.3.0 +boto3==1.39.7 +botocore==1.39.7 +certifi==2025.7.14 +coverage[toml]==7.9.2 +fastapi==0.116.1 +freezegun==1.5.3 +h11==0.16.0 +httpcore==1.0.9 +httpretty==1.1.4 +httpx==0.28.1 +hypothesis==6.45.0 +idna==3.10 +iniconfig==2.1.0 +jmespath==1.0.1 +mock==5.2.0 +msgpack==1.1.1 +opentracing==2.4.0 +packaging==25.0 +pluggy==1.6.0 +pydantic==2.11.7 +pydantic-core==2.33.2 +pygments==2.19.2 +pytest==8.4.1 +pytest-cov==6.2.1 +pytest-mock==3.14.1 +pytest-randomly==3.16.0 +python-dateutil==2.9.0.post0 +s3transfer==0.13.0 +six==1.17.0 +sniffio==1.3.1 +sortedcontainers==2.4.0 +starlette==0.47.1 +structlog==25.4.0 +typing-extensions==4.14.1 +typing-inspection==0.4.1 +urllib3==2.5.0 +wheel==0.45.1 + +# The following packages are considered to be unsafe in a requirements file: +setuptools==80.9.0 diff --git a/.riot/requirements/3ddc705.txt b/.riot/requirements/3ddc705.txt new file mode 100644 index 00000000000..77ddad5026c --- /dev/null +++ b/.riot/requirements/3ddc705.txt @@ -0,0 +1,49 @@ +# +# This file is autogenerated by pip-compile with Python 3.13 +# by the following command: +# +# pip-compile --allow-unsafe --no-annotate .riot/requirements/3ddc705.in +# +annotated-types==0.7.0 +anyio==4.9.0 +attrs==25.3.0 +boto3==1.39.6 +botocore==1.39.6 +certifi==2025.7.14 +coverage[toml]==7.9.2 +fastapi==0.116.1 +freezegun==1.5.3 +h11==0.16.0 +httpcore==1.0.9 +httpretty==1.1.4 +httpx==0.28.1 +hypothesis==6.45.0 +idna==3.10 +iniconfig==2.1.0 +jmespath==1.0.1 +mock==5.2.0 +msgpack==1.1.1 +opentracing==2.4.0 +packaging==25.0 +pluggy==1.6.0 +pydantic==2.11.7 +pydantic-core==2.33.2 +pygments==2.19.2 +pytest==8.4.1 +pytest-cov==6.2.1 +pytest-mock==3.14.1 +pytest-randomly==3.16.0 +python-dateutil==2.9.0.post0 +s3transfer==0.13.0 +six==1.17.0 +sniffio==1.3.1 +sortedcontainers==2.4.0 +starlette==0.47.1 +structlog==25.4.0 +typing-extensions==4.14.1 +typing-inspection==0.4.1 +urllib3==2.5.0 +wheel==0.45.1 + +# The following packages are considered to be unsafe in a requirements file: +setuptools==80.9.0 diff --git a/.riot/requirements/805c8c9.txt b/.riot/requirements/805c8c9.txt new file mode 100644 index 00000000000..067aa536867 --- /dev/null +++ b/.riot/requirements/805c8c9.txt @@ -0,0 +1,49 @@ +# +# This file is autogenerated by pip-compile with Python 3.12 +# by the following command: +# +# pip-compile --allow-unsafe --no-annotate .riot/requirements/805c8c9.in +# +annotated-types==0.7.0 +anyio==4.9.0 +attrs==25.3.0 +boto3==1.39.6 +botocore==1.39.6 +certifi==2025.7.14 +coverage[toml]==7.9.2 +fastapi==0.116.1 +freezegun==1.5.3 +h11==0.16.0 +httpcore==1.0.9 +httpretty==1.1.4 +httpx==0.28.1 +hypothesis==6.45.0 +idna==3.10 +iniconfig==2.1.0 +jmespath==1.0.1 +mock==5.2.0 +msgpack==1.1.1 +opentracing==2.4.0 +packaging==25.0 +pluggy==1.6.0 +pydantic==2.11.7 +pydantic-core==2.33.2 +pygments==2.19.2 +pytest==8.4.1 +pytest-cov==6.2.1 +pytest-mock==3.14.1 +pytest-randomly==3.16.0 +python-dateutil==2.9.0.post0 +s3transfer==0.13.0 +six==1.17.0 +sniffio==1.3.1 +sortedcontainers==2.4.0 +starlette==0.47.1 +structlog==25.4.0 +typing-extensions==4.14.1 +typing-inspection==0.4.1 +urllib3==2.5.0 +wheel==0.45.1 + +# The following packages are considered to be unsafe in a requirements file: +setuptools==80.9.0 diff --git a/.riot/requirements/91810c5.txt b/.riot/requirements/91810c5.txt new file mode 100644 index 00000000000..121cbab055d --- /dev/null +++ b/.riot/requirements/91810c5.txt @@ -0,0 +1,52 @@ +# +# This file is autogenerated by pip-compile with Python 3.8 +# by the following command: +# +# pip-compile --allow-unsafe --no-annotate .riot/requirements/91810c5.in +# +annotated-types==0.7.0 +anyio==4.5.2 +attrs==22.1.0 +boto3==1.37.38 +botocore==1.37.38 +cattrs==23.1.2 +certifi==2025.7.14 +coverage[toml]==7.6.1 +exceptiongroup==1.3.0 +fastapi==0.116.1 +freezegun==1.5.3 +h11==0.16.0 +httpcore==1.0.9 +httpretty==1.1.4 +httpx==0.28.1 +hypothesis==6.45.0 +idna==3.10 +importlib-metadata==8.5.0 +iniconfig==2.1.0 +jmespath==1.0.1 +mock==5.2.0 +msgpack==1.1.1 +opentracing==2.4.0 +packaging==25.0 +pluggy==1.5.0 +pydantic==2.10.6 +pydantic-core==2.27.2 +pytest==8.3.5 +pytest-cov==5.0.0 +pytest-mock==3.14.1 +pytest-randomly==3.15.0 +python-dateutil==2.9.0.post0 +s3transfer==0.11.5 +six==1.17.0 +sniffio==1.3.1 +sortedcontainers==2.4.0 +starlette==0.44.0 +structlog==25.4.0 +tomli==2.2.1 +typing-extensions==4.13.2 +urllib3==1.26.20 +wheel==0.45.1 +zipp==3.20.2 + +# The following packages are considered to be unsafe in a requirements file: +setuptools==75.3.2 diff --git a/ddtrace/_trace/span.py b/ddtrace/_trace/span.py index f712d6335ab..3bfb2dee3c9 100644 --- a/ddtrace/_trace/span.py +++ b/ddtrace/_trace/span.py @@ -2,7 +2,6 @@ import math import pprint import sys -from time import time_ns import traceback from types import TracebackType from typing import Any @@ -55,6 +54,7 @@ from ddtrace.internal.sampling import SamplingMechanism from ddtrace.internal.sampling import set_sampling_decision_maker from ddtrace.internal.utils.deprecations import DDTraceDeprecationWarning +from ddtrace.internal.utils.time import Time from ddtrace.settings._config import config from ddtrace.vendor.debtcollector import deprecate @@ -70,7 +70,7 @@ def __init__( ): self.name: str = name if time_unix_nano is None: - time_unix_nano = time_ns() + time_unix_nano = Time.time_ns() self.time_unix_nano: int = time_unix_nano self.attributes: dict = attributes if attributes else {} @@ -199,7 +199,7 @@ def __init__( self._meta_struct: Dict[str, Dict[str, Any]] = {} - self.start_ns: int = time_ns() if start is None else int(start * 1e9) + self.start_ns: int = Time.time_ns() if start is None else int(start * 1e9) self.duration_ns: Optional[int] = None if trace_id is not None: @@ -292,7 +292,7 @@ def finished(self, value: bool) -> None: """ if value: if not self.finished: - self.duration_ns = time_ns() - self.start_ns + self.duration_ns = Time.time_ns() - self.start_ns else: self.duration_ns = None @@ -314,7 +314,7 @@ def finish(self, finish_time: Optional[float] = None) -> None: :param finish_time: The end time of the span, in seconds. Defaults to ``now``. """ if finish_time is None: - self._finish_ns(time_ns()) + self._finish_ns(Time.time_ns()) else: self._finish_ns(int(finish_time * 1e9)) @@ -650,7 +650,7 @@ def record_exception( # User provided attributes must take precedence over attrs attrs.update(attributes) - self._add_event(name="exception", attributes=attrs, timestamp=time_ns()) + self._add_event(name="exception", attributes=attrs, timestamp=Time.time_ns()) def _validate_attribute(self, key: str, value: object) -> bool: if isinstance(value, (str, bool, int, float)): diff --git a/ddtrace/internal/utils/time.py b/ddtrace/internal/utils/time.py index 49e4058bac2..42aa12b9fec 100644 --- a/ddtrace/internal/utils/time.py +++ b/ddtrace/internal/utils/time.py @@ -1,4 +1,4 @@ -import time +import time as builtin_time from types import TracebackType from typing import Optional from typing import Type # noqa:F401 @@ -9,6 +9,22 @@ log = get_logger(__name__) +class Time: + """ + References to the standard Python time functions that won't be clobbered by `freezegun`. + + `freezegun`_ scans all loaded modules to check for imported functions from the `time` module, but it does not look + inside classes or other objects, so these references are safe to use in the tracer. + + .. _freezegun: https://github.com/spulec/freezegun/blob/1.5.3/freezegun/api.py#L817 + """ + + time = builtin_time.time + time_ns = builtin_time.time_ns + monotonic = builtin_time.monotonic + monotonic_ns = builtin_time.monotonic_ns + + class StopWatch(object): """A simple timer/stopwatch helper class. @@ -31,7 +47,7 @@ def __init__(self) -> None: def start(self): # type: () -> StopWatch """Starts the watch.""" - self._started_at = time.monotonic() + self._started_at = Time.monotonic() return self def elapsed(self) -> float: @@ -44,7 +60,7 @@ def elapsed(self) -> float: if self._started_at is None: raise RuntimeError("Can not get the elapsed time of a stopwatch if it has not been started/stopped") if self._stopped_at is None: - now = time.monotonic() + now = Time.monotonic() else: now = self._stopped_at return now - self._started_at @@ -66,7 +82,7 @@ def stop(self): """Stops the watch.""" if self._started_at is None: raise RuntimeError("Can not stop a stopwatch that has not been started") - self._stopped_at = time.monotonic() + self._stopped_at = Time.monotonic() return self @@ -74,7 +90,7 @@ class HourGlass(object): """An implementation of an hourglass.""" def __init__(self, duration: float) -> None: - t = time.monotonic() + t = Time.monotonic() self._duration = duration self._started_at = t - duration @@ -84,7 +100,7 @@ def __init__(self, duration: float) -> None: def turn(self) -> None: """Turn the hourglass.""" - t = time.monotonic() + t = Time.monotonic() top_0 = self._end_at - self._started_at bottom = self._duration - top_0 + min(t - self._started_at, top_0) @@ -104,7 +120,7 @@ def _trickled(self): def _trickling(self): # type: () -> bool - if time.monotonic() < self._end_at: + if Time.monotonic() < self._end_at: return True # No longer trickling, so we change state diff --git a/tests/opentelemetry/test_span.py b/tests/opentelemetry/test_span.py index 3d18cf3c4db..e825ee9a928 100644 --- a/tests/opentelemetry/test_span.py +++ b/tests/opentelemetry/test_span.py @@ -55,7 +55,7 @@ def test_otel_span_events(oteltracer): with oteltracer.start_span("web.response") as span2: # mock time_ns to ensure the event timestamp is consistent in snapshot files - with mock.patch("ddtrace._trace.span.time_ns", return_value=1714537311986000): + with mock.patch("ddtrace._trace.span.Time.time_ns", return_value=1714537311986000): span2.add_event("Web page loaded") span2.add_event("Button changed color", {"colors": [112, 215, 70], "response.time": 134.3, "success": True}) diff --git a/tests/opentelemetry/test_trace.py b/tests/opentelemetry/test_trace.py index f0c2e732670..6bfb478c13d 100644 --- a/tests/opentelemetry/test_trace.py +++ b/tests/opentelemetry/test_trace.py @@ -25,7 +25,7 @@ def test_otel_start_span_record_exception(oteltracer): raised_span = oteltracer.start_span("test-raised-exception") with pytest.raises(Exception, match="Sorry Otel Span, I failed you"): # Ensures that the exception is recorded with the consistent timestamp for snapshot testing - with mock.patch("ddtrace._trace.span.time_ns", return_value=1716560261227739000): + with mock.patch("ddtrace._trace.span.Time.time_ns", return_value=1716560261227739000): with raised_span: raised_span.record_exception(ValueError("Invalid Operation 1")) raise Exception("Sorry Otel Span, I failed you") diff --git a/tests/opentracer/core/test_tracer.py b/tests/opentracer/core/test_tracer.py index f5534c8f1b0..e83fc495997 100644 --- a/tests/opentracer/core/test_tracer.py +++ b/tests/opentracer/core/test_tracer.py @@ -122,7 +122,7 @@ def test_start_span_references(self, ot_tracer, test_spans): def test_start_span_custom_start_time(self, ot_tracer): """Start a span with a custom start time.""" t = 100 - with mock.patch("ddtrace._trace.span.time_ns") as time: + with mock.patch("ddtrace._trace.span.Time.time_ns") as time: time.return_value = 102 * 1e9 with ot_tracer.start_span("myop", start_time=t) as span: pass diff --git a/tests/tracer/test_encoders.py b/tests/tracer/test_encoders.py index afd546559bd..81f9ab4a490 100644 --- a/tests/tracer/test_encoders.py +++ b/tests/tracer/test_encoders.py @@ -553,7 +553,7 @@ def test_span_event_encoding_msgpack(): {"emotion": "happy", "rating": 9.8, "other": [1, 9.5, 1], "idol": False}, 17353464354546, ) - with mock.patch("ddtrace._trace.span.time_ns", return_value=2234567890123456): + with mock.patch("ddtrace._trace.span.Time.time_ns", return_value=2234567890123456): span._add_event("We are going to the moon") # Get test parameters from environment variables diff --git a/tests/tracer/test_freezegun.py b/tests/tracer/test_freezegun.py new file mode 100644 index 00000000000..21c0d71b0ef --- /dev/null +++ b/tests/tracer/test_freezegun.py @@ -0,0 +1,49 @@ +import datetime +import time + +from ddtrace.internal.utils.time import StopWatch +from ddtrace.trace import tracer as dd_tracer + + +class TestFreezegunTestCase: + def test_freezegun_does_not_freeze_tracing(self): + import freezegun + + with freezegun.freeze_time("2020-01-01"): + with dd_tracer.trace("freezegun.test") as span: + time.sleep(1) + + assert span.duration >= 1 + + def test_freezegun_fast_forward_does_not_affect_tracing(self): + import freezegun + + with freezegun.freeze_time("2020-01-01") as frozen_time: + with dd_tracer.trace("freezegun.test") as span: + time.sleep(1) + frozen_time.tick(delta=datetime.timedelta(days=10)) + assert 1 <= span.duration <= 5 + + def test_freezegun_does_not_freeze_stopwatch(self): + import freezegun + + with freezegun.freeze_time("2020-01-01"): + with StopWatch() as sw: + time.sleep(1) + assert sw.elapsed() >= 1 + + def test_freezegun_configure_default_ignore_list_continues_to_ignore_ddtrace(self): + import freezegun + from freezegun.config import DEFAULT_IGNORE_LIST + + try: + freezegun.configure(default_ignore_list=[]) + + with freezegun.freeze_time("2020-01-01"): + with dd_tracer.trace("freezegun.test") as span: + time.sleep(1) + + assert span.duration >= 1 + finally: + # Reset the ignore list to its default value after the test + freezegun.configure(default_ignore_list=DEFAULT_IGNORE_LIST) From a1d6af040aaf04d087ae93f0e3df7ad7f62c06f6 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?V=C3=ADtor=20De=20Ara=C3=BAjo?= Date: Wed, 16 Jul 2025 21:26:14 +0000 Subject: [PATCH 2/7] riot envs --- .riot/requirements/159f4bb.txt | 58 +++++++++++++++--------------- .riot/requirements/15e8745.txt | 58 +++++++++++++++--------------- .riot/requirements/1793deb.txt | 50 +++++++++++++------------- .riot/requirements/18d037c.txt | 62 ++++++++++++++++---------------- .riot/requirements/1aa24de.txt | 64 ++++++++++++++++++---------------- .riot/requirements/1df4764.txt | 52 ++++++++++++++------------- .riot/requirements/7bbf828.txt | 52 ++++++++++++++------------- .riot/requirements/b35a160.txt | 36 +++++++++---------- .riot/requirements/bcbec2a.txt | 52 ++++++++++++++------------- 9 files changed, 249 insertions(+), 235 deletions(-) diff --git a/.riot/requirements/159f4bb.txt b/.riot/requirements/159f4bb.txt index 41cf05bdf26..83bb1bcfae3 100644 --- a/.riot/requirements/159f4bb.txt +++ b/.riot/requirements/159f4bb.txt @@ -5,42 +5,44 @@ # pip-compile --allow-unsafe --no-annotate .riot/requirements/159f4bb.in # annotated-types==0.7.0 -anyio==4.6.2.post1 -attrs==24.2.0 -boto3==1.35.62 -botocore==1.35.62 -certifi==2024.8.30 -coverage[toml]==7.6.7 -fastapi==0.115.5 -h11==0.14.0 -httpcore==1.0.7 +anyio==4.9.0 +attrs==25.3.0 +boto3==1.39.7 +botocore==1.39.7 +certifi==2025.7.14 +coverage[toml]==7.9.2 +fastapi==0.116.1 +h11==0.16.0 +httpcore==1.0.9 httpretty==1.1.4 -httpx==0.27.2 +httpx==0.28.1 hypothesis==6.45.0 idna==3.10 -iniconfig==2.0.0 +iniconfig==2.1.0 jmespath==1.0.1 -mock==5.1.0 -msgpack==1.1.0 +mock==5.2.0 +msgpack==1.1.1 opentracing==2.4.0 -packaging==24.2 -pluggy==1.5.0 -pydantic==2.9.2 -pydantic-core==2.23.4 -pytest==8.3.3 -pytest-cov==6.0.0 -pytest-mock==3.14.0 +packaging==25.0 +pluggy==1.6.0 +pydantic==2.11.7 +pydantic-core==2.33.2 +pygments==2.19.2 +pytest==8.4.1 +pytest-cov==6.2.1 +pytest-mock==3.14.1 pytest-randomly==3.16.0 python-dateutil==2.9.0.post0 -s3transfer==0.10.3 -six==1.16.0 +s3transfer==0.13.0 +six==1.17.0 sniffio==1.3.1 sortedcontainers==2.4.0 -starlette==0.41.2 -structlog==24.4.0 -typing-extensions==4.12.2 -urllib3==2.2.3 -wheel==0.45.0 +starlette==0.47.1 +structlog==25.4.0 +typing-extensions==4.14.1 +typing-inspection==0.4.1 +urllib3==2.5.0 +wheel==0.45.1 # The following packages are considered to be unsafe in a requirements file: -setuptools==75.5.0 +setuptools==80.9.0 diff --git a/.riot/requirements/15e8745.txt b/.riot/requirements/15e8745.txt index 08c33f59162..f96f1b81d6e 100644 --- a/.riot/requirements/15e8745.txt +++ b/.riot/requirements/15e8745.txt @@ -5,42 +5,44 @@ # pip-compile --allow-unsafe --no-annotate .riot/requirements/15e8745.in # annotated-types==0.7.0 -anyio==4.6.2.post1 -attrs==24.2.0 -boto3==1.35.62 -botocore==1.35.62 -certifi==2024.8.30 -coverage[toml]==7.6.7 -fastapi==0.115.5 -h11==0.14.0 -httpcore==1.0.7 +anyio==4.9.0 +attrs==25.3.0 +boto3==1.39.7 +botocore==1.39.7 +certifi==2025.7.14 +coverage[toml]==7.9.2 +fastapi==0.116.1 +h11==0.16.0 +httpcore==1.0.9 httpretty==1.1.4 -httpx==0.27.2 +httpx==0.28.1 hypothesis==6.45.0 idna==3.10 -iniconfig==2.0.0 +iniconfig==2.1.0 jmespath==1.0.1 -mock==5.1.0 -msgpack==1.1.0 +mock==5.2.0 +msgpack==1.1.1 opentracing==2.4.0 -packaging==24.2 -pluggy==1.5.0 -pydantic==2.9.2 -pydantic-core==2.23.4 -pytest==8.3.3 -pytest-cov==6.0.0 -pytest-mock==3.14.0 +packaging==25.0 +pluggy==1.6.0 +pydantic==2.11.7 +pydantic-core==2.33.2 +pygments==2.19.2 +pytest==8.4.1 +pytest-cov==6.2.1 +pytest-mock==3.14.1 pytest-randomly==3.16.0 python-dateutil==2.9.0.post0 -s3transfer==0.10.3 -six==1.16.0 +s3transfer==0.13.0 +six==1.17.0 sniffio==1.3.1 sortedcontainers==2.4.0 -starlette==0.41.2 -structlog==24.4.0 -typing-extensions==4.12.2 -urllib3==2.2.3 -wheel==0.45.0 +starlette==0.47.1 +structlog==25.4.0 +typing-extensions==4.14.1 +typing-inspection==0.4.1 +urllib3==2.5.0 +wheel==0.45.1 # The following packages are considered to be unsafe in a requirements file: -setuptools==75.5.0 +setuptools==80.9.0 diff --git a/.riot/requirements/1793deb.txt b/.riot/requirements/1793deb.txt index 9002bd898b2..2fa40553662 100644 --- a/.riot/requirements/1793deb.txt +++ b/.riot/requirements/1793deb.txt @@ -6,45 +6,45 @@ # annotated-types==0.7.0 anyio==4.5.2 -attrs==24.2.0 -boto3==1.35.62 -botocore==1.35.62 -certifi==2024.8.30 +attrs==25.3.0 +boto3==1.37.38 +botocore==1.37.38 +certifi==2025.7.14 coverage[toml]==7.6.1 -exceptiongroup==1.2.2 -fastapi==0.115.5 -h11==0.14.0 -httpcore==1.0.7 +exceptiongroup==1.3.0 +fastapi==0.116.1 +h11==0.16.0 +httpcore==1.0.9 httpretty==1.1.4 -httpx==0.27.2 +httpx==0.28.1 hypothesis==6.45.0 idna==3.10 importlib-metadata==8.5.0 -iniconfig==2.0.0 +iniconfig==2.1.0 jmespath==1.0.1 -mock==5.1.0 -msgpack==1.1.0 +mock==5.2.0 +msgpack==1.1.1 opentracing==2.4.0 -packaging==24.2 +packaging==25.0 pluggy==1.5.0 -pydantic==2.9.2 -pydantic-core==2.23.4 -pytest==8.3.3 +pydantic==2.10.6 +pydantic-core==2.27.2 +pytest==8.3.5 pytest-cov==5.0.0 -pytest-mock==3.14.0 +pytest-mock==3.14.1 pytest-randomly==3.15.0 python-dateutil==2.9.0.post0 -s3transfer==0.10.3 -six==1.16.0 +s3transfer==0.11.5 +six==1.17.0 sniffio==1.3.1 sortedcontainers==2.4.0 -starlette==0.41.2 -structlog==24.4.0 -tomli==2.1.0 -typing-extensions==4.12.2 +starlette==0.44.0 +structlog==25.4.0 +tomli==2.2.1 +typing-extensions==4.13.2 urllib3==1.26.20 -wheel==0.45.0 +wheel==0.45.1 zipp==3.20.2 # The following packages are considered to be unsafe in a requirements file: -setuptools==75.3.0 +setuptools==75.3.2 diff --git a/.riot/requirements/18d037c.txt b/.riot/requirements/18d037c.txt index 5e22bd1f37d..edc46fba034 100644 --- a/.riot/requirements/18d037c.txt +++ b/.riot/requirements/18d037c.txt @@ -5,44 +5,46 @@ # pip-compile --allow-unsafe --no-annotate .riot/requirements/18d037c.in # annotated-types==0.7.0 -anyio==4.6.2.post1 -attrs==24.2.0 -boto3==1.35.62 -botocore==1.35.62 -certifi==2024.8.30 -coverage[toml]==7.6.7 -exceptiongroup==1.2.2 -fastapi==0.115.5 -h11==0.14.0 -httpcore==1.0.7 +anyio==4.9.0 +attrs==25.3.0 +boto3==1.39.7 +botocore==1.39.7 +certifi==2025.7.14 +coverage[toml]==7.9.2 +exceptiongroup==1.3.0 +fastapi==0.116.1 +h11==0.16.0 +httpcore==1.0.9 httpretty==1.1.4 -httpx==0.27.2 +httpx==0.28.1 hypothesis==6.45.0 idna==3.10 -iniconfig==2.0.0 +iniconfig==2.1.0 jmespath==1.0.1 -mock==5.1.0 -msgpack==1.1.0 +mock==5.2.0 +msgpack==1.1.1 opentracing==2.4.0 -packaging==24.2 -pluggy==1.5.0 -pydantic==2.9.2 -pydantic-core==2.23.4 -pytest==8.3.3 -pytest-cov==6.0.0 -pytest-mock==3.14.0 +packaging==25.0 +pluggy==1.6.0 +pydantic==2.11.7 +pydantic-core==2.33.2 +pygments==2.19.2 +pytest==8.4.1 +pytest-cov==6.2.1 +pytest-mock==3.14.1 pytest-randomly==3.16.0 python-dateutil==2.9.0.post0 -s3transfer==0.10.3 -six==1.16.0 +s3transfer==0.13.0 +six==1.17.0 sniffio==1.3.1 sortedcontainers==2.4.0 -starlette==0.41.2 -structlog==24.4.0 -tomli==2.1.0 -typing-extensions==4.12.2 -urllib3==2.2.3 -wheel==0.45.0 +starlette==0.47.1 +structlog==25.4.0 +tomli==2.2.1 +typing-extensions==4.14.1 +typing-inspection==0.4.1 +urllib3==2.5.0 +wheel==0.45.1 # The following packages are considered to be unsafe in a requirements file: -setuptools==75.5.0 +setuptools==80.9.0 diff --git a/.riot/requirements/1aa24de.txt b/.riot/requirements/1aa24de.txt index d61dfa8fa6b..f51192feffe 100644 --- a/.riot/requirements/1aa24de.txt +++ b/.riot/requirements/1aa24de.txt @@ -5,46 +5,48 @@ # pip-compile --allow-unsafe --no-annotate .riot/requirements/1aa24de.in # annotated-types==0.7.0 -anyio==4.6.2.post1 -attrs==24.2.0 -boto3==1.35.62 -botocore==1.35.62 -certifi==2024.8.30 -coverage[toml]==7.6.7 -exceptiongroup==1.2.2 -fastapi==0.115.5 -h11==0.14.0 -httpcore==1.0.7 +anyio==4.9.0 +attrs==25.3.0 +boto3==1.39.7 +botocore==1.39.7 +certifi==2025.7.14 +coverage[toml]==7.9.2 +exceptiongroup==1.3.0 +fastapi==0.116.1 +h11==0.16.0 +httpcore==1.0.9 httpretty==1.1.4 -httpx==0.27.2 +httpx==0.28.1 hypothesis==6.45.0 idna==3.10 -importlib-metadata==8.5.0 -iniconfig==2.0.0 +importlib-metadata==8.7.0 +iniconfig==2.1.0 jmespath==1.0.1 -mock==5.1.0 -msgpack==1.1.0 +mock==5.2.0 +msgpack==1.1.1 opentracing==2.4.0 -packaging==24.2 -pluggy==1.5.0 -pydantic==2.9.2 -pydantic-core==2.23.4 -pytest==8.3.3 -pytest-cov==6.0.0 -pytest-mock==3.14.0 +packaging==25.0 +pluggy==1.6.0 +pydantic==2.11.7 +pydantic-core==2.33.2 +pygments==2.19.2 +pytest==8.4.1 +pytest-cov==6.2.1 +pytest-mock==3.14.1 pytest-randomly==3.16.0 python-dateutil==2.9.0.post0 -s3transfer==0.10.3 -six==1.16.0 +s3transfer==0.13.0 +six==1.17.0 sniffio==1.3.1 sortedcontainers==2.4.0 -starlette==0.41.2 -structlog==24.4.0 -tomli==2.1.0 -typing-extensions==4.12.2 +starlette==0.47.1 +structlog==25.4.0 +tomli==2.2.1 +typing-extensions==4.14.1 +typing-inspection==0.4.1 urllib3==1.26.20 -wheel==0.45.0 -zipp==3.21.0 +wheel==0.45.1 +zipp==3.23.0 # The following packages are considered to be unsafe in a requirements file: -setuptools==75.5.0 +setuptools==80.9.0 diff --git a/.riot/requirements/1df4764.txt b/.riot/requirements/1df4764.txt index d6cef24569d..b3baac728fc 100644 --- a/.riot/requirements/1df4764.txt +++ b/.riot/requirements/1df4764.txt @@ -5,42 +5,44 @@ # pip-compile --allow-unsafe --no-annotate .riot/requirements/1df4764.in # annotated-types==0.7.0 -anyio==4.7.0 -attrs==24.2.0 -boto3==1.35.78 -botocore==1.35.78 -certifi==2024.8.30 -coverage[toml]==7.6.9 -fastapi==0.115.6 -h11==0.14.0 -httpcore==1.0.7 +anyio==4.9.0 +attrs==25.3.0 +boto3==1.39.7 +botocore==1.39.7 +certifi==2025.7.14 +coverage[toml]==7.9.2 +fastapi==0.116.1 +h11==0.16.0 +httpcore==1.0.9 httpretty==1.1.4 httpx==0.28.1 hypothesis==6.45.0 idna==3.10 -iniconfig==2.0.0 +iniconfig==2.1.0 jmespath==1.0.1 -mock==5.1.0 -msgpack==1.1.0 +mock==5.2.0 +msgpack==1.1.1 opentracing==2.4.0 -packaging==24.2 -pluggy==1.5.0 -pydantic==2.10.3 -pydantic-core==2.27.1 -pytest==8.3.4 -pytest-cov==6.0.0 -pytest-mock==3.14.0 +packaging==25.0 +pluggy==1.6.0 +pydantic==2.11.7 +pydantic-core==2.33.2 +pygments==2.19.2 +pytest==8.4.1 +pytest-cov==6.2.1 +pytest-mock==3.14.1 pytest-randomly==3.16.0 python-dateutil==2.9.0.post0 -s3transfer==0.10.4 +s3transfer==0.13.0 six==1.17.0 sniffio==1.3.1 sortedcontainers==2.4.0 -starlette==0.41.3 -structlog==24.4.0 -typing-extensions==4.12.2 -urllib3==2.2.3 +starlette==0.47.1 +structlog==25.4.0 +typing-extensions==4.14.1 +typing-inspection==0.4.1 +urllib3==2.5.0 wheel==0.45.1 # The following packages are considered to be unsafe in a requirements file: -setuptools==75.6.0 +setuptools==80.9.0 diff --git a/.riot/requirements/7bbf828.txt b/.riot/requirements/7bbf828.txt index e1c39713bce..dbb765cc46b 100644 --- a/.riot/requirements/7bbf828.txt +++ b/.riot/requirements/7bbf828.txt @@ -5,42 +5,44 @@ # pip-compile --allow-unsafe --no-annotate .riot/requirements/7bbf828.in # annotated-types==0.7.0 -anyio==4.7.0 -attrs==24.2.0 -boto3==1.35.78 -botocore==1.35.78 -certifi==2024.8.30 -coverage[toml]==7.6.9 -fastapi==0.115.6 -h11==0.14.0 -httpcore==1.0.7 +anyio==4.9.0 +attrs==25.3.0 +boto3==1.39.7 +botocore==1.39.7 +certifi==2025.7.14 +coverage[toml]==7.9.2 +fastapi==0.116.1 +h11==0.16.0 +httpcore==1.0.9 httpretty==1.1.4 httpx==0.28.1 hypothesis==6.45.0 idna==3.10 -iniconfig==2.0.0 +iniconfig==2.1.0 jmespath==1.0.1 -mock==5.1.0 -msgpack==1.1.0 +mock==5.2.0 +msgpack==1.1.1 opentracing==2.4.0 -packaging==24.2 -pluggy==1.5.0 -pydantic==2.10.3 -pydantic-core==2.27.1 -pytest==8.3.4 -pytest-cov==6.0.0 -pytest-mock==3.14.0 +packaging==25.0 +pluggy==1.6.0 +pydantic==2.11.7 +pydantic-core==2.33.2 +pygments==2.19.2 +pytest==8.4.1 +pytest-cov==6.2.1 +pytest-mock==3.14.1 pytest-randomly==3.16.0 python-dateutil==2.9.0.post0 -s3transfer==0.10.4 +s3transfer==0.13.0 six==1.17.0 sniffio==1.3.1 sortedcontainers==2.4.0 -starlette==0.41.3 -structlog==24.4.0 -typing-extensions==4.12.2 -urllib3==2.2.3 +starlette==0.47.1 +structlog==25.4.0 +typing-extensions==4.14.1 +typing-inspection==0.4.1 +urllib3==2.5.0 wheel==0.45.1 # The following packages are considered to be unsafe in a requirements file: -setuptools==75.6.0 +setuptools==80.9.0 diff --git a/.riot/requirements/b35a160.txt b/.riot/requirements/b35a160.txt index d0202d9b774..543a1b964a0 100644 --- a/.riot/requirements/b35a160.txt +++ b/.riot/requirements/b35a160.txt @@ -2,50 +2,50 @@ # This file is autogenerated by pip-compile with Python 3.8 # by the following command: # -# pip-compile --no-annotate .riot/requirements/b35a160.in +# pip-compile --allow-unsafe --no-annotate .riot/requirements/b35a160.in # annotated-types==0.7.0 anyio==4.5.2 attrs==22.1.0 -boto3==1.36.9 -botocore==1.36.9 +boto3==1.37.38 +botocore==1.37.38 cattrs==23.1.2 -certifi==2024.12.14 +certifi==2025.7.14 coverage[toml]==7.6.1 -exceptiongroup==1.2.2 -fastapi==0.115.8 -h11==0.14.0 -httpcore==1.0.7 +exceptiongroup==1.3.0 +fastapi==0.116.1 +h11==0.16.0 +httpcore==1.0.9 httpretty==1.1.4 httpx==0.28.1 hypothesis==6.45.0 idna==3.10 importlib-metadata==8.5.0 -iniconfig==2.0.0 +iniconfig==2.1.0 jmespath==1.0.1 -mock==5.1.0 -msgpack==1.1.0 +mock==5.2.0 +msgpack==1.1.1 opentracing==2.4.0 -packaging==24.2 +packaging==25.0 pluggy==1.5.0 pydantic==2.10.6 pydantic-core==2.27.2 -pytest==8.3.4 +pytest==8.3.5 pytest-cov==5.0.0 -pytest-mock==3.14.0 +pytest-mock==3.14.1 pytest-randomly==3.15.0 python-dateutil==2.9.0.post0 -s3transfer==0.11.2 +s3transfer==0.11.5 six==1.17.0 sniffio==1.3.1 sortedcontainers==2.4.0 starlette==0.44.0 -structlog==25.1.0 +structlog==25.4.0 tomli==2.2.1 -typing-extensions==4.12.2 +typing-extensions==4.13.2 urllib3==1.26.20 wheel==0.45.1 zipp==3.20.2 # The following packages are considered to be unsafe in a requirements file: -# setuptools +setuptools==75.3.2 diff --git a/.riot/requirements/bcbec2a.txt b/.riot/requirements/bcbec2a.txt index 665c0aadc1a..1f9a7e231f6 100644 --- a/.riot/requirements/bcbec2a.txt +++ b/.riot/requirements/bcbec2a.txt @@ -5,42 +5,44 @@ # pip-compile --allow-unsafe --no-annotate .riot/requirements/bcbec2a.in # annotated-types==0.7.0 -anyio==4.7.0 -attrs==24.2.0 -boto3==1.35.78 -botocore==1.35.78 -certifi==2024.8.30 -coverage[toml]==7.6.9 -fastapi==0.115.6 -h11==0.14.0 -httpcore==1.0.7 +anyio==4.9.0 +attrs==25.3.0 +boto3==1.39.7 +botocore==1.39.7 +certifi==2025.7.14 +coverage[toml]==7.9.2 +fastapi==0.116.1 +h11==0.16.0 +httpcore==1.0.9 httpretty==1.1.4 httpx==0.28.1 hypothesis==6.45.0 idna==3.10 -iniconfig==2.0.0 +iniconfig==2.1.0 jmespath==1.0.1 -mock==5.1.0 -msgpack==1.1.0 +mock==5.2.0 +msgpack==1.1.1 opentracing==2.4.0 -packaging==24.2 -pluggy==1.5.0 -pydantic==2.10.3 -pydantic-core==2.27.1 -pytest==8.3.4 -pytest-cov==6.0.0 -pytest-mock==3.14.0 +packaging==25.0 +pluggy==1.6.0 +pydantic==2.11.7 +pydantic-core==2.33.2 +pygments==2.19.2 +pytest==8.4.1 +pytest-cov==6.2.1 +pytest-mock==3.14.1 pytest-randomly==3.16.0 python-dateutil==2.9.0.post0 -s3transfer==0.10.4 +s3transfer==0.13.0 six==1.17.0 sniffio==1.3.1 sortedcontainers==2.4.0 -starlette==0.41.3 -structlog==24.4.0 -typing-extensions==4.12.2 -urllib3==2.2.3 +starlette==0.47.1 +structlog==25.4.0 +typing-extensions==4.14.1 +typing-inspection==0.4.1 +urllib3==2.5.0 wheel==0.45.1 # The following packages are considered to be unsafe in a requirements file: -setuptools==75.6.0 +setuptools==80.9.0 From f736ab2882d2bda3d60a10614ac642effb701b88 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?V=C3=ADtor=20De=20Ara=C3=BAjo?= Date: Wed, 16 Jul 2025 21:40:54 +0000 Subject: [PATCH 3/7] riotfiles, the revenge --- .riot/requirements/159f4bb.txt | 48 ------------------------------- .riot/requirements/15e8745.txt | 48 ------------------------------- .riot/requirements/1793deb.txt | 50 -------------------------------- .riot/requirements/18d037c.txt | 50 -------------------------------- .riot/requirements/1aa24de.txt | 52 ---------------------------------- .riot/requirements/1df4764.txt | 48 ------------------------------- .riot/requirements/7bbf828.txt | 48 ------------------------------- .riot/requirements/b35a160.txt | 51 --------------------------------- .riot/requirements/bcbec2a.txt | 48 ------------------------------- riotfile.py | 1 + 10 files changed, 1 insertion(+), 443 deletions(-) delete mode 100644 .riot/requirements/159f4bb.txt delete mode 100644 .riot/requirements/15e8745.txt delete mode 100644 .riot/requirements/1793deb.txt delete mode 100644 .riot/requirements/18d037c.txt delete mode 100644 .riot/requirements/1aa24de.txt delete mode 100644 .riot/requirements/1df4764.txt delete mode 100644 .riot/requirements/7bbf828.txt delete mode 100644 .riot/requirements/b35a160.txt delete mode 100644 .riot/requirements/bcbec2a.txt diff --git a/.riot/requirements/159f4bb.txt b/.riot/requirements/159f4bb.txt deleted file mode 100644 index 83bb1bcfae3..00000000000 --- a/.riot/requirements/159f4bb.txt +++ /dev/null @@ -1,48 +0,0 @@ -# -# This file is autogenerated by pip-compile with Python 3.11 -# by the following command: -# -# pip-compile --allow-unsafe --no-annotate .riot/requirements/159f4bb.in -# -annotated-types==0.7.0 -anyio==4.9.0 -attrs==25.3.0 -boto3==1.39.7 -botocore==1.39.7 -certifi==2025.7.14 -coverage[toml]==7.9.2 -fastapi==0.116.1 -h11==0.16.0 -httpcore==1.0.9 -httpretty==1.1.4 -httpx==0.28.1 -hypothesis==6.45.0 -idna==3.10 -iniconfig==2.1.0 -jmespath==1.0.1 -mock==5.2.0 -msgpack==1.1.1 -opentracing==2.4.0 -packaging==25.0 -pluggy==1.6.0 -pydantic==2.11.7 -pydantic-core==2.33.2 -pygments==2.19.2 -pytest==8.4.1 -pytest-cov==6.2.1 -pytest-mock==3.14.1 -pytest-randomly==3.16.0 -python-dateutil==2.9.0.post0 -s3transfer==0.13.0 -six==1.17.0 -sniffio==1.3.1 -sortedcontainers==2.4.0 -starlette==0.47.1 -structlog==25.4.0 -typing-extensions==4.14.1 -typing-inspection==0.4.1 -urllib3==2.5.0 -wheel==0.45.1 - -# The following packages are considered to be unsafe in a requirements file: -setuptools==80.9.0 diff --git a/.riot/requirements/15e8745.txt b/.riot/requirements/15e8745.txt deleted file mode 100644 index f96f1b81d6e..00000000000 --- a/.riot/requirements/15e8745.txt +++ /dev/null @@ -1,48 +0,0 @@ -# -# This file is autogenerated by pip-compile with Python 3.12 -# by the following command: -# -# pip-compile --allow-unsafe --no-annotate .riot/requirements/15e8745.in -# -annotated-types==0.7.0 -anyio==4.9.0 -attrs==25.3.0 -boto3==1.39.7 -botocore==1.39.7 -certifi==2025.7.14 -coverage[toml]==7.9.2 -fastapi==0.116.1 -h11==0.16.0 -httpcore==1.0.9 -httpretty==1.1.4 -httpx==0.28.1 -hypothesis==6.45.0 -idna==3.10 -iniconfig==2.1.0 -jmespath==1.0.1 -mock==5.2.0 -msgpack==1.1.1 -opentracing==2.4.0 -packaging==25.0 -pluggy==1.6.0 -pydantic==2.11.7 -pydantic-core==2.33.2 -pygments==2.19.2 -pytest==8.4.1 -pytest-cov==6.2.1 -pytest-mock==3.14.1 -pytest-randomly==3.16.0 -python-dateutil==2.9.0.post0 -s3transfer==0.13.0 -six==1.17.0 -sniffio==1.3.1 -sortedcontainers==2.4.0 -starlette==0.47.1 -structlog==25.4.0 -typing-extensions==4.14.1 -typing-inspection==0.4.1 -urllib3==2.5.0 -wheel==0.45.1 - -# The following packages are considered to be unsafe in a requirements file: -setuptools==80.9.0 diff --git a/.riot/requirements/1793deb.txt b/.riot/requirements/1793deb.txt deleted file mode 100644 index 2fa40553662..00000000000 --- a/.riot/requirements/1793deb.txt +++ /dev/null @@ -1,50 +0,0 @@ -# -# This file is autogenerated by pip-compile with Python 3.8 -# by the following command: -# -# pip-compile --allow-unsafe --no-annotate .riot/requirements/1793deb.in -# -annotated-types==0.7.0 -anyio==4.5.2 -attrs==25.3.0 -boto3==1.37.38 -botocore==1.37.38 -certifi==2025.7.14 -coverage[toml]==7.6.1 -exceptiongroup==1.3.0 -fastapi==0.116.1 -h11==0.16.0 -httpcore==1.0.9 -httpretty==1.1.4 -httpx==0.28.1 -hypothesis==6.45.0 -idna==3.10 -importlib-metadata==8.5.0 -iniconfig==2.1.0 -jmespath==1.0.1 -mock==5.2.0 -msgpack==1.1.1 -opentracing==2.4.0 -packaging==25.0 -pluggy==1.5.0 -pydantic==2.10.6 -pydantic-core==2.27.2 -pytest==8.3.5 -pytest-cov==5.0.0 -pytest-mock==3.14.1 -pytest-randomly==3.15.0 -python-dateutil==2.9.0.post0 -s3transfer==0.11.5 -six==1.17.0 -sniffio==1.3.1 -sortedcontainers==2.4.0 -starlette==0.44.0 -structlog==25.4.0 -tomli==2.2.1 -typing-extensions==4.13.2 -urllib3==1.26.20 -wheel==0.45.1 -zipp==3.20.2 - -# The following packages are considered to be unsafe in a requirements file: -setuptools==75.3.2 diff --git a/.riot/requirements/18d037c.txt b/.riot/requirements/18d037c.txt deleted file mode 100644 index edc46fba034..00000000000 --- a/.riot/requirements/18d037c.txt +++ /dev/null @@ -1,50 +0,0 @@ -# -# This file is autogenerated by pip-compile with Python 3.10 -# by the following command: -# -# pip-compile --allow-unsafe --no-annotate .riot/requirements/18d037c.in -# -annotated-types==0.7.0 -anyio==4.9.0 -attrs==25.3.0 -boto3==1.39.7 -botocore==1.39.7 -certifi==2025.7.14 -coverage[toml]==7.9.2 -exceptiongroup==1.3.0 -fastapi==0.116.1 -h11==0.16.0 -httpcore==1.0.9 -httpretty==1.1.4 -httpx==0.28.1 -hypothesis==6.45.0 -idna==3.10 -iniconfig==2.1.0 -jmespath==1.0.1 -mock==5.2.0 -msgpack==1.1.1 -opentracing==2.4.0 -packaging==25.0 -pluggy==1.6.0 -pydantic==2.11.7 -pydantic-core==2.33.2 -pygments==2.19.2 -pytest==8.4.1 -pytest-cov==6.2.1 -pytest-mock==3.14.1 -pytest-randomly==3.16.0 -python-dateutil==2.9.0.post0 -s3transfer==0.13.0 -six==1.17.0 -sniffio==1.3.1 -sortedcontainers==2.4.0 -starlette==0.47.1 -structlog==25.4.0 -tomli==2.2.1 -typing-extensions==4.14.1 -typing-inspection==0.4.1 -urllib3==2.5.0 -wheel==0.45.1 - -# The following packages are considered to be unsafe in a requirements file: -setuptools==80.9.0 diff --git a/.riot/requirements/1aa24de.txt b/.riot/requirements/1aa24de.txt deleted file mode 100644 index f51192feffe..00000000000 --- a/.riot/requirements/1aa24de.txt +++ /dev/null @@ -1,52 +0,0 @@ -# -# This file is autogenerated by pip-compile with Python 3.9 -# by the following command: -# -# pip-compile --allow-unsafe --no-annotate .riot/requirements/1aa24de.in -# -annotated-types==0.7.0 -anyio==4.9.0 -attrs==25.3.0 -boto3==1.39.7 -botocore==1.39.7 -certifi==2025.7.14 -coverage[toml]==7.9.2 -exceptiongroup==1.3.0 -fastapi==0.116.1 -h11==0.16.0 -httpcore==1.0.9 -httpretty==1.1.4 -httpx==0.28.1 -hypothesis==6.45.0 -idna==3.10 -importlib-metadata==8.7.0 -iniconfig==2.1.0 -jmespath==1.0.1 -mock==5.2.0 -msgpack==1.1.1 -opentracing==2.4.0 -packaging==25.0 -pluggy==1.6.0 -pydantic==2.11.7 -pydantic-core==2.33.2 -pygments==2.19.2 -pytest==8.4.1 -pytest-cov==6.2.1 -pytest-mock==3.14.1 -pytest-randomly==3.16.0 -python-dateutil==2.9.0.post0 -s3transfer==0.13.0 -six==1.17.0 -sniffio==1.3.1 -sortedcontainers==2.4.0 -starlette==0.47.1 -structlog==25.4.0 -tomli==2.2.1 -typing-extensions==4.14.1 -typing-inspection==0.4.1 -urllib3==1.26.20 -wheel==0.45.1 -zipp==3.23.0 - -# The following packages are considered to be unsafe in a requirements file: -setuptools==80.9.0 diff --git a/.riot/requirements/1df4764.txt b/.riot/requirements/1df4764.txt deleted file mode 100644 index b3baac728fc..00000000000 --- a/.riot/requirements/1df4764.txt +++ /dev/null @@ -1,48 +0,0 @@ -# -# This file is autogenerated by pip-compile with Python 3.13 -# by the following command: -# -# pip-compile --allow-unsafe --no-annotate .riot/requirements/1df4764.in -# -annotated-types==0.7.0 -anyio==4.9.0 -attrs==25.3.0 -boto3==1.39.7 -botocore==1.39.7 -certifi==2025.7.14 -coverage[toml]==7.9.2 -fastapi==0.116.1 -h11==0.16.0 -httpcore==1.0.9 -httpretty==1.1.4 -httpx==0.28.1 -hypothesis==6.45.0 -idna==3.10 -iniconfig==2.1.0 -jmespath==1.0.1 -mock==5.2.0 -msgpack==1.1.1 -opentracing==2.4.0 -packaging==25.0 -pluggy==1.6.0 -pydantic==2.11.7 -pydantic-core==2.33.2 -pygments==2.19.2 -pytest==8.4.1 -pytest-cov==6.2.1 -pytest-mock==3.14.1 -pytest-randomly==3.16.0 -python-dateutil==2.9.0.post0 -s3transfer==0.13.0 -six==1.17.0 -sniffio==1.3.1 -sortedcontainers==2.4.0 -starlette==0.47.1 -structlog==25.4.0 -typing-extensions==4.14.1 -typing-inspection==0.4.1 -urllib3==2.5.0 -wheel==0.45.1 - -# The following packages are considered to be unsafe in a requirements file: -setuptools==80.9.0 diff --git a/.riot/requirements/7bbf828.txt b/.riot/requirements/7bbf828.txt deleted file mode 100644 index dbb765cc46b..00000000000 --- a/.riot/requirements/7bbf828.txt +++ /dev/null @@ -1,48 +0,0 @@ -# -# This file is autogenerated by pip-compile with Python 3.13 -# by the following command: -# -# pip-compile --allow-unsafe --no-annotate .riot/requirements/7bbf828.in -# -annotated-types==0.7.0 -anyio==4.9.0 -attrs==25.3.0 -boto3==1.39.7 -botocore==1.39.7 -certifi==2025.7.14 -coverage[toml]==7.9.2 -fastapi==0.116.1 -h11==0.16.0 -httpcore==1.0.9 -httpretty==1.1.4 -httpx==0.28.1 -hypothesis==6.45.0 -idna==3.10 -iniconfig==2.1.0 -jmespath==1.0.1 -mock==5.2.0 -msgpack==1.1.1 -opentracing==2.4.0 -packaging==25.0 -pluggy==1.6.0 -pydantic==2.11.7 -pydantic-core==2.33.2 -pygments==2.19.2 -pytest==8.4.1 -pytest-cov==6.2.1 -pytest-mock==3.14.1 -pytest-randomly==3.16.0 -python-dateutil==2.9.0.post0 -s3transfer==0.13.0 -six==1.17.0 -sniffio==1.3.1 -sortedcontainers==2.4.0 -starlette==0.47.1 -structlog==25.4.0 -typing-extensions==4.14.1 -typing-inspection==0.4.1 -urllib3==2.5.0 -wheel==0.45.1 - -# The following packages are considered to be unsafe in a requirements file: -setuptools==80.9.0 diff --git a/.riot/requirements/b35a160.txt b/.riot/requirements/b35a160.txt deleted file mode 100644 index 543a1b964a0..00000000000 --- a/.riot/requirements/b35a160.txt +++ /dev/null @@ -1,51 +0,0 @@ -# -# This file is autogenerated by pip-compile with Python 3.8 -# by the following command: -# -# pip-compile --allow-unsafe --no-annotate .riot/requirements/b35a160.in -# -annotated-types==0.7.0 -anyio==4.5.2 -attrs==22.1.0 -boto3==1.37.38 -botocore==1.37.38 -cattrs==23.1.2 -certifi==2025.7.14 -coverage[toml]==7.6.1 -exceptiongroup==1.3.0 -fastapi==0.116.1 -h11==0.16.0 -httpcore==1.0.9 -httpretty==1.1.4 -httpx==0.28.1 -hypothesis==6.45.0 -idna==3.10 -importlib-metadata==8.5.0 -iniconfig==2.1.0 -jmespath==1.0.1 -mock==5.2.0 -msgpack==1.1.1 -opentracing==2.4.0 -packaging==25.0 -pluggy==1.5.0 -pydantic==2.10.6 -pydantic-core==2.27.2 -pytest==8.3.5 -pytest-cov==5.0.0 -pytest-mock==3.14.1 -pytest-randomly==3.15.0 -python-dateutil==2.9.0.post0 -s3transfer==0.11.5 -six==1.17.0 -sniffio==1.3.1 -sortedcontainers==2.4.0 -starlette==0.44.0 -structlog==25.4.0 -tomli==2.2.1 -typing-extensions==4.13.2 -urllib3==1.26.20 -wheel==0.45.1 -zipp==3.20.2 - -# The following packages are considered to be unsafe in a requirements file: -setuptools==75.3.2 diff --git a/.riot/requirements/bcbec2a.txt b/.riot/requirements/bcbec2a.txt deleted file mode 100644 index 1f9a7e231f6..00000000000 --- a/.riot/requirements/bcbec2a.txt +++ /dev/null @@ -1,48 +0,0 @@ -# -# This file is autogenerated by pip-compile with Python 3.13 -# by the following command: -# -# pip-compile --allow-unsafe --no-annotate .riot/requirements/bcbec2a.in -# -annotated-types==0.7.0 -anyio==4.9.0 -attrs==25.3.0 -boto3==1.39.7 -botocore==1.39.7 -certifi==2025.7.14 -coverage[toml]==7.9.2 -fastapi==0.116.1 -h11==0.16.0 -httpcore==1.0.9 -httpretty==1.1.4 -httpx==0.28.1 -hypothesis==6.45.0 -idna==3.10 -iniconfig==2.1.0 -jmespath==1.0.1 -mock==5.2.0 -msgpack==1.1.1 -opentracing==2.4.0 -packaging==25.0 -pluggy==1.6.0 -pydantic==2.11.7 -pydantic-core==2.33.2 -pygments==2.19.2 -pytest==8.4.1 -pytest-cov==6.2.1 -pytest-mock==3.14.1 -pytest-randomly==3.16.0 -python-dateutil==2.9.0.post0 -s3transfer==0.13.0 -six==1.17.0 -sniffio==1.3.1 -sortedcontainers==2.4.0 -starlette==0.47.1 -structlog==25.4.0 -typing-extensions==4.14.1 -typing-inspection==0.4.1 -urllib3==2.5.0 -wheel==0.45.1 - -# The following packages are considered to be unsafe in a requirements file: -setuptools==80.9.0 diff --git a/riotfile.py b/riotfile.py index c3f3c66dce2..9e81bce5785 100644 --- a/riotfile.py +++ b/riotfile.py @@ -352,6 +352,7 @@ def select_pys(min_version: str = MIN_PYTHON_VERSION, max_version: str = MAX_PYT "pytest-randomly": latest, "setuptools": latest, "boto3": latest, + "freezegun": latest, }, env={ "DD_CIVISIBILITY_LOG_LEVEL": "none", From 6db09e38270d95ee34a3e3ab452d0ac49fc33467 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?V=C3=ADtor=20De=20Ara=C3=BAjo?= Date: Thu, 17 Jul 2025 10:08:21 +0000 Subject: [PATCH 4/7] release note --- ...tracer-fix-freezegun-span-durations-8386151643ca8d35.yaml | 5 +++++ 1 file changed, 5 insertions(+) create mode 100644 releasenotes/notes/tracer-fix-freezegun-span-durations-8386151643ca8d35.yaml diff --git a/releasenotes/notes/tracer-fix-freezegun-span-durations-8386151643ca8d35.yaml b/releasenotes/notes/tracer-fix-freezegun-span-durations-8386151643ca8d35.yaml new file mode 100644 index 00000000000..48a8a6ced70 --- /dev/null +++ b/releasenotes/notes/tracer-fix-freezegun-span-durations-8386151643ca8d35.yaml @@ -0,0 +1,5 @@ +--- +fixes: + - | + tracing: This fix resolves an issue where spans would have incorrect timestamps and durations when ``freezegun`` was + in use. With this change, the ``freezegun`` integration is not necessary anymore. From ccd14598c69a2c663b503550eaad4310d23500f2 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?V=C3=ADtor=20De=20Ara=C3=BAjo?= Date: Wed, 16 Jul 2025 21:20:02 +0000 Subject: [PATCH 5/7] fix(freezegun): remove freezegun integration --- .github/CODEOWNERS | 4 - ddtrace/_monkey.py | 1 - ddtrace/contrib/_freezegun.py | 14 --- .../integration_registry/registry.yaml | 10 -- ddtrace/contrib/internal/freezegun/patch.py | 74 ----------- ddtrace/contrib/internal/pytest/_plugin_v2.py | 5 - ddtrace/settings/_config.py | 1 - docs/index.rst | 2 - docs/integrations.rst | 7 -- riotfile.py | 15 --- tests/ci_visibility/suitespec.yml | 6 - tests/contrib/freezegun/test_freezegun.py | 115 ------------------ tests/contrib/suitespec.yml | 13 -- 13 files changed, 267 deletions(-) delete mode 100644 ddtrace/contrib/_freezegun.py delete mode 100644 ddtrace/contrib/internal/freezegun/patch.py delete mode 100644 tests/contrib/freezegun/test_freezegun.py diff --git a/.github/CODEOWNERS b/.github/CODEOWNERS index 6507113b3e8..ad7f61bfee0 100644 --- a/.github/CODEOWNERS +++ b/.github/CODEOWNERS @@ -82,10 +82,6 @@ tests/coverage @DataDog/apm-core-python @ tests/tracer/test_ci.py @DataDog/ci-app-libraries ddtrace/ext/git.py @DataDog/ci-app-libraries @DataDog/apm-core-python scripts/ci_visibility/* @DataDog/ci-app-libraries -# Test Visibility owns the freezegun integration because it's the team most affected by it -ddtrace/contrib/freezegun @DataDog/ci-app-libraries -ddtrace/contrib/internal/freezegun @DataDog/ci-app-libraries -tests/contrib/freezegun @DataDog/ci-app-libraries # Test Visibility: Selenium integration ddtrace/contrib/selenium @DataDog/ci-app-libraries ddtrace/internal/selenium @DataDog/ci-app-libraries diff --git a/ddtrace/_monkey.py b/ddtrace/_monkey.py index 220bbcfd0dd..1126fa5dfba 100644 --- a/ddtrace/_monkey.py +++ b/ddtrace/_monkey.py @@ -48,7 +48,6 @@ "elasticsearch": True, "algoliasearch": True, "futures": True, - "freezegun": True, "google_generativeai": True, "google_genai": True, "gevent": True, diff --git a/ddtrace/contrib/_freezegun.py b/ddtrace/contrib/_freezegun.py deleted file mode 100644 index d9f48ded072..00000000000 --- a/ddtrace/contrib/_freezegun.py +++ /dev/null @@ -1,14 +0,0 @@ -""" -The freezegun integration reconfigures freezegun's default ignore list to ignore ddtrace. - -Enabling -~~~~~~~~ -The freezegun integration is enabled by default. Use :func:`patch()` to enable the integration:: - from ddtrace import patch - patch(freezegun=True) - - -Configuration -~~~~~~~~~~~~~ -The freezegun integration is not configurable, but may be disabled using DD_PATCH_MODULES=freezegun:false . -""" diff --git a/ddtrace/contrib/integration_registry/registry.yaml b/ddtrace/contrib/integration_registry/registry.yaml index cad325d5222..fa737d4606a 100644 --- a/ddtrace/contrib/integration_registry/registry.yaml +++ b/ddtrace/contrib/integration_registry/registry.yaml @@ -369,16 +369,6 @@ integrations: min: 1.10.1 max: 2.3.0 -- integration_name: freezegun - is_external_package: true - is_tested: true - dependency_names: - - freezegun - tested_versions_by_dependency: - freezegun: - min: 1.3.1 - max: 1.5.2 - - integration_name: futures is_external_package: false is_tested: true diff --git a/ddtrace/contrib/internal/freezegun/patch.py b/ddtrace/contrib/internal/freezegun/patch.py deleted file mode 100644 index c9058bf354c..00000000000 --- a/ddtrace/contrib/internal/freezegun/patch.py +++ /dev/null @@ -1,74 +0,0 @@ -from typing import Dict - -from ddtrace.internal.logger import get_logger -from ddtrace.internal.wrapping.context import WrappingContext - - -log = get_logger(__name__) - -DDTRACE_MODULE_NAME = "ddtrace" - - -class FreezegunConfigWrappingContext(WrappingContext): - """Wraps the call to freezegun.configure to ensure that ddtrace remains patched if default_ignore_list is passed - in as an argument - """ - - # __exit__ comes from the parent class - # no-dd-sa:python-best-practices/ctx-manager-enter-exit-defined - def __enter__(self) -> "FreezegunConfigWrappingContext": - super().__enter__() - try: - default_ignore_list = self.get_local("default_ignore_list") - except KeyError: - log.debug("Could not get default_ignore_list on call to configure()") - return - - if default_ignore_list is not None and DDTRACE_MODULE_NAME not in default_ignore_list: - default_ignore_list.append(DDTRACE_MODULE_NAME) - - return self - - -def get_version() -> str: - import freezegun - - try: - return freezegun.__version__ - except AttributeError: - log.debug("Could not get freezegun version") - return "" - - -def _supported_versions() -> Dict[str, str]: - return {"freezegun": "*"} - - -def patch() -> None: - import freezegun - - if getattr(freezegun, "_datadog_patch", False): - return - - FreezegunConfigWrappingContext(freezegun.configure).wrap() - - freezegun.configure(extend_ignore_list=[DDTRACE_MODULE_NAME]) - - freezegun._datadog_patch = True - - -def unpatch() -> None: - import freezegun - - if not getattr(freezegun, "_datadog_patch", False): - return - - if FreezegunConfigWrappingContext.is_wrapped(freezegun.configure): - FreezegunConfigWrappingContext.extract(freezegun.configure).unwrap() - - # Note: we do not want to restore to the original ignore list, as it may have been modified by the user, but we do - # want to remove the ddtrace module from the ignore list - new_ignore_list = [m for m in freezegun.config.settings.default_ignore_list if m != DDTRACE_MODULE_NAME] - freezegun.configure(default_ignore_list=new_ignore_list) - - freezegun._datadog_patch = False diff --git a/ddtrace/contrib/internal/pytest/_plugin_v2.py b/ddtrace/contrib/internal/pytest/_plugin_v2.py index 93eeb9e0ba4..996dcc10fb5 100644 --- a/ddtrace/contrib/internal/pytest/_plugin_v2.py +++ b/ddtrace/contrib/internal/pytest/_plugin_v2.py @@ -242,11 +242,6 @@ def _pytest_load_initial_conftests_pre_yield(early_config, parser, args): try: take_over_logger_stream_handler() - if not asbool(os.getenv("_DD_PYTEST_FREEZEGUN_SKIP_PATCH")): - from ddtrace._monkey import patch - - # Freezegun is proactively patched to avoid it interfering with internal timing - patch(freezegun=True) dd_config.test_visibility.itr_skipping_level = ITR_SKIPPING_LEVEL.SUITE enable_test_visibility(config=dd_config.pytest) if InternalTestSession.should_collect_coverage(): diff --git a/ddtrace/settings/_config.py b/ddtrace/settings/_config.py index 53c2822fc56..c7ca4ee32e9 100644 --- a/ddtrace/settings/_config.py +++ b/ddtrace/settings/_config.py @@ -124,7 +124,6 @@ "protobuf", "aiohttp_jinja2", "pymongo", - "freezegun", "vertica", "rq_worker", "elasticsearch", diff --git a/docs/index.rst b/docs/index.rst index 1b6766e53b6..386d85fc0dd 100644 --- a/docs/index.rst +++ b/docs/index.rst @@ -106,8 +106,6 @@ contacting support. +--------------------------------------------------+---------------+----------------+ | :ref:`flask_cache` | >= 0.13 | No | +--------------------------------------------------+---------------+----------------+ -| :ref:`freezegun` | \* | Yes | -+--------------------------------------------------+---------------+----------------+ | :ref:`futures` | \* | Yes | +--------------------------------------------------+---------------+----------------+ | :ref:`gevent` (greenlet>=1.0) | >= 20.12 | Yes | diff --git a/docs/integrations.rst b/docs/integrations.rst index 53b43d3307a..9c65d48051c 100644 --- a/docs/integrations.rst +++ b/docs/integrations.rst @@ -216,13 +216,6 @@ Flask Cache .. automodule:: ddtrace.contrib.flask_cache -.. _freezegun: - -FreezeGun -^^^^^^^^^ -.. automodule:: ddtrace.contrib._freezegun - - .. _futures: futures diff --git a/riotfile.py b/riotfile.py index 9e81bce5785..2d04886f30d 100644 --- a/riotfile.py +++ b/riotfile.py @@ -3335,21 +3335,6 @@ def select_pys(min_version: str = MIN_PYTHON_VERSION, max_version: str = MAX_PYT ), ], ), - Venv( - name="freezegun", - command="pytest tests/contrib/freezegun {cmdargs}", - pkgs={ - "pytest-randomly": latest, - }, - venvs=[ - Venv( - pys=["3.10", "3.12"], - pkgs={ - "freezegun": ["~=1.3.0", "~=1.5.0"], - }, - ), - ], - ), Venv( name="appsec_integrations_flask", command="pytest -vvv {cmdargs} tests/appsec/integrations/flask_tests/", diff --git a/tests/ci_visibility/suitespec.yml b/tests/ci_visibility/suitespec.yml index 8945979a99a..3ecd0ca6b1b 100644 --- a/tests/ci_visibility/suitespec.yml +++ b/tests/ci_visibility/suitespec.yml @@ -19,8 +19,6 @@ components: unittest: - ddtrace/contrib/_unittest.py - ddtrace/contrib/internal/unittest/* - freezegun: - - ddtrace/contrib/internal/freezegun/* suites: ci_visibility: parallelism: 4 @@ -33,7 +31,6 @@ suites: - '@pytest' - '@codeowners' - '@unittest' - - '@freezegun' - tests/ci_visibility/* runner: riot snapshot: true @@ -58,7 +55,6 @@ suites: - '@ci_visibility' - '@coverage' - '@codeowners' - - '@freezegun' - tests/contrib/pytest/* - tests/contrib/pytest_benchmark/* - tests/contrib/pytest_bdd/* @@ -77,7 +73,6 @@ suites: - '@ci_visibility' - '@coverage' - '@codeowners' - - '@freezegun' - tests/contrib/pytest/* - tests/contrib/pytest_benchmark/* - tests/contrib/pytest_bdd/* @@ -107,7 +102,6 @@ suites: - '@unittest' - '@ci_visibility' - '@coverage' - - '@freezegun' - tests/contrib/unittest/* - tests/snapshots/tests.contrib.unittest.* runner: riot diff --git a/tests/contrib/freezegun/test_freezegun.py b/tests/contrib/freezegun/test_freezegun.py deleted file mode 100644 index 07554039ee9..00000000000 --- a/tests/contrib/freezegun/test_freezegun.py +++ /dev/null @@ -1,115 +0,0 @@ -import datetime -import os -import time - -import pytest - -from ddtrace.internal.utils.time import StopWatch -from ddtrace.trace import tracer as dd_tracer -from tests.contrib.pytest.test_pytest import PytestTestCaseBase -from tests.utils import flaky - - -class TestFreezegunTestCase: - @pytest.fixture(autouse=True) - def _patch_freezegun(self): - from ddtrace.contrib.internal.freezegun.patch import patch - from ddtrace.contrib.internal.freezegun.patch import unpatch - - patch() - yield - unpatch() - - @flaky(1759346444) - def test_freezegun_unpatch(self): - import freezegun - - from ddtrace.contrib.internal.freezegun.patch import unpatch - - unpatch() - - with freezegun.freeze_time("2020-01-01"): - with dd_tracer.trace("freezegun.test") as span: - time.sleep(1) - - assert span.duration == 0 - - def test_freezegun_does_not_freeze_tracing(self): - import freezegun - - with freezegun.freeze_time("2020-01-01"): - with dd_tracer.trace("freezegun.test") as span: - time.sleep(1) - - assert span.duration >= 1 - - def test_freezegun_fast_forward_does_not_affect_tracing(self): - import freezegun - - with freezegun.freeze_time("2020-01-01") as frozen_time: - with dd_tracer.trace("freezegun.test") as span: - time.sleep(1) - frozen_time.tick(delta=datetime.timedelta(days=10)) - assert 1 <= span.duration <= 5 - - def test_freezegun_does_not_freeze_stopwatch(self): - import freezegun - - with freezegun.freeze_time("2020-01-01"): - with StopWatch() as sw: - time.sleep(1) - assert sw.elapsed() >= 1 - - def test_freezegun_configure_default_ignore_list_continues_to_ignore_ddtrace(self): - import freezegun - from freezegun.config import DEFAULT_IGNORE_LIST - - try: - freezegun.configure(default_ignore_list=[]) - - with freezegun.freeze_time("2020-01-01"): - with dd_tracer.trace("freezegun.test") as span: - time.sleep(1) - - assert span.duration >= 1 - finally: - # Reset the ignore list to its default value after the test - freezegun.configure(default_ignore_list=DEFAULT_IGNORE_LIST) - - -class PytestFreezegunTestCase(PytestTestCaseBase): - @flaky(1759346444) - def test_freezegun_pytest_plugin(self): - """Tests that pytest's patching of freezegun in the v1 plugin version works""" - import sys - - from ddtrace.contrib.internal.freezegun.patch import unpatch - - unpatch() - if "freezegun" in sys.modules: - del sys.modules["freezegun"] - - py_file = self.testdir.makepyfile( - """ - import datetime - import time - - import freezegun - - from ddtrace.trace import tracer as dd_tracer - - def test_pytest_patched_freezegun(): - with freezegun.freeze_time("2020-01-01"): - with dd_tracer.trace("freezegun.test") as span: - time.sleep(1) - assert span.duration >= 1 - - """ - ) - file_name = os.path.basename(py_file.strpath) - self.inline_run("--ddtrace", "-s", file_name) - spans = self.pop_spans() - - assert len(spans) == 4 - for span in spans: - assert span.get_tag("test.status") == "pass" diff --git a/tests/contrib/suitespec.yml b/tests/contrib/suitespec.yml index db7594aba61..c4506b990f7 100644 --- a/tests/contrib/suitespec.yml +++ b/tests/contrib/suitespec.yml @@ -107,9 +107,6 @@ components: - ddtrace/contrib/internal/flask/* - ddtrace/contrib/flask_cache.py - ddtrace/contrib/internal/flask_cache/* - freezegun: - - ddtrace/contrib/_freezegun.py - - ddtrace/contrib/internal/freezegun/* futures: - ddtrace/contrib/_futures.py - ddtrace/contrib/internal/futures/* @@ -705,16 +702,6 @@ suites: - memcached - redis snapshot: true - freezegun: - paths: - - '@bootstrap' - - '@core' - - '@contrib' - - '@tracing' - - '@freezegun' - - tests/contrib/freezegun/* - runner: riot - snapshot: true gevent: paths: - '@bootstrap' From 630d41a5da57755d29f0e8b1fdfdf2509e9862a5 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?V=C3=ADtor=20De=20Ara=C3=BAjo?= Date: Wed, 16 Jul 2025 21:21:22 +0000 Subject: [PATCH 6/7] remove riot envs --- .riot/requirements/14676df.txt | 26 -------------------------- .riot/requirements/15de642.txt | 23 ----------------------- .riot/requirements/1d1dbc1.txt | 26 -------------------------- .riot/requirements/2bcce4e.txt | 23 ----------------------- 4 files changed, 98 deletions(-) delete mode 100644 .riot/requirements/14676df.txt delete mode 100644 .riot/requirements/15de642.txt delete mode 100644 .riot/requirements/1d1dbc1.txt delete mode 100644 .riot/requirements/2bcce4e.txt diff --git a/.riot/requirements/14676df.txt b/.riot/requirements/14676df.txt deleted file mode 100644 index 055678228c9..00000000000 --- a/.riot/requirements/14676df.txt +++ /dev/null @@ -1,26 +0,0 @@ -# -# This file is autogenerated by pip-compile with Python 3.10 -# by the following command: -# -# pip-compile --no-annotate .riot/requirements/14676df.in -# -attrs==25.3.0 -coverage[toml]==7.8.2 -exceptiongroup==1.3.0 -freezegun==1.5.2 -hypothesis==6.45.0 -iniconfig==2.1.0 -mock==5.2.0 -opentracing==2.4.0 -packaging==25.0 -pluggy==1.6.0 -pygments==2.19.1 -pytest==8.4.0 -pytest-cov==6.1.1 -pytest-mock==3.14.1 -pytest-randomly==3.16.0 -python-dateutil==2.9.0.post0 -six==1.17.0 -sortedcontainers==2.4.0 -tomli==2.2.1 -typing-extensions==4.14.0 diff --git a/.riot/requirements/15de642.txt b/.riot/requirements/15de642.txt deleted file mode 100644 index 9e138c07de8..00000000000 --- a/.riot/requirements/15de642.txt +++ /dev/null @@ -1,23 +0,0 @@ -# -# This file is autogenerated by pip-compile with Python 3.12 -# by the following command: -# -# pip-compile --no-annotate .riot/requirements/15de642.in -# -attrs==25.3.0 -coverage[toml]==7.8.2 -freezegun==1.5.2 -hypothesis==6.45.0 -iniconfig==2.1.0 -mock==5.2.0 -opentracing==2.4.0 -packaging==25.0 -pluggy==1.6.0 -pygments==2.19.1 -pytest==8.4.0 -pytest-cov==6.1.1 -pytest-mock==3.14.1 -pytest-randomly==3.16.0 -python-dateutil==2.9.0.post0 -six==1.17.0 -sortedcontainers==2.4.0 diff --git a/.riot/requirements/1d1dbc1.txt b/.riot/requirements/1d1dbc1.txt deleted file mode 100644 index 179f45bf156..00000000000 --- a/.riot/requirements/1d1dbc1.txt +++ /dev/null @@ -1,26 +0,0 @@ -# -# This file is autogenerated by pip-compile with Python 3.10 -# by the following command: -# -# pip-compile --no-annotate .riot/requirements/1d1dbc1.in -# -attrs==25.3.0 -coverage[toml]==7.8.2 -exceptiongroup==1.3.0 -freezegun==1.3.1 -hypothesis==6.45.0 -iniconfig==2.1.0 -mock==5.2.0 -opentracing==2.4.0 -packaging==25.0 -pluggy==1.6.0 -pygments==2.19.1 -pytest==8.4.0 -pytest-cov==6.1.1 -pytest-mock==3.14.1 -pytest-randomly==3.16.0 -python-dateutil==2.9.0.post0 -six==1.17.0 -sortedcontainers==2.4.0 -tomli==2.2.1 -typing-extensions==4.14.0 diff --git a/.riot/requirements/2bcce4e.txt b/.riot/requirements/2bcce4e.txt deleted file mode 100644 index c444938efa6..00000000000 --- a/.riot/requirements/2bcce4e.txt +++ /dev/null @@ -1,23 +0,0 @@ -# -# This file is autogenerated by pip-compile with Python 3.12 -# by the following command: -# -# pip-compile --no-annotate .riot/requirements/2bcce4e.in -# -attrs==25.3.0 -coverage[toml]==7.8.2 -freezegun==1.3.1 -hypothesis==6.45.0 -iniconfig==2.1.0 -mock==5.2.0 -opentracing==2.4.0 -packaging==25.0 -pluggy==1.6.0 -pygments==2.19.1 -pytest==8.4.0 -pytest-cov==6.1.1 -pytest-mock==3.14.1 -pytest-randomly==3.16.0 -python-dateutil==2.9.0.post0 -six==1.17.0 -sortedcontainers==2.4.0 From 0c3c7ccf956ebd63e43a2100c2cf837450a4e092 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?V=C3=ADtor=20De=20Ara=C3=BAjo?= Date: Thu, 17 Jul 2025 10:15:09 +0000 Subject: [PATCH 7/7] release note --- .../remove-freezegun-integration-525a4d789e0d08f4.yaml | 6 ++++++ 1 file changed, 6 insertions(+) create mode 100644 releasenotes/notes/remove-freezegun-integration-525a4d789e0d08f4.yaml diff --git a/releasenotes/notes/remove-freezegun-integration-525a4d789e0d08f4.yaml b/releasenotes/notes/remove-freezegun-integration-525a4d789e0d08f4.yaml new file mode 100644 index 00000000000..d49d61b1d3d --- /dev/null +++ b/releasenotes/notes/remove-freezegun-integration-525a4d789e0d08f4.yaml @@ -0,0 +1,6 @@ +--- +fixes: + - | + CI Visibility: This fix resolves an issue where ``freezegun`` would not work with tests defined in ``unittest`` + classes. The ``freezegun`` integration was removed, as it is not necessary anymore for the correct reporting of test + durations and timestamps.