diff --git a/.github/workflows/ci.yml b/.github/workflows/ci.yml index e8931e229e..03ed8de742 100644 --- a/.github/workflows/ci.yml +++ b/.github/workflows/ci.yml @@ -44,7 +44,11 @@ jobs: with: python-version: 3.12 - - run: | + - name: Detect unexpected changes to tox.ini or CI + run: | + pip install -e . + pip install -r scripts/populate_tox/requirements.txt + python scripts/populate_tox/populate_tox.py --fail-on-changes pip install -r scripts/split_tox_gh_actions/requirements.txt python scripts/split_tox_gh_actions/split_tox_gh_actions.py --fail-on-changes diff --git a/.github/workflows/release.yml b/.github/workflows/release.yml index ae9ae279c7..4d8c060f6a 100644 --- a/.github/workflows/release.yml +++ b/.github/workflows/release.yml @@ -20,7 +20,7 @@ jobs: steps: - name: Get auth token id: token - uses: actions/create-github-app-token@67e27a7eb7db372a1c61a7f9bdab8699e9ee57f7 # v1.11.3 + uses: actions/create-github-app-token@0d564482f06ca65fa9e77e2510873638c82206f2 # v1.11.5 with: app-id: ${{ vars.SENTRY_RELEASE_BOT_CLIENT_ID }} private-key: ${{ secrets.SENTRY_RELEASE_BOT_PRIVATE_KEY }} diff --git a/requirements-docs.txt b/requirements-docs.txt index 15f226aac7..81e04ba3ef 100644 --- a/requirements-docs.txt +++ b/requirements-docs.txt @@ -1,5 +1,5 @@ gevent shibuya -sphinx +sphinx<8.2 sphinx-autodoc-typehints[type_comments]>=1.8.0 typing-extensions diff --git a/scripts/populate_tox/README.md b/scripts/populate_tox/README.md index aa9884387e..c9a3b67ba0 100644 --- a/scripts/populate_tox/README.md +++ b/scripts/populate_tox/README.md @@ -45,9 +45,15 @@ integration_name: { rule2: [package3, package4, ...], }, "python": python_version_specifier, + "include": package_version_specifier, } ``` +When talking about version specifiers, we mean +[version specifiers as defined](https://packaging.python.org/en/latest/specifications/version-specifiers/#id5) +by the Python Packaging Authority. See also the actual implementation +in [packaging.specifiers](https://packaging.pypa.io/en/stable/specifiers.html). + ### `package` The name of the third party package as it's listed on PyPI. The script will @@ -118,6 +124,35 @@ metadata or the SDK is explicitly not supporting some packages on specific Python versions (because of, for example, broken context vars), the `python` key can be used. +### `include` + +Sometimes we only want to consider testing some specific versions of packages. +For example, the Starlite package has two alpha prereleases of version 2.0.0, but +we do not want to test these, since Starlite 2.0 was renamed to Litestar. + +The value of the `include` key expects a version specifier defining which +versions should be considered for testing. For example, since we only want to test +versions below 2.x in Starlite, we can use + +```python +"starlite": { + "include": "<2", + ... +} +``` + +The `include` key can also be used to exclude a set of specific versions by using +`!=` version specifiers. For example, the Starlite restriction above could equivalently +be expressed like so: + + +```python +"starlite": { + "include": "!=2.0.0a1,!=2.0.0a2", + ... +} +``` + ## How-Tos diff --git a/scripts/populate_tox/config.py b/scripts/populate_tox/config.py index 2c2920e7ac..b5da928d80 100644 --- a/scripts/populate_tox/config.py +++ b/scripts/populate_tox/config.py @@ -129,6 +129,7 @@ ], }, "python": "<=3.11", + "include": "!=2.0.0a1,!=2.0.0a2", # these are not relevant as there will never be a stable 2.0 release (starlite continues as litestar) }, "statsig": { "package": "statsig", diff --git a/scripts/populate_tox/populate_tox.py b/scripts/populate_tox/populate_tox.py index 4bfce80ce7..544d4bdcb1 100644 --- a/scripts/populate_tox/populate_tox.py +++ b/scripts/populate_tox/populate_tox.py @@ -3,15 +3,18 @@ """ import functools +import hashlib import os import sys import time from bisect import bisect_left from collections import defaultdict +from datetime import datetime, timezone from importlib.metadata import metadata from packaging.specifiers import SpecifierSet from packaging.version import Version from pathlib import Path +from textwrap import dedent from typing import Optional, Union # Adding the scripts directory to PATH. This is necessary in order to be able @@ -106,7 +109,9 @@ def fetch_release(package: str, version: Version) -> dict: return pypi_data.json() -def _prefilter_releases(integration: str, releases: dict[str, dict]) -> list[Version]: +def _prefilter_releases( + integration: str, releases: dict[str, dict], older_than: Optional[datetime] = None +) -> tuple[list[Version], Optional[Version]]: """ Filter `releases`, removing releases that are for sure unsupported. @@ -115,6 +120,10 @@ def _prefilter_releases(integration: str, releases: dict[str, dict]) -> list[Ver they require additional API calls to be made. The purpose of this function is to slim down the list so that we don't have to make more API calls than necessary for releases that are for sure not supported. + + The function returns a tuple with: + - the list of prefiltered releases + - an optional prerelease if there is one that should be tested """ min_supported = _MIN_VERSIONS.get(integration) if min_supported is not None: @@ -124,7 +133,14 @@ def _prefilter_releases(integration: str, releases: dict[str, dict]) -> list[Ver f" {integration} doesn't have a minimum version defined in sentry_sdk/integrations/__init__.py. Consider defining one" ) + include_versions = None + if TEST_SUITE_CONFIG[integration].get("include") is not None: + include_versions = SpecifierSet( + TEST_SUITE_CONFIG[integration]["include"], prereleases=True + ) + filtered_releases = [] + last_prerelease = None for release, data in releases.items(): if not data: @@ -135,14 +151,24 @@ def _prefilter_releases(integration: str, releases: dict[str, dict]) -> list[Ver if meta["yanked"]: continue + if older_than is not None: + if datetime.fromisoformat(meta["upload_time_iso_8601"]) > older_than: + continue + version = Version(release) if min_supported and version < min_supported: continue - if version.is_prerelease or version.is_postrelease: - # TODO: consider the newest prerelease unless obsolete - # https://github.com/getsentry/sentry-python/issues/4030 + if version.is_postrelease or version.is_devrelease: + continue + + if include_versions is not None and version not in include_versions: + continue + + if version.is_prerelease: + if last_prerelease is None or version > last_prerelease: + last_prerelease = version continue for i, saved_version in enumerate(filtered_releases): @@ -157,22 +183,41 @@ def _prefilter_releases(integration: str, releases: dict[str, dict]) -> list[Ver else: filtered_releases.append(version) - return sorted(filtered_releases) + filtered_releases.sort() + + # Check if the latest prerelease is relevant (i.e., it's for a version higher + # than the last released version); if not, don't consider it + if last_prerelease is not None: + if not filtered_releases or last_prerelease > filtered_releases[-1]: + return filtered_releases, last_prerelease + return filtered_releases, None -def get_supported_releases(integration: str, pypi_data: dict) -> list[Version]: + +def get_supported_releases( + integration: str, pypi_data: dict, older_than: Optional[datetime] = None +) -> tuple[list[Version], Optional[Version]]: """ Get a list of releases that are currently supported by the SDK. This takes into account a handful of parameters (Python support, the lowest version we've defined for the framework, the date of the release). + + We return the list of supported releases and optionally also the newest + prerelease, if it should be tested (meaning it's for a version higher than + the current stable version). + + If an `older_than` timestamp is provided, no release newer than that will be + considered. """ package = pypi_data["info"]["name"] # Get a consolidated list without taking into account Python support yet # (because that might require an additional API call for some # of the releases) - releases = _prefilter_releases(integration, pypi_data["releases"]) + releases, latest_prerelease = _prefilter_releases( + integration, pypi_data["releases"], older_than + ) # Determine Python support expected_python_versions = TEST_SUITE_CONFIG[integration].get("python") @@ -196,14 +241,18 @@ def _supports_lowest(release: Version) -> bool: # version(s) that we do, cut off the rest releases = releases[i:] - return releases + return releases, latest_prerelease -def pick_releases_to_test(releases: list[Version]) -> list[Version]: +def pick_releases_to_test( + releases: list[Version], last_prerelease: Optional[Version] +) -> list[Version]: """Pick a handful of releases to test from a sorted list of supported releases.""" # If the package has majors (or major-like releases, even if they don't do # semver), we want to make sure we're testing them all. If not, we just pick # the oldest, the newest, and a couple in between. + # + # If there is a relevant prerelease, also test that in addition to the above. has_majors = len(set([v.major for v in releases])) > 1 filtered_releases = set() @@ -238,7 +287,11 @@ def pick_releases_to_test(releases: list[Version]) -> list[Version]: releases[-1], # latest } - return sorted(filtered_releases) + filtered_releases = sorted(filtered_releases) + if last_prerelease is not None: + filtered_releases.append(last_prerelease) + + return filtered_releases def supported_python_versions( @@ -381,7 +434,9 @@ def _render_dependencies(integration: str, releases: list[Version]) -> list[str] return rendered -def write_tox_file(packages: dict) -> None: +def write_tox_file( + packages: dict, update_timestamp: bool, last_updated: datetime +) -> None: template = ENV.get_template("tox.jinja") context = {"groups": {}} @@ -400,6 +455,11 @@ def write_tox_file(packages: dict) -> None: } ) + if update_timestamp: + context["updated"] = datetime.now(tz=timezone.utc).isoformat() + else: + context["updated"] = last_updated.isoformat() + rendered = template.render(context) with open(TOX_FILE, "w") as file: @@ -453,7 +513,59 @@ def _add_python_versions_to_release( release.rendered_python_versions = _render_python_versions(release.python_versions) -def main() -> None: +def get_file_hash() -> str: + """Calculate a hash of the tox.ini file.""" + hasher = hashlib.md5() + + with open(TOX_FILE, "rb") as f: + buf = f.read() + hasher.update(buf) + + return hasher.hexdigest() + + +def get_last_updated() -> Optional[datetime]: + timestamp = None + + with open(TOX_FILE, "r") as f: + for line in f: + if line.startswith("# Last generated:"): + timestamp = datetime.fromisoformat(line.strip().split()[-1]) + break + + if timestamp is None: + print( + "Failed to find out when tox.ini was last generated; the timestamp seems to be missing from the file." + ) + + return timestamp + + +def main(fail_on_changes: bool = False) -> None: + """ + Generate tox.ini from the tox.jinja template. + + The script has two modes of operation: + - fail on changes mode (if `fail_on_changes` is True) + - normal mode (if `fail_on_changes` is False) + + Fail on changes mode is run on every PR to make sure that `tox.ini`, + `tox.jinja` and this script don't go out of sync because of manual changes + in one place but not the other. + + Normal mode is meant to be run as a cron job, regenerating tox.ini and + proposing the changes via a PR. + """ + print(f"Running in {'fail_on_changes' if fail_on_changes else 'normal'} mode.") + last_updated = get_last_updated() + if fail_on_changes: + # We need to make the script ignore any new releases after the `last_updated` + # timestamp so that we don't fail CI on a PR just because a new package + # version was released, leading to unrelated changes in tox.ini. + print( + f"Since we're in fail_on_changes mode, we're only considering releases before the last tox.ini update at {last_updated.isoformat()}." + ) + global MIN_PYTHON_VERSION, MAX_PYTHON_VERSION sdk_python_versions = _parse_python_versions_from_classifiers( metadata("sentry-sdk").get_all("Classifier") @@ -480,7 +592,14 @@ def main() -> None: pypi_data = fetch_package(package) # Get the list of all supported releases - releases = get_supported_releases(integration, pypi_data) + + # If in fail-on-changes mode, ignore releases newer than `last_updated` + older_than = last_updated if fail_on_changes else None + + releases, latest_prerelease = get_supported_releases( + integration, pypi_data, older_than + ) + if not releases: print(" Found no supported releases.") continue @@ -488,9 +607,9 @@ def main() -> None: _compare_min_version_with_defined(integration, releases) # Pick a handful of the supported releases to actually test against - # and fetch the PYPI data for each to determine which Python versions + # and fetch the PyPI data for each to determine which Python versions # to test it on - test_releases = pick_releases_to_test(releases) + test_releases = pick_releases_to_test(releases, latest_prerelease) for release in test_releases: _add_python_versions_to_release(integration, package, release) @@ -510,8 +629,44 @@ def main() -> None: } ) - write_tox_file(packages) + if fail_on_changes: + old_file_hash = get_file_hash() + + write_tox_file( + packages, update_timestamp=not fail_on_changes, last_updated=last_updated + ) + + if fail_on_changes: + new_file_hash = get_file_hash() + if old_file_hash != new_file_hash: + raise RuntimeError( + dedent( + """ + Detected that `tox.ini` is out of sync with + `scripts/populate_tox/tox.jinja` and/or + `scripts/populate_tox/populate_tox.py`. This might either mean + that `tox.ini` was changed manually, or the `tox.jinja` + template and/or the `populate_tox.py` script were changed without + regenerating `tox.ini`. + + Please don't make manual changes to `tox.ini`. Instead, make the + changes to the `tox.jinja` template and/or the `populate_tox.py` + script (as applicable) and regenerate the `tox.ini` file with: + + python -m venv toxgen.env + . toxgen.env/bin/activate + pip install -r scripts/populate_tox/requirements.txt + python scripts/populate_tox/populate_tox.py + """ + ) + ) + print("Done checking tox.ini. Looking good!") + else: + print( + "Done generating tox.ini. Make sure to also update the CI YAML files to reflect the new test targets." + ) if __name__ == "__main__": - main() + fail_on_changes = len(sys.argv) == 2 and sys.argv[1] == "--fail-on-changes" + main(fail_on_changes) diff --git a/scripts/populate_tox/tox.jinja b/scripts/populate_tox/tox.jinja index fea23895f2..fdda6840db 100644 --- a/scripts/populate_tox/tox.jinja +++ b/scripts/populate_tox/tox.jinja @@ -9,6 +9,8 @@ # or in the script (if you want to change the auto-generated part). # The file (and all resulting CI YAMLs) then need to be regenerated via # "scripts/generate-test-files.sh". +# +# Last generated: {{ updated }} [tox] requires = diff --git a/sentry_sdk/integrations/anthropic.py b/sentry_sdk/integrations/anthropic.py index 112c8690be..29105bd7ae 100644 --- a/sentry_sdk/integrations/anthropic.py +++ b/sentry_sdk/integrations/anthropic.py @@ -101,6 +101,8 @@ def _collect_ai_data(event, input_tokens, output_tokens, content_blocks): elif event.type == "content_block_delta": if hasattr(event.delta, "text"): content_blocks.append(event.delta.text) + elif hasattr(event.delta, "partial_json"): + content_blocks.append(event.delta.partial_json) elif event.type == "content_block_stop": pass elif event.type == "message_delta": diff --git a/sentry_sdk/integrations/aws_lambda.py b/sentry_sdk/integrations/aws_lambda.py index 648859a233..82dedb3191 100644 --- a/sentry_sdk/integrations/aws_lambda.py +++ b/sentry_sdk/integrations/aws_lambda.py @@ -75,7 +75,10 @@ def sentry_init_error(*args, **kwargs): else: # Fall back to AWS lambdas JSON representation of the error - sentry_event = _event_from_error_json(json.loads(args[1])) + error_info = args[1] + if isinstance(error_info, str): + error_info = json.loads(error_info) + sentry_event = _event_from_error_json(error_info) sentry_sdk.capture_event(sentry_event) return init_error(*args, **kwargs) diff --git a/sentry_sdk/profiler/__init__.py b/sentry_sdk/profiler/__init__.py index 46382cc29d..d8d4e076d5 100644 --- a/sentry_sdk/profiler/__init__.py +++ b/sentry_sdk/profiler/__init__.py @@ -1,4 +1,9 @@ -from sentry_sdk.profiler.continuous_profiler import start_profiler, stop_profiler +from sentry_sdk.profiler.continuous_profiler import ( + start_profile_session, + start_profiler, + stop_profile_session, + stop_profiler, +) from sentry_sdk.profiler.transaction_profiler import ( MAX_PROFILE_DURATION_NS, PROFILE_MINIMUM_SAMPLES, @@ -20,8 +25,10 @@ ) __all__ = [ - "start_profiler", - "stop_profiler", + "start_profile_session", + "start_profiler", # TODO: Deprecate this in favor of `start_profile_session` + "stop_profile_session", + "stop_profiler", # TODO: Deprecate this in favor of `stop_profile_session` # DEPRECATED: The following was re-exported for backwards compatibility. It # will be removed from sentry_sdk.profiler in a future release. "MAX_PROFILE_DURATION_NS", diff --git a/sentry_sdk/profiler/continuous_profiler.py b/sentry_sdk/profiler/continuous_profiler.py index 1619925bd2..9e2aa35fc1 100644 --- a/sentry_sdk/profiler/continuous_profiler.py +++ b/sentry_sdk/profiler/continuous_profiler.py @@ -145,6 +145,13 @@ def try_profile_lifecycle_trace_start(): def start_profiler(): # type: () -> None + + # TODO: deprecate this as it'll be replaced by `start_profile_session` + start_profile_session() + + +def start_profile_session(): + # type: () -> None if _scheduler is None: return @@ -153,6 +160,13 @@ def start_profiler(): def stop_profiler(): # type: () -> None + + # TODO: deprecate this as it'll be replaced by `stop_profile_session` + stop_profile_session() + + +def stop_profile_session(): + # type: () -> None if _scheduler is None: return diff --git a/sentry_sdk/scope.py b/sentry_sdk/scope.py index 45f3dfe0a0..51f95cdeae 100644 --- a/sentry_sdk/scope.py +++ b/sentry_sdk/scope.py @@ -1397,7 +1397,7 @@ def update_from_kwargs( user=None, # type: Optional[Any] level=None, # type: Optional[LogLevelStr] extras=None, # type: Optional[Dict[str, Any]] - contexts=None, # type: Optional[Dict[str, Any]] + contexts=None, # type: Optional[Dict[str, Dict[str, Any]]] tags=None, # type: Optional[Dict[str, str]] fingerprint=None, # type: Optional[List[str]] ): diff --git a/tests/integrations/anthropic/test_anthropic.py b/tests/integrations/anthropic/test_anthropic.py index ece2cfe7a3..253f1d4f33 100644 --- a/tests/integrations/anthropic/test_anthropic.py +++ b/tests/integrations/anthropic/test_anthropic.py @@ -1,5 +1,6 @@ from unittest import mock + try: from unittest.mock import AsyncMock except ImportError: @@ -10,7 +11,7 @@ async def __call__(self, *args, **kwargs): import pytest -from anthropic import AsyncAnthropic, Anthropic, AnthropicError, AsyncStream, Stream +from anthropic import Anthropic, AnthropicError, AsyncAnthropic, AsyncStream, Stream from anthropic.types import MessageDeltaUsage, TextDelta, Usage from anthropic.types.content_block_delta_event import ContentBlockDeltaEvent from anthropic.types.content_block_start_event import ContentBlockStartEvent @@ -19,6 +20,7 @@ async def __call__(self, *args, **kwargs): from anthropic.types.message_delta_event import MessageDeltaEvent from anthropic.types.message_start_event import MessageStartEvent +from sentry_sdk.integrations.anthropic import _add_ai_data_to_span, _collect_ai_data from sentry_sdk.utils import _serialize_span_attribute, package_version try: @@ -526,9 +528,9 @@ def test_streaming_create_message_with_input_json_delta( assert span["data"][SPANDATA.AI_INPUT_MESSAGES] == _serialize_span_attribute( messages ) - assert span["data"][SPANDATA.AI_RESPONSES] == _serialize_span_attribute( - [{"type": "text", "text": ""}] - ) # we do not record InputJSONDelta because it could contain PII + assert span["data"][SPANDATA.AI_RESPONSES] == _serialize_span_attribute([ + {"type": "text", "text": "{'location': 'San Francisco, CA'}"} + ]) # we do not record InputJSONDelta because it could contain PII else: assert SPANDATA.AI_INPUT_MESSAGES not in span["data"] @@ -665,9 +667,9 @@ async def test_streaming_create_message_with_input_json_delta_async( assert span["data"][SPANDATA.AI_INPUT_MESSAGES] == _serialize_span_attribute( messages ) - assert span["data"][SPANDATA.AI_RESPONSES] == _serialize_span_attribute( - [{"type": "text", "text": ""}] - ) # we do not record InputJSONDelta because it could contain PII + assert span["data"][SPANDATA.AI_RESPONSES] == _serialize_span_attribute([ + {"type": "text", "text": "{'location': 'San Francisco, CA'}"} + ]) # we do not record InputJSONDelta because it could contain PII else: assert SPANDATA.AI_INPUT_MESSAGES not in span["data"] @@ -770,3 +772,70 @@ async def test_span_origin_async(sentry_init, capture_events): assert event["contexts"]["trace"]["origin"] == "manual" assert event["spans"][0]["origin"] == "auto.ai.anthropic" + + +@pytest.mark.skipif( + ANTHROPIC_VERSION < (0, 27), + reason="Versions <0.27.0 do not include InputJSONDelta.", +) +def test_collect_ai_data_with_input_json_delta(): + event = ContentBlockDeltaEvent( + delta=InputJSONDelta(partial_json="test", type="input_json_delta"), + index=0, + type="content_block_delta", + ) + + input_tokens = 10 + output_tokens = 20 + content_blocks = [] + + new_input_tokens, new_output_tokens, new_content_blocks = _collect_ai_data( + event, input_tokens, output_tokens, content_blocks + ) + + assert new_input_tokens == input_tokens + assert new_output_tokens == output_tokens + assert new_content_blocks == ["test"] + + +@pytest.mark.skipif( + ANTHROPIC_VERSION < (0, 27), + reason="Versions <0.27.0 do not include InputJSONDelta.", +) +def test_add_ai_data_to_span_with_input_json_delta(sentry_init, capture_events): + sentry_init( + integrations=[AnthropicIntegration(include_prompts=True)], + traces_sample_rate=1.0, + send_default_pii=True, + ) + events = capture_events() + + with start_span(name="test"): + with start_span(name="anthropic") as span: + integration = AnthropicIntegration() + + _add_ai_data_to_span( + span, + integration, + input_tokens=10, + output_tokens=20, + content_blocks=["{'test': 'data',", "'more': 'json'}"], + ) + + # assert span._data.get("ai.streaming") is True + # assert span._measurements.get("ai_prompt_tokens_used")["value"] == 10 + # assert span._measurements.get("ai_completion_tokens_used")["value"] == 20 + # assert span._measurements.get("ai_total_tokens_used")["value"] == 30 + + (event,) = events + + assert len(event["spans"]) == 1 + (span,) = event["spans"] + + assert span["data"][SPANDATA.AI_RESPONSES] == _serialize_span_attribute([ + {"type": "text", "text": "{'test': 'data','more': 'json'}"} + ]) + assert span["data"]["ai.streaming"] == True + assert span["measurements"]["ai_prompt_tokens_used"]["value"] == 10 + assert span["measurements"]["ai_completion_tokens_used"]["value"] == 20 + assert span["measurements"]["ai_total_tokens_used"]["value"] == 30 diff --git a/tests/integrations/aws_lambda/test_aws.py b/tests/integrations/aws_lambda/test_aws.py index d413431b81..325d4886ee 100644 --- a/tests/integrations/aws_lambda/test_aws.py +++ b/tests/integrations/aws_lambda/test_aws.py @@ -319,9 +319,6 @@ def test_handler(event, context): } -@pytest.mark.xfail( - reason="Amazon changed something (2024-10-01) and on Python 3.9+ our SDK can not capture events in the init phase of the Lambda function anymore. We need to fix this somehow." -) def test_init_error(run_lambda_function, lambda_runtime): envelope_items, _ = run_lambda_function( LAMBDA_PRELUDE diff --git a/tests/profiler/test_continuous_profiler.py b/tests/profiler/test_continuous_profiler.py index fa55b0be5f..7f1ede0bd1 100644 --- a/tests/profiler/test_continuous_profiler.py +++ b/tests/profiler/test_continuous_profiler.py @@ -11,7 +11,9 @@ get_profiler_id, setup_continuous_profiler, start_profiler, + start_profile_session, stop_profiler, + stop_profile_session, ) from tests.conftest import ApproxDict @@ -207,6 +209,21 @@ def assert_single_transaction_without_profile_chunks(envelopes): pytest.param("gevent", marks=requires_gevent), ], ) +@pytest.mark.parametrize( + ["start_profiler_func", "stop_profiler_func"], + [ + pytest.param( + start_profile_session, + stop_profile_session, + id="start_profile_session/stop_profile_session", + ), + pytest.param( + start_profiler, + stop_profiler, + id="start_profiler/stop_profiler (deprecated)", + ), + ], +) @pytest.mark.parametrize( "make_options", [ @@ -219,6 +236,8 @@ def test_continuous_profiler_auto_start_and_manual_stop( sentry_init, capture_envelopes, mode, + start_profiler_func, + stop_profiler_func, make_options, teardown_profiling, ): @@ -239,7 +258,7 @@ def test_continuous_profiler_auto_start_and_manual_stop( assert_single_transaction_with_profile_chunks(envelopes, thread) for _ in range(3): - stop_profiler() + stop_profiler_func() envelopes.clear() @@ -249,7 +268,7 @@ def test_continuous_profiler_auto_start_and_manual_stop( assert_single_transaction_without_profile_chunks(envelopes) - start_profiler() + start_profiler_func() envelopes.clear() @@ -267,6 +286,21 @@ def test_continuous_profiler_auto_start_and_manual_stop( pytest.param("gevent", marks=requires_gevent), ], ) +@pytest.mark.parametrize( + ["start_profiler_func", "stop_profiler_func"], + [ + pytest.param( + start_profile_session, + stop_profile_session, + id="start_profile_session/stop_profile_session", + ), + pytest.param( + start_profiler, + stop_profiler, + id="start_profiler/stop_profiler (deprecated)", + ), + ], +) @pytest.mark.parametrize( "make_options", [ @@ -279,6 +313,8 @@ def test_continuous_profiler_manual_start_and_stop_sampled( sentry_init, capture_envelopes, mode, + start_profiler_func, + stop_profiler_func, make_options, teardown_profiling, ): @@ -295,7 +331,7 @@ def test_continuous_profiler_manual_start_and_stop_sampled( thread = threading.current_thread() for _ in range(3): - start_profiler() + start_profiler_func() envelopes.clear() @@ -309,7 +345,7 @@ def test_continuous_profiler_manual_start_and_stop_sampled( assert get_profiler_id() is not None, "profiler should be running" - stop_profiler() + stop_profiler_func() # the profiler stops immediately in manual mode assert get_profiler_id() is None, "profiler should not be running" @@ -332,6 +368,21 @@ def test_continuous_profiler_manual_start_and_stop_sampled( pytest.param("gevent", marks=requires_gevent), ], ) +@pytest.mark.parametrize( + ["start_profiler_func", "stop_profiler_func"], + [ + pytest.param( + start_profile_session, + stop_profile_session, + id="start_profile_session/stop_profile_session", + ), + pytest.param( + start_profiler, + stop_profiler, + id="start_profiler/stop_profiler (deprecated)", + ), + ], +) @pytest.mark.parametrize( "make_options", [ @@ -343,6 +394,8 @@ def test_continuous_profiler_manual_start_and_stop_unsampled( sentry_init, capture_envelopes, mode, + start_profiler_func, + stop_profiler_func, make_options, teardown_profiling, ): @@ -356,7 +409,7 @@ def test_continuous_profiler_manual_start_and_stop_unsampled( envelopes = capture_envelopes() - start_profiler() + start_profiler_func() with sentry_sdk.start_span(name="profiling"): with sentry_sdk.start_span(op="op"): @@ -364,7 +417,7 @@ def test_continuous_profiler_manual_start_and_stop_unsampled( assert_single_transaction_without_profile_chunks(envelopes) - stop_profiler() + stop_profiler_func() @pytest.mark.parametrize( @@ -485,6 +538,21 @@ def test_continuous_profiler_auto_start_and_stop_unsampled( ), ], ) +@pytest.mark.parametrize( + ["start_profiler_func", "stop_profiler_func"], + [ + pytest.param( + start_profile_session, + stop_profile_session, + id="start_profile_session/stop_profile_session", + ), + pytest.param( + start_profiler, + stop_profiler, + id="start_profiler/stop_profiler (deprecated)", + ), + ], +) @pytest.mark.parametrize( "make_options", [ @@ -495,6 +563,8 @@ def test_continuous_profiler_auto_start_and_stop_unsampled( def test_continuous_profiler_manual_start_and_stop_noop_when_using_trace_lifecyle( sentry_init, mode, + start_profiler_func, + stop_profiler_func, class_name, make_options, teardown_profiling, @@ -510,11 +580,11 @@ def test_continuous_profiler_manual_start_and_stop_noop_when_using_trace_lifecyl with mock.patch( f"sentry_sdk.profiler.continuous_profiler.{class_name}.ensure_running" ) as mock_ensure_running: - start_profiler() + start_profiler_func() mock_ensure_running.assert_not_called() with mock.patch( f"sentry_sdk.profiler.continuous_profiler.{class_name}.teardown" ) as mock_teardown: - stop_profiler() + stop_profiler_func() mock_teardown.assert_not_called() diff --git a/tox.ini b/tox.ini index ebc6df8227..8bb9401a27 100644 --- a/tox.ini +++ b/tox.ini @@ -9,6 +9,8 @@ # or in the script (if you want to change the auto-generated part). # The file (and all resulting CI YAMLs) then need to be regenerated via # "scripts/generate-test-files.sh". +# +# Last generated: 2025-02-19T12:41:15.689786+00:00 [tox] requires = @@ -207,10 +209,11 @@ envlist = {py3.8,py3.10,py3.11}-ariadne-v0.20.1 {py3.8,py3.11,py3.12}-ariadne-v0.22 {py3.8,py3.11,py3.12}-ariadne-v0.24.0 - {py3.8,py3.11,py3.12}-ariadne-v0.25.2 + {py3.9,py3.12,py3.13}-ariadne-v0.26.0 {py3.7,py3.9,py3.10}-gql-v3.4.1 {py3.7,py3.11,py3.12}-gql-v3.5.0 + {py3.9,py3.12,py3.13}-gql-v3.6.0b4 {py3.7,py3.9,py3.10}-graphene-v3.3 {py3.8,py3.12,py3.13}-graphene-v3.4.3 @@ -232,6 +235,7 @@ envlist = {py3.7,py3.8}-celery-v4.4.7 {py3.7,py3.8}-celery-v5.0.5 {py3.8,py3.11,py3.12}-celery-v5.4.0 + {py3.8,py3.12,py3.13}-celery-v5.5.0rc4 {py3.7}-dramatiq-v1.9.0 {py3.7,py3.8,py3.9}-dramatiq-v1.12.3 @@ -581,13 +585,14 @@ deps = ariadne-v0.20.1: ariadne==0.20.1 ariadne-v0.22: ariadne==0.22 ariadne-v0.24.0: ariadne==0.24.0 - ariadne-v0.25.2: ariadne==0.25.2 + ariadne-v0.26.0: ariadne==0.26.0 ariadne: fastapi ariadne: flask ariadne: httpx gql-v3.4.1: gql[all]==3.4.1 gql-v3.5.0: gql[all]==3.5.0 + gql-v3.6.0b4: gql[all]==3.6.0b4 graphene-v3.3: graphene==3.3 graphene-v3.4.3: graphene==3.4.3 @@ -619,6 +624,7 @@ deps = celery-v4.4.7: celery==4.4.7 celery-v5.0.5: celery==5.0.5 celery-v5.4.0: celery==5.4.0 + celery-v5.5.0rc4: celery==5.5.0rc4 celery: newrelic celery: redis py3.7-celery: importlib-metadata<5.0