django-lambda-tasks 0.11.2__tar.gz → 0.12.0__tar.gz
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- django_lambda_tasks-0.12.0/.github/workflows/ci.yml +55 -0
- {django_lambda_tasks-0.11.2 → django_lambda_tasks-0.12.0}/.github/workflows/release.yml +1 -1
- {django_lambda_tasks-0.11.2 → django_lambda_tasks-0.12.0}/.kiro/steering/product.md +4 -4
- {django_lambda_tasks-0.11.2 → django_lambda_tasks-0.12.0}/.kiro/steering/structure.md +1 -1
- {django_lambda_tasks-0.11.2 → django_lambda_tasks-0.12.0}/.kiro/steering/tech.md +1 -1
- {django_lambda_tasks-0.11.2 → django_lambda_tasks-0.12.0}/PKG-INFO +4 -4
- {django_lambda_tasks-0.11.2 → django_lambda_tasks-0.12.0}/README.md +3 -3
- {django_lambda_tasks-0.11.2 → django_lambda_tasks-0.12.0}/example/example_project/sentry.py +2 -3
- {django_lambda_tasks-0.11.2 → django_lambda_tasks-0.12.0}/lambda_tasks/sentry.py +14 -74
- {django_lambda_tasks-0.11.2 → django_lambda_tasks-0.12.0}/pyproject.toml +2 -2
- {django_lambda_tasks-0.11.2 → django_lambda_tasks-0.12.0}/tests/test_sentry.py +50 -88
- django_lambda_tasks-0.11.2/.github/workflows/ci.yml +0 -87
- {django_lambda_tasks-0.11.2 → django_lambda_tasks-0.12.0}/.github/dependabot.yml +0 -0
- {django_lambda_tasks-0.11.2 → django_lambda_tasks-0.12.0}/.gitignore +0 -0
- {django_lambda_tasks-0.11.2 → django_lambda_tasks-0.12.0}/.kiro/specs/async-local-execution/.config.kiro +0 -0
- {django_lambda_tasks-0.11.2 → django_lambda_tasks-0.12.0}/.kiro/specs/async-local-execution/design.md +0 -0
- {django_lambda_tasks-0.11.2 → django_lambda_tasks-0.12.0}/.kiro/specs/async-local-execution/requirements.md +0 -0
- {django_lambda_tasks-0.11.2 → django_lambda_tasks-0.12.0}/.kiro/specs/async-local-execution/tasks.md +0 -0
- {django_lambda_tasks-0.11.2 → django_lambda_tasks-0.12.0}/.kiro/specs/deferred-task-enqueue/.config.kiro +0 -0
- {django_lambda_tasks-0.11.2 → django_lambda_tasks-0.12.0}/.kiro/specs/deferred-task-enqueue/design.md +0 -0
- {django_lambda_tasks-0.11.2 → django_lambda_tasks-0.12.0}/.kiro/specs/deferred-task-enqueue/requirements.md +0 -0
- {django_lambda_tasks-0.11.2 → django_lambda_tasks-0.12.0}/.kiro/specs/deferred-task-enqueue/tasks.md +0 -0
- {django_lambda_tasks-0.11.2 → django_lambda_tasks-0.12.0}/.kiro/specs/eager-mode-example-app/.config.kiro +0 -0
- {django_lambda_tasks-0.11.2 → django_lambda_tasks-0.12.0}/.kiro/specs/eager-mode-example-app/design.md +0 -0
- {django_lambda_tasks-0.11.2 → django_lambda_tasks-0.12.0}/.kiro/specs/eager-mode-example-app/requirements.md +0 -0
- {django_lambda_tasks-0.11.2 → django_lambda_tasks-0.12.0}/.kiro/specs/eager-mode-example-app/tasks.md +0 -0
- {django_lambda_tasks-0.11.2 → django_lambda_tasks-0.12.0}/.kiro/specs/ignore-errors-decorator-option/.config.kiro +0 -0
- {django_lambda_tasks-0.11.2 → django_lambda_tasks-0.12.0}/.kiro/specs/ignore-errors-decorator-option/design.md +0 -0
- {django_lambda_tasks-0.11.2 → django_lambda_tasks-0.12.0}/.kiro/specs/ignore-errors-decorator-option/requirements.md +0 -0
- {django_lambda_tasks-0.11.2 → django_lambda_tasks-0.12.0}/.kiro/specs/ignore-errors-decorator-option/tasks.md +0 -0
- {django_lambda_tasks-0.11.2 → django_lambda_tasks-0.12.0}/.kiro/specs/import-string-task-resolution/.config.kiro +0 -0
- {django_lambda_tasks-0.11.2 → django_lambda_tasks-0.12.0}/.kiro/specs/import-string-task-resolution/design.md +0 -0
- {django_lambda_tasks-0.11.2 → django_lambda_tasks-0.12.0}/.kiro/specs/import-string-task-resolution/requirements.md +0 -0
- {django_lambda_tasks-0.11.2 → django_lambda_tasks-0.12.0}/.kiro/specs/import-string-task-resolution/tasks.md +0 -0
- {django_lambda_tasks-0.11.2 → django_lambda_tasks-0.12.0}/.kiro/specs/retry-delay/.config.kiro +0 -0
- {django_lambda_tasks-0.11.2 → django_lambda_tasks-0.12.0}/.kiro/specs/retry-delay/design.md +0 -0
- {django_lambda_tasks-0.11.2 → django_lambda_tasks-0.12.0}/.kiro/specs/retry-delay/requirements.md +0 -0
- {django_lambda_tasks-0.11.2 → django_lambda_tasks-0.12.0}/.kiro/specs/retry-delay/tasks.md +0 -0
- {django_lambda_tasks-0.11.2 → django_lambda_tasks-0.12.0}/.kiro/specs/rse-background-tasks/.config.kiro +0 -0
- {django_lambda_tasks-0.11.2 → django_lambda_tasks-0.12.0}/.kiro/specs/rse-background-tasks/design.md +0 -0
- {django_lambda_tasks-0.11.2 → django_lambda_tasks-0.12.0}/.kiro/specs/rse-background-tasks/requirements.md +0 -0
- {django_lambda_tasks-0.11.2 → django_lambda_tasks-0.12.0}/.kiro/specs/rse-background-tasks/tasks.md +0 -0
- {django_lambda_tasks-0.11.2 → django_lambda_tasks-0.12.0}/.kiro/specs/rse-background-tasks-bugfix/.config.kiro +0 -0
- {django_lambda_tasks-0.11.2 → django_lambda_tasks-0.12.0}/.kiro/specs/rse-background-tasks-bugfix/bugfix.md +0 -0
- {django_lambda_tasks-0.11.2 → django_lambda_tasks-0.12.0}/.kiro/specs/rse-background-tasks-bugfix/design.md +0 -0
- {django_lambda_tasks-0.11.2 → django_lambda_tasks-0.12.0}/.kiro/specs/rse-background-tasks-bugfix/tasks.md +0 -0
- {django_lambda_tasks-0.11.2 → django_lambda_tasks-0.12.0}/.kiro/specs/singleton-task/.config.kiro +0 -0
- {django_lambda_tasks-0.11.2 → django_lambda_tasks-0.12.0}/.kiro/specs/singleton-task/design.md +0 -0
- {django_lambda_tasks-0.11.2 → django_lambda_tasks-0.12.0}/.kiro/specs/singleton-task/requirements.md +0 -0
- {django_lambda_tasks-0.11.2 → django_lambda_tasks-0.12.0}/.kiro/specs/singleton-task/tasks.md +0 -0
- {django_lambda_tasks-0.11.2 → django_lambda_tasks-0.12.0}/.kiro/specs/ssm-environment-loader/.config.kiro +0 -0
- {django_lambda_tasks-0.11.2 → django_lambda_tasks-0.12.0}/.kiro/specs/ssm-environment-loader/design.md +0 -0
- {django_lambda_tasks-0.11.2 → django_lambda_tasks-0.12.0}/.kiro/specs/ssm-environment-loader/requirements.md +0 -0
- {django_lambda_tasks-0.11.2 → django_lambda_tasks-0.12.0}/.kiro/specs/ssm-environment-loader/tasks.md +0 -0
- {django_lambda_tasks-0.11.2 → django_lambda_tasks-0.12.0}/.kiro/specs/task-retry/.config.kiro +0 -0
- {django_lambda_tasks-0.11.2 → django_lambda_tasks-0.12.0}/.kiro/specs/task-retry/design.md +0 -0
- {django_lambda_tasks-0.11.2 → django_lambda_tasks-0.12.0}/.kiro/specs/task-retry/requirements.md +0 -0
- {django_lambda_tasks-0.11.2 → django_lambda_tasks-0.12.0}/.kiro/specs/task-retry/tasks.md +0 -0
- {django_lambda_tasks-0.11.2 → django_lambda_tasks-0.12.0}/.pre-commit-config.yaml +0 -0
- {django_lambda_tasks-0.11.2 → django_lambda_tasks-0.12.0}/.vscode/settings.json +0 -0
- {django_lambda_tasks-0.11.2 → django_lambda_tasks-0.12.0}/docker-compose.yml +0 -0
- {django_lambda_tasks-0.11.2 → django_lambda_tasks-0.12.0}/example/README.md +0 -0
- {django_lambda_tasks-0.11.2 → django_lambda_tasks-0.12.0}/example/docker-compose.yml +0 -0
- {django_lambda_tasks-0.11.2 → django_lambda_tasks-0.12.0}/example/example_app/__init__.py +0 -0
- {django_lambda_tasks-0.11.2 → django_lambda_tasks-0.12.0}/example/example_app/apps.py +0 -0
- {django_lambda_tasks-0.11.2 → django_lambda_tasks-0.12.0}/example/example_app/tasks.py +0 -0
- {django_lambda_tasks-0.11.2 → django_lambda_tasks-0.12.0}/example/example_app/urls.py +0 -0
- {django_lambda_tasks-0.11.2 → django_lambda_tasks-0.12.0}/example/example_app/views.py +0 -0
- {django_lambda_tasks-0.11.2 → django_lambda_tasks-0.12.0}/example/example_project/__init__.py +0 -0
- {django_lambda_tasks-0.11.2 → django_lambda_tasks-0.12.0}/example/example_project/settings.py +0 -0
- {django_lambda_tasks-0.11.2 → django_lambda_tasks-0.12.0}/example/example_project/urls.py +0 -0
- {django_lambda_tasks-0.11.2 → django_lambda_tasks-0.12.0}/example/example_project/wsgi.py +0 -0
- {django_lambda_tasks-0.11.2 → django_lambda_tasks-0.12.0}/example/manage.py +0 -0
- {django_lambda_tasks-0.11.2 → django_lambda_tasks-0.12.0}/lambda_tasks/__init__.py +0 -0
- {django_lambda_tasks-0.11.2 → django_lambda_tasks-0.12.0}/lambda_tasks/admin.py +0 -0
- {django_lambda_tasks-0.11.2 → django_lambda_tasks-0.12.0}/lambda_tasks/apps.py +0 -0
- {django_lambda_tasks-0.11.2 → django_lambda_tasks-0.12.0}/lambda_tasks/checks.py +0 -0
- {django_lambda_tasks-0.11.2 → django_lambda_tasks-0.12.0}/lambda_tasks/decorators.py +0 -0
- {django_lambda_tasks-0.11.2 → django_lambda_tasks-0.12.0}/lambda_tasks/environment_loader.py +0 -0
- {django_lambda_tasks-0.11.2 → django_lambda_tasks-0.12.0}/lambda_tasks/handler.py +0 -0
- {django_lambda_tasks-0.11.2 → django_lambda_tasks-0.12.0}/lambda_tasks/local_executor.py +0 -0
- {django_lambda_tasks-0.11.2 → django_lambda_tasks-0.12.0}/lambda_tasks/logging.py +0 -0
- {django_lambda_tasks-0.11.2 → django_lambda_tasks-0.12.0}/lambda_tasks/migrations/0001_initial.py +0 -0
- {django_lambda_tasks-0.11.2 → django_lambda_tasks-0.12.0}/lambda_tasks/migrations/0002_alter_taskrecord_status.py +0 -0
- {django_lambda_tasks-0.11.2 → django_lambda_tasks-0.12.0}/lambda_tasks/migrations/0003_taskrecord_taskrecord_kwargs_trgm.py +0 -0
- {django_lambda_tasks-0.11.2 → django_lambda_tasks-0.12.0}/lambda_tasks/migrations/0004_remove_taskrecord_taskrecord_kwargs_trgm_and_more.py +0 -0
- {django_lambda_tasks-0.11.2 → django_lambda_tasks-0.12.0}/lambda_tasks/migrations/__init__.py +0 -0
- {django_lambda_tasks-0.11.2 → django_lambda_tasks-0.12.0}/lambda_tasks/models.py +0 -0
- {django_lambda_tasks-0.11.2 → django_lambda_tasks-0.12.0}/lambda_tasks/secret_loader.py +0 -0
- {django_lambda_tasks-0.11.2 → django_lambda_tasks-0.12.0}/lambda_tasks/settings.py +0 -0
- {django_lambda_tasks-0.11.2 → django_lambda_tasks-0.12.0}/lambda_tasks/tasks.py +0 -0
- {django_lambda_tasks-0.11.2 → django_lambda_tasks-0.12.0}/lambda_tasks/timeouts.py +0 -0
- {django_lambda_tasks-0.11.2 → django_lambda_tasks-0.12.0}/tests/conftest.py +0 -0
- {django_lambda_tasks-0.11.2 → django_lambda_tasks-0.12.0}/tests/settings.py +0 -0
- {django_lambda_tasks-0.11.2 → django_lambda_tasks-0.12.0}/tests/test_admin.py +0 -0
- {django_lambda_tasks-0.11.2 → django_lambda_tasks-0.12.0}/tests/test_batch.py +0 -0
- {django_lambda_tasks-0.11.2 → django_lambda_tasks-0.12.0}/tests/test_batch_worker.py +0 -0
- {django_lambda_tasks-0.11.2 → django_lambda_tasks-0.12.0}/tests/test_checks.py +0 -0
- {django_lambda_tasks-0.11.2 → django_lambda_tasks-0.12.0}/tests/test_decorator.py +0 -0
- {django_lambda_tasks-0.11.2 → django_lambda_tasks-0.12.0}/tests/test_decorators.py +0 -0
- {django_lambda_tasks-0.11.2 → django_lambda_tasks-0.12.0}/tests/test_deferred_enqueue.py +0 -0
- {django_lambda_tasks-0.11.2 → django_lambda_tasks-0.12.0}/tests/test_environment_loader.py +0 -0
- {django_lambda_tasks-0.11.2 → django_lambda_tasks-0.12.0}/tests/test_handler.py +0 -0
- {django_lambda_tasks-0.11.2 → django_lambda_tasks-0.12.0}/tests/test_kwargs_only.py +0 -0
- {django_lambda_tasks-0.11.2 → django_lambda_tasks-0.12.0}/tests/test_local_executor.py +0 -0
- {django_lambda_tasks-0.11.2 → django_lambda_tasks-0.12.0}/tests/test_logging.py +0 -0
- {django_lambda_tasks-0.11.2 → django_lambda_tasks-0.12.0}/tests/test_memory_limit.py +0 -0
- {django_lambda_tasks-0.11.2 → django_lambda_tasks-0.12.0}/tests/test_models.py +0 -0
- {django_lambda_tasks-0.11.2 → django_lambda_tasks-0.12.0}/tests/test_noop_execution.py +0 -0
- {django_lambda_tasks-0.11.2 → django_lambda_tasks-0.12.0}/tests/test_secret_loader.py +0 -0
- {django_lambda_tasks-0.11.2 → django_lambda_tasks-0.12.0}/tests/test_serializer.py +0 -0
- {django_lambda_tasks-0.11.2 → django_lambda_tasks-0.12.0}/tests/test_settings.py +0 -0
- {django_lambda_tasks-0.11.2 → django_lambda_tasks-0.12.0}/tests/test_tasks.py +0 -0
- {django_lambda_tasks-0.11.2 → django_lambda_tasks-0.12.0}/tests/test_timeout_validation.py +0 -0
- {django_lambda_tasks-0.11.2 → django_lambda_tasks-0.12.0}/tests/test_timeouts.py +0 -0
|
@@ -0,0 +1,55 @@
|
|
|
1
|
+
name: CI
|
|
2
|
+
|
|
3
|
+
on:
|
|
4
|
+
push:
|
|
5
|
+
pull_request:
|
|
6
|
+
workflow_call:
|
|
7
|
+
|
|
8
|
+
env:
|
|
9
|
+
MINIMUM_PYTHON_VERSION: '3.11'
|
|
10
|
+
|
|
11
|
+
concurrency:
|
|
12
|
+
group: ${{ github.head_ref || github.run_id }}
|
|
13
|
+
cancel-in-progress: true
|
|
14
|
+
|
|
15
|
+
jobs:
|
|
16
|
+
|
|
17
|
+
precommit:
|
|
18
|
+
runs-on: ubuntu-latest
|
|
19
|
+
steps:
|
|
20
|
+
- uses: actions/checkout@3d3c42e5aac5ba805825da76410c181273ba90b1 # v7.0.1
|
|
21
|
+
- name: Install uv and set the python version
|
|
22
|
+
uses: astral-sh/setup-uv@1db35dd8eee11c5894872e0b383ae6c406cf738d # v10.4.0
|
|
23
|
+
with:
|
|
24
|
+
python-version: ${{ env.MINIMUM_PYTHON_VERSION }}
|
|
25
|
+
- name: Run static code inspections
|
|
26
|
+
run: uv run pre-commit run --all-files
|
|
27
|
+
|
|
28
|
+
build:
|
|
29
|
+
runs-on: ubuntu-latest
|
|
30
|
+
strategy:
|
|
31
|
+
matrix:
|
|
32
|
+
python-version: ["3.11", "3.12", "3.13", "3.14", "3.15"]
|
|
33
|
+
services:
|
|
34
|
+
postgres:
|
|
35
|
+
image: postgres:17
|
|
36
|
+
env:
|
|
37
|
+
POSTGRES_DB: lambda_tasks_test
|
|
38
|
+
POSTGRES_USER: postgres
|
|
39
|
+
POSTGRES_PASSWORD: postgres
|
|
40
|
+
ports:
|
|
41
|
+
- 5432:5432
|
|
42
|
+
options: >-
|
|
43
|
+
--health-cmd "pg_isready -U postgres"
|
|
44
|
+
--health-interval 10s
|
|
45
|
+
--health-timeout 5s
|
|
46
|
+
--health-retries 5
|
|
47
|
+
steps:
|
|
48
|
+
- uses: actions/checkout@3d3c42e5aac5ba805825da76410c181273ba90b1 # v7.0.1
|
|
49
|
+
- name: Install uv and set the python version
|
|
50
|
+
uses: astral-sh/setup-uv@1db35dd8eee11c5894872e0b383ae6c406cf738d # v10.4.0
|
|
51
|
+
with:
|
|
52
|
+
python-version: ${{ matrix.python-version }}
|
|
53
|
+
- name: Run tests
|
|
54
|
+
run: |
|
|
55
|
+
uv run pytest --cov-branch --cov-report term-missing --cov=tests/ --cov=lambda_tasks/
|
|
@@ -20,7 +20,7 @@ jobs:
|
|
|
20
20
|
steps:
|
|
21
21
|
- uses: actions/checkout@3d3c42e5aac5ba805825da76410c181273ba90b1 # v7.0.1
|
|
22
22
|
- name: Install Python ${{ env.MINIMUM_PYTHON_VERSION }}
|
|
23
|
-
uses: astral-sh/setup-uv@
|
|
23
|
+
uses: astral-sh/setup-uv@1db35dd8eee11c5894872e0b383ae6c406cf738d # v10.4.0
|
|
24
24
|
with:
|
|
25
25
|
python-version: ${{ env.MINIMUM_PYTHON_VERSION }}
|
|
26
26
|
- name: Build the package
|
|
@@ -326,17 +326,17 @@ The library does not call `sentry_sdk.init(...)` — the host application owns S
|
|
|
326
326
|
|
|
327
327
|
Error attribution also relies on the `lambda_task` **tag**, so it is reliable even when the trace is not sampled.
|
|
328
328
|
|
|
329
|
-
**If a host keeps `AwsLambdaIntegration` anyway:** the library still behaves correctly. `
|
|
329
|
+
**If a host keeps `AwsLambdaIntegration` anyway:** the library still behaves correctly. `task_scope` uses `start_span`, which is automatically root-or-child on sentry-sdk 3.0, and traces the task as a **child span** of it rather than a second, competing transaction. A nested *transaction* per task would inherit (not independently re-roll) the invocation's sampling decision, doubling transaction volume and defeating `traces_sample_rate`; a child span is sent only if its parent is sampled. In that case the transaction name is the Lambda function name and the task name lives on the `lambda_task` tag.
|
|
330
330
|
|
|
331
|
-
`task_scope` deliberately does **not** call `scope.set_transaction_name(task_name)`: when an invocation transaction is active it would rename the shared transaction (fighting across sibling records in a batch) and
|
|
331
|
+
`task_scope` deliberately does **not** call `scope.set_transaction_name(task_name)`: when an invocation transaction is active it would rename the shared transaction (fighting across sibling records in a batch) and corrupt the root-segment naming. The `lambda_task` tag is the reliable attribution.
|
|
332
332
|
|
|
333
333
|
**Reporting task failures:** the executor catches task exceptions (recording `FAILED` and not re-raising). On the two **terminal** failure branches in `models.py` (plain failure and max-retries-exceeded) it logs the exception at ERROR via `task_logger.error(error, exc_info=True)`. With the assumed host config `LoggingIntegration(event_level=logging.ERROR)`, that log becomes a Sentry event, attributed to the task by the active `task_scope` tags. No explicit `capture_exception` call is made — the error log is the single reporting path, so there are no duplicate events. The **retry** branch logs at WARNING and is deliberately not reported — transient, to-be-re-enqueued failures would flood Sentry; only terminal failures are reported.
|
|
334
334
|
|
|
335
335
|
**Reporting failures outside a task:** pre-execution failures in the handler (malformed SQS message, un-importable task, misconfiguration, cold-start errors) happen before `task_scope` opens. `handler.py` logs them at ERROR inside `lambda_tasks.sentry.handler_error_scope(message_id=...)`, a context manager that tags an isolated scope (`lambda_task.handler_error` + the message id) so the resulting log-driven Sentry event is identifiable. This relies on the same `LoggingIntegration(event_level=ERROR)` as task failures. Cold-start failures are additionally re-raised so AWS marks the invocation failed and redrives.
|
|
336
336
|
|
|
337
|
-
**Error-level log forwarding (required):** both task-failure and handler-failure reporting flow through `logger.error(..., exc_info=True)` + the host's `LoggingIntegration(event_level=logging.ERROR)`. On sentry-sdk
|
|
337
|
+
**Error-level log forwarding (required):** both task-failure and handler-failure reporting flow through `logger.error(..., exc_info=True)` + the host's `LoggingIntegration(event_level=logging.ERROR)`. On sentry-sdk 3.0 the default is `None`, so the host **must** configure it explicitly for error reporting to work (it is part of the recommended config and the example app). The library does not call `capture_exception` itself, so this integration is not optional for error visibility.
|
|
338
338
|
|
|
339
|
-
**SDK version compatibility:**
|
|
339
|
+
**SDK version compatibility:** requires sentry-sdk 3.0+ (stream mode); 2.x is not supported. `start_span` is both root and child and metadata is attached via `set_attribute`.
|
|
340
340
|
|
|
341
341
|
`task_scope` and `handler_error_scope` are no-ops when `sentry_sdk` is not installed or no client is initialised, so Sentry is not a dependency of the library. `sentry-sdk` is a dev dependency only (pinned `>=2,<3`), for the test suite; a dedicated CI job additionally runs the suite against the latest sentry-sdk 3.x pre-release on Python 3.14.
|
|
342
342
|
|
|
@@ -48,7 +48,7 @@ django-lambda-tasks/
|
|
|
48
48
|
- `environment_loader.py` — loads env vars from a Secrets Manager secret at cold start; validates flat JSON format; idempotent via `_loaded` sentinel
|
|
49
49
|
- `secret_loader.py` — resolves `LAMBDA_TASKS_SECRET_*` env vars from Secrets Manager before Django starts; validates format, detects conflicts, batches API calls; idempotent via `_loaded` sentinel
|
|
50
50
|
- `logging.py` — `task_logger` singleton; `message_id` set/cleared around each task execution
|
|
51
|
-
- `sentry.py` — `task_scope` context manager + `handler_error_scope` context manager. `task_scope` opens an isolated `new_scope` and traces the task. With the **recommended** host config (no `AwsLambdaIntegration`) nothing is active, so the task starts its **own transaction named after the task** on both Lambda and Batch. If a host keeps `AwsLambdaIntegration`, the task is instead traced as a **child span** of the active invocation transaction (
|
|
51
|
+
- `sentry.py` — `task_scope` context manager + `handler_error_scope` context manager. `task_scope` opens an isolated `new_scope` and traces the task. With the **recommended** host config (no `AwsLambdaIntegration`) nothing is active, so the task starts its **own transaction named after the task** on both Lambda and Batch. If a host keeps `AwsLambdaIntegration`, the task is instead traced as a **child span** of the active invocation transaction (`start_span` is auto root-or-child on 3.0) — never a second, competing transaction, which would double trace volume and defeat `traces_sample_rate`. Records `lambda_task` / `lambda_task.message_id` / `lambda_task.n_retries` / `lambda_task.runtime` as span metadata and scope tags (runtime read from `AWS_LAMBDA_FUNCTION_NAME` or `AWS_BATCH_JQ_NAME`). Deliberately does not call `set_transaction_name` (would rename an active invocation transaction and break segment naming); error attribution rides on the `lambda_task` tag. **Failure reporting** is via error logs, not explicit captures: the terminal failure branches in `models.py` (plain failure + max-retries) call `task_logger.error(error, exc_info=True)`, and the host's `LoggingIntegration(event_level=ERROR)` turns that into the Sentry event (the retry branch logs at WARNING and is not reported). `handler_error_scope(message_id=...)` is a context manager used in `handler.py` to tag an isolated scope (`lambda_task.handler_error` + message id) around the handler's `logger.error`, so pre-task failures are reported and identifiable via the same LoggingIntegration. Requires sentry-sdk 3.0+ (`start_span`/`set_attribute`). No-op when `sentry_sdk` is absent or uninitialised (`sentry-sdk` is a dev dependency only, pinned `>=3`). Wrapped around the task body in `SQSLambdaTaskMessage.execute_immediately`. Error reporting requires `LoggingIntegration(event_level=logging.ERROR)` in the host init (must be set explicitly on 3.0); demonstrated in the example app
|
|
52
52
|
- `settings.py` — constants (`MAX_DELAY`, `MAX_TIMEOUT`, `MAX_BATCH_TIMEOUT`); `_is_sqs_queue()` and `_is_batch_queue()` helpers; `LambdaTasksSettings` instantiated fresh per use (reads live Django settings); `queue_max_timeout()` method returns 900 or 3600 based on queue type
|
|
53
53
|
- `admin.py` — Django admin registration for `TaskRecord`
|
|
54
54
|
- `apps.py` — Django `AppConfig`; `ready()` imports `checks` to register deployment checks and installs the local-executor shutdown signal handlers when `LOCAL_WORKERS > 0`
|
|
@@ -23,7 +23,7 @@ inclusion: always
|
|
|
23
23
|
|---|---|---|
|
|
24
24
|
| `pytest` | `>= 9.0.2` | Test runner |
|
|
25
25
|
| `hypothesis` | present | Property-based testing (`.hypothesis/` directory exists) |
|
|
26
|
-
| `sentry-sdk` | `>=
|
|
26
|
+
| `sentry-sdk` | `>=3` | Testing the Sentry integration (`task_scope`, `handler_error_scope`). Not a runtime dependency |
|
|
27
27
|
|
|
28
28
|
## Package Manager
|
|
29
29
|
|
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
Metadata-Version: 2.5
|
|
2
2
|
Name: django-lambda-tasks
|
|
3
|
-
Version: 0.
|
|
3
|
+
Version: 0.12.0
|
|
4
4
|
Summary: Run async tasks in a lambda function
|
|
5
5
|
Requires-Python: >=3.11
|
|
6
6
|
Requires-Dist: awslambdaric
|
|
@@ -474,7 +474,7 @@ sentry_sdk.init(
|
|
|
474
474
|
Two deliberate choices:
|
|
475
475
|
|
|
476
476
|
- **No `AwsLambdaIntegration`.** It names every event's transaction after the Lambda function, which hides which task ran — all tasks would look the same. Without it, each task's trace is named after the task (see below). You lose `AwsLambdaIntegration`'s automatic reporting of handler-level failures, but the library reports those itself (see "Failures outside a task"), so nothing is lost in practice.
|
|
477
|
-
- **`LoggingIntegration(event_level=logging.ERROR)`.** This makes `logger.error(...)` (including `task_logger`) become Sentry events. On sentry-sdk
|
|
477
|
+
- **`LoggingIntegration(event_level=logging.ERROR)`.** This makes `logger.error(...)` (including `task_logger`) become Sentry events. On sentry-sdk 3.0 the default is `None`, so you must set it explicitly.
|
|
478
478
|
|
|
479
479
|
#### What the library does per task
|
|
480
480
|
|
|
@@ -490,7 +490,7 @@ Error attribution also relies on the `lambda_task` **tag**, so it is reliable ev
|
|
|
490
490
|
|
|
491
491
|
#### Task failures are reported
|
|
492
492
|
|
|
493
|
-
The executor catches a failing task's exception (recording a `FAILED` `TaskRecord`) rather than re-raising it. On the **terminal failure paths** — a plain failure and max-retries-exceeded — the library logs the exception at ERROR (`task_logger.error(..., exc_info=True)`), which your `LoggingIntegration(event_level=ERROR)` turns into a Sentry event, attributed to the task via the active scope tags. This is why that integration is part of the recommended config: without it, a merely-caught exception produces no error event
|
|
493
|
+
The executor catches a failing task's exception (recording a `FAILED` `TaskRecord`) rather than re-raising it. On the **terminal failure paths** — a plain failure and max-retries-exceeded — the library logs the exception at ERROR (`task_logger.error(..., exc_info=True)`), which your `LoggingIntegration(event_level=ERROR)` turns into a Sentry event, attributed to the task via the active scope tags. This is why that integration is part of the recommended config: without it, a merely-caught exception produces no error event.
|
|
494
494
|
|
|
495
495
|
Transient, retryable failures (a task that will be re-enqueued) are logged at WARNING and **not** reported to Sentry, to avoid flooding on every retry; only the final, terminal failure is reported.
|
|
496
496
|
|
|
@@ -500,7 +500,7 @@ Pre-execution failures in the Lambda/Batch handler — a malformed SQS message,
|
|
|
500
500
|
|
|
501
501
|
#### SDK version compatibility
|
|
502
502
|
|
|
503
|
-
The integration
|
|
503
|
+
The integration requires sentry-sdk 3.0 or later (stream mode); sentry-sdk 2.x is not supported. It uses `start_span`/`set_attribute`.
|
|
504
504
|
|
|
505
505
|
`sentry_sdk` is not a dependency of this library — if it is not installed or not initialised, all of the above is a silent no-op.
|
|
506
506
|
|
|
@@ -462,7 +462,7 @@ sentry_sdk.init(
|
|
|
462
462
|
Two deliberate choices:
|
|
463
463
|
|
|
464
464
|
- **No `AwsLambdaIntegration`.** It names every event's transaction after the Lambda function, which hides which task ran — all tasks would look the same. Without it, each task's trace is named after the task (see below). You lose `AwsLambdaIntegration`'s automatic reporting of handler-level failures, but the library reports those itself (see "Failures outside a task"), so nothing is lost in practice.
|
|
465
|
-
- **`LoggingIntegration(event_level=logging.ERROR)`.** This makes `logger.error(...)` (including `task_logger`) become Sentry events. On sentry-sdk
|
|
465
|
+
- **`LoggingIntegration(event_level=logging.ERROR)`.** This makes `logger.error(...)` (including `task_logger`) become Sentry events. On sentry-sdk 3.0 the default is `None`, so you must set it explicitly.
|
|
466
466
|
|
|
467
467
|
#### What the library does per task
|
|
468
468
|
|
|
@@ -478,7 +478,7 @@ Error attribution also relies on the `lambda_task` **tag**, so it is reliable ev
|
|
|
478
478
|
|
|
479
479
|
#### Task failures are reported
|
|
480
480
|
|
|
481
|
-
The executor catches a failing task's exception (recording a `FAILED` `TaskRecord`) rather than re-raising it. On the **terminal failure paths** — a plain failure and max-retries-exceeded — the library logs the exception at ERROR (`task_logger.error(..., exc_info=True)`), which your `LoggingIntegration(event_level=ERROR)` turns into a Sentry event, attributed to the task via the active scope tags. This is why that integration is part of the recommended config: without it, a merely-caught exception produces no error event
|
|
481
|
+
The executor catches a failing task's exception (recording a `FAILED` `TaskRecord`) rather than re-raising it. On the **terminal failure paths** — a plain failure and max-retries-exceeded — the library logs the exception at ERROR (`task_logger.error(..., exc_info=True)`), which your `LoggingIntegration(event_level=ERROR)` turns into a Sentry event, attributed to the task via the active scope tags. This is why that integration is part of the recommended config: without it, a merely-caught exception produces no error event.
|
|
482
482
|
|
|
483
483
|
Transient, retryable failures (a task that will be re-enqueued) are logged at WARNING and **not** reported to Sentry, to avoid flooding on every retry; only the final, terminal failure is reported.
|
|
484
484
|
|
|
@@ -488,7 +488,7 @@ Pre-execution failures in the Lambda/Batch handler — a malformed SQS message,
|
|
|
488
488
|
|
|
489
489
|
#### SDK version compatibility
|
|
490
490
|
|
|
491
|
-
The integration
|
|
491
|
+
The integration requires sentry-sdk 3.0 or later (stream mode); sentry-sdk 2.x is not supported. It uses `start_span`/`set_attribute`.
|
|
492
492
|
|
|
493
493
|
`sentry_sdk` is not a dependency of this library — if it is not installed or not initialised, all of the above is a silent no-op.
|
|
494
494
|
|
|
@@ -39,9 +39,8 @@ def init_sentry() -> None:
|
|
|
39
39
|
# LoggingIntegration(event_level=ERROR) is REQUIRED, not optional:
|
|
40
40
|
# the library reports task and handler failures by logging them at
|
|
41
41
|
# ERROR (not by calling capture_exception), so this integration is
|
|
42
|
-
# what turns those logs into Sentry events. On sentry-sdk
|
|
43
|
-
#
|
|
44
|
-
# it must be set explicitly.
|
|
42
|
+
# what turns those logs into Sentry events. On sentry-sdk 3.0 the
|
|
43
|
+
# default is None, so it must be set explicitly.
|
|
45
44
|
LoggingIntegration(event_level=logging.ERROR),
|
|
46
45
|
],
|
|
47
46
|
disabled_integrations=[
|
|
@@ -23,21 +23,11 @@ transaction is sampled, so sampling is respected.
|
|
|
23
23
|
Error attribution does not depend on the trace being sampled: the ``lambda_task``
|
|
24
24
|
scope tag carries the task name on every error event regardless.
|
|
25
25
|
|
|
26
|
-
|
|
27
|
-
|
|
28
|
-
|
|
29
|
-
|
|
30
|
-
|
|
31
|
-
``start_span``. Metadata is attached with ``set_tag``; ``Span.set_attribute``
|
|
32
|
-
does not exist, and ``Scope`` has a ``transaction`` attribute.
|
|
33
|
-
* 3.0 — transaction mode is gone. ``start_span`` is both root (when nothing is
|
|
34
|
-
active) and child (when something is), metadata is attached via
|
|
35
|
-
``set_attribute``, and ``Scope`` has no ``transaction`` attribute.
|
|
36
|
-
|
|
37
|
-
We detect which API is present at runtime (via ``hasattr``) and use the correct
|
|
38
|
-
one, so this module keeps working unchanged after an SDK upgrade. Metadata is
|
|
39
|
-
attached with whichever setter the running span exposes (``set_attribute`` when
|
|
40
|
-
available, otherwise ``set_tag``).
|
|
26
|
+
SDK support
|
|
27
|
+
-----------
|
|
28
|
+
Requires sentry-sdk 3.0 or later (stream mode). ``start_span`` is both a root
|
|
29
|
+
(when nothing is active) and a child (when something is), and metadata is
|
|
30
|
+
attached to spans via ``set_attribute``.
|
|
41
31
|
|
|
42
32
|
Everything here degrades to a no-op when ``sentry_sdk`` is not installed or no
|
|
43
33
|
client is active, so the library has no hard dependency on Sentry.
|
|
@@ -66,60 +56,6 @@ def _runtime_environment() -> str | None:
|
|
|
66
56
|
)
|
|
67
57
|
|
|
68
58
|
|
|
69
|
-
def _set_metadata(span: Any, *, key: str, value: Any) -> None:
|
|
70
|
-
"""Attach *key*/*value* to *span* using whichever setter the SDK exposes.
|
|
71
|
-
|
|
72
|
-
SDK 3.0 (stream mode) spans use ``set_attribute``; SDK 2.x transactions use
|
|
73
|
-
``set_tag``. Preferring ``set_attribute`` means the richer, future API is
|
|
74
|
-
used whenever it is available.
|
|
75
|
-
"""
|
|
76
|
-
if hasattr(span, "set_attribute"):
|
|
77
|
-
span.set_attribute(key, value)
|
|
78
|
-
else:
|
|
79
|
-
span.set_tag(key, value)
|
|
80
|
-
|
|
81
|
-
|
|
82
|
-
def _start_task_root(*, task_name: str) -> Any:
|
|
83
|
-
"""Start and return the per-task span/transaction context manager.
|
|
84
|
-
|
|
85
|
-
Crucially, this starts a **child span** when a trace is already active
|
|
86
|
-
(e.g. ``AwsLambdaIntegration`` starts a transaction per Lambda invocation)
|
|
87
|
-
and only starts a **new transaction** when nothing is active (e.g. AWS
|
|
88
|
-
Batch, where there is no Lambda integration).
|
|
89
|
-
|
|
90
|
-
Why this matters for volume: starting a nested *transaction* under the
|
|
91
|
-
invocation transaction produced a *second* transaction per task that
|
|
92
|
-
inherited — rather than independently re-rolled — the parent's sampling
|
|
93
|
-
decision, roughly doubling transaction volume and defeating
|
|
94
|
-
``traces_sample_rate``. A child span carries no separate sampling decision:
|
|
95
|
-
it is sent only if its parent transaction is sampled, so one invocation
|
|
96
|
-
yields one transaction with the task span nested inside it.
|
|
97
|
-
|
|
98
|
-
The tracing API also differs across the SDK 2.x → 3.0 boundary:
|
|
99
|
-
|
|
100
|
-
* 2.x — ``start_transaction(name=, op=)`` for a root; ``start_span`` for a
|
|
101
|
-
child of the active transaction.
|
|
102
|
-
* 3.0 — transactions are gone; ``start_span(name=)`` is both the root (when
|
|
103
|
-
nothing is active) and a child (when something is), and no longer accepts
|
|
104
|
-
``op``.
|
|
105
|
-
"""
|
|
106
|
-
if not hasattr(sentry_sdk, "start_transaction"):
|
|
107
|
-
# SDK 3.0: start_span is automatically a root when nothing is active
|
|
108
|
-
# and a child otherwise — no manual active-trace check needed. (Scope
|
|
109
|
-
# has no ``transaction`` attribute on 3.0.)
|
|
110
|
-
return sentry_sdk.start_span(name=task_name)
|
|
111
|
-
else:
|
|
112
|
-
# SDK 2.x: a bare start_span with no active transaction is dropped,
|
|
113
|
-
# so pick child span vs. new transaction based on whether a trace is
|
|
114
|
-
# already active.
|
|
115
|
-
has_active_transaction = sentry_sdk.get_current_scope().transaction is not None
|
|
116
|
-
|
|
117
|
-
if has_active_transaction:
|
|
118
|
-
return sentry_sdk.start_span(op="task", name=task_name)
|
|
119
|
-
else:
|
|
120
|
-
return sentry_sdk.start_transaction(name=task_name, op="task")
|
|
121
|
-
|
|
122
|
-
|
|
123
59
|
def handler_error_scope(
|
|
124
60
|
*, message_id: str | None = None
|
|
125
61
|
) -> "contextlib.AbstractContextManager[Any]":
|
|
@@ -191,11 +127,15 @@ def task_scope(*, task_name: str, message_id: str, n_retries: int) -> Iterator[N
|
|
|
191
127
|
if runtime:
|
|
192
128
|
scope.set_tag("lambda_task.runtime", runtime)
|
|
193
129
|
|
|
194
|
-
|
|
195
|
-
|
|
196
|
-
|
|
197
|
-
|
|
130
|
+
# On SDK 3.0 start_span is automatically a root when nothing is active
|
|
131
|
+
# (e.g. AWS Batch) and a child of the active span otherwise (e.g. under
|
|
132
|
+
# AwsLambdaIntegration). A child is sent only if its parent is sampled,
|
|
133
|
+
# so one invocation yields one trace and traces_sample_rate is respected.
|
|
134
|
+
with sentry_sdk.start_span(name=task_name) as span:
|
|
135
|
+
span.set_attribute("lambda_task", task_name)
|
|
136
|
+
span.set_attribute("lambda_task.message_id", message_id)
|
|
137
|
+
span.set_attribute("lambda_task.n_retries", n_retries)
|
|
198
138
|
if runtime:
|
|
199
|
-
|
|
139
|
+
span.set_attribute("lambda_task.runtime", runtime)
|
|
200
140
|
|
|
201
141
|
yield
|
|
@@ -7,7 +7,7 @@ packages = ["lambda_tasks"]
|
|
|
7
7
|
|
|
8
8
|
[project]
|
|
9
9
|
name = "django-lambda-tasks"
|
|
10
|
-
version = "0.
|
|
10
|
+
version = "0.12.0"
|
|
11
11
|
description = "Run async tasks in a lambda function"
|
|
12
12
|
readme = "README.md"
|
|
13
13
|
requires-python = ">=3.11"
|
|
@@ -31,7 +31,7 @@ dev = [
|
|
|
31
31
|
"pytest-cov",
|
|
32
32
|
"ty",
|
|
33
33
|
"psycopg",
|
|
34
|
-
"sentry-sdk>=
|
|
34
|
+
"sentry-sdk>=3",
|
|
35
35
|
]
|
|
36
36
|
|
|
37
37
|
[tool.ty.rules]
|
|
@@ -7,6 +7,7 @@ when Sentry is not initialised.
|
|
|
7
7
|
"""
|
|
8
8
|
|
|
9
9
|
import threading
|
|
10
|
+
import time
|
|
10
11
|
import uuid
|
|
11
12
|
from unittest.mock import patch
|
|
12
13
|
|
|
@@ -25,6 +26,9 @@ from lambda_tasks.models import (
|
|
|
25
26
|
from lambda_tasks.sentry import handler_error_scope, task_scope
|
|
26
27
|
from lambda_tasks.settings import LambdaTasksSettings
|
|
27
28
|
|
|
29
|
+
# Upper bound on how long to wait for asynchronously delivered spans.
|
|
30
|
+
_TRACE_WAIT_TIMEOUT = 5.0
|
|
31
|
+
|
|
28
32
|
# ---------------------------------------------------------------------------
|
|
29
33
|
# Tasks (module level for import_string resolution)
|
|
30
34
|
# ---------------------------------------------------------------------------
|
|
@@ -47,7 +51,6 @@ def _sentry_task_raises(*, msg: str) -> None:
|
|
|
47
51
|
def _sentry_task_logs_error(*, msg: str) -> str:
|
|
48
52
|
# Logs an error via task_logger without raising. With a host-configured
|
|
49
53
|
# LoggingIntegration(event_level=ERROR) this surfaces as a Sentry event on
|
|
50
|
-
# both SDK 2.x and 3.0.
|
|
51
54
|
try:
|
|
52
55
|
raise ValueError(msg)
|
|
53
56
|
except ValueError as error:
|
|
@@ -76,25 +79,11 @@ def _make_message(*, task_name: str, kwargs: dict) -> SQSLambdaTaskMessage:
|
|
|
76
79
|
return SQSLambdaTaskMessage(task_name=task_name, kwargs=kwargs)
|
|
77
80
|
|
|
78
81
|
|
|
79
|
-
def _active_root(name: str):
|
|
80
|
-
"""Start an outer root transaction/segment, as AwsLambdaIntegration would.
|
|
81
|
-
|
|
82
|
-
Uses ``start_transaction`` on SDK 2.x and ``start_span`` on 3.0 so the test
|
|
83
|
-
simulates an already-active invocation trace on both SDK versions.
|
|
84
|
-
"""
|
|
85
|
-
if hasattr(sentry_sdk, "start_transaction"):
|
|
86
|
-
return sentry_sdk.start_transaction(name=name, op="function.aws")
|
|
87
|
-
else:
|
|
88
|
-
return sentry_sdk.start_span(name=name)
|
|
89
|
-
|
|
90
|
-
|
|
91
82
|
class _CapturedTrace:
|
|
92
|
-
"""A captured
|
|
83
|
+
"""A captured span.
|
|
93
84
|
|
|
94
|
-
``
|
|
95
|
-
|
|
96
|
-
tags (2.x) and span attributes (3.0). ``is_root`` is True when this is a
|
|
97
|
-
root transaction/segment rather than a child span.
|
|
85
|
+
``meta`` holds the span attributes. ``is_root`` is True when this is a
|
|
86
|
+
root segment rather than a child span.
|
|
98
87
|
"""
|
|
99
88
|
|
|
100
89
|
def __init__(self, *, name: str, meta: dict, is_root: bool = True) -> None:
|
|
@@ -103,33 +92,10 @@ class _CapturedTrace:
|
|
|
103
92
|
self.is_root = is_root
|
|
104
93
|
|
|
105
94
|
|
|
106
|
-
def
|
|
107
|
-
"""Flatten a 2.x transaction envelope into its root plus child spans.
|
|
108
|
-
|
|
109
|
-
On 2.x child spans are bundled inside the transaction payload rather than
|
|
110
|
-
sent separately, so we expand them here to mirror the 3.0 shape.
|
|
111
|
-
"""
|
|
112
|
-
trace = event.get("contexts", {}).get("trace", {})
|
|
113
|
-
root_meta = {**event.get("tags", {}), **(trace.get("data") or {})}
|
|
114
|
-
traces = [
|
|
115
|
-
_CapturedTrace(name=event.get("transaction", ""), meta=root_meta, is_root=True)
|
|
116
|
-
]
|
|
117
|
-
for span in event.get("spans", []):
|
|
118
|
-
meta = {**(span.get("tags") or {}), **(span.get("data") or {})}
|
|
119
|
-
traces.append(
|
|
120
|
-
_CapturedTrace(
|
|
121
|
-
name=span.get("description") or span.get("op") or "",
|
|
122
|
-
meta=meta,
|
|
123
|
-
is_root=False,
|
|
124
|
-
)
|
|
125
|
-
)
|
|
126
|
-
return traces
|
|
127
|
-
|
|
128
|
-
|
|
129
|
-
def _normalise_3x_spans(payload: dict) -> list[_CapturedTrace]:
|
|
95
|
+
def _normalise_spans(payload: dict) -> list[_CapturedTrace]:
|
|
130
96
|
traces: list[_CapturedTrace] = []
|
|
131
97
|
for span in payload.get("items", []):
|
|
132
|
-
#
|
|
98
|
+
# Attributes are {key: {"value": ..., "type": ...}}.
|
|
133
99
|
meta = {k: v.get("value") for k, v in span.get("attributes", {}).items()}
|
|
134
100
|
traces.append(
|
|
135
101
|
_CapturedTrace(
|
|
@@ -144,8 +110,7 @@ def _normalise_3x_spans(payload: dict) -> list[_CapturedTrace]:
|
|
|
144
110
|
class _CapturingTransport(Transport):
|
|
145
111
|
"""In-memory Sentry transport recording error and trace events.
|
|
146
112
|
|
|
147
|
-
|
|
148
|
-
(stream-mode spans, envelope items of type ``span``).
|
|
113
|
+
Traces are stream-mode spans (envelope items of type ``span``).
|
|
149
114
|
|
|
150
115
|
Access is guarded by a lock and reads return snapshots: ``sentry_sdk`` may
|
|
151
116
|
deliver envelopes from a background thread (observed on some 3.x
|
|
@@ -165,12 +130,9 @@ class _CapturingTransport(Transport):
|
|
|
165
130
|
if error is not None:
|
|
166
131
|
with self._lock:
|
|
167
132
|
self._errors.append(error)
|
|
168
|
-
elif item.type == "
|
|
133
|
+
elif item.type == "span": # stream mode
|
|
169
134
|
with self._lock:
|
|
170
|
-
self._traces.extend(
|
|
171
|
-
elif item.type == "span": # SDK 3.0 stream mode
|
|
172
|
-
with self._lock:
|
|
173
|
-
self._traces.extend(_normalise_3x_spans(item.payload.json))
|
|
135
|
+
self._traces.extend(_normalise_spans(item.payload.json))
|
|
174
136
|
|
|
175
137
|
def snapshot_errors(self) -> list[dict]:
|
|
176
138
|
with self._lock:
|
|
@@ -191,22 +153,32 @@ class _Captured:
|
|
|
191
153
|
def errors(self) -> list[dict]:
|
|
192
154
|
return self._transport.snapshot_errors()
|
|
193
155
|
|
|
194
|
-
|
|
195
|
-
|
|
196
|
-
|
|
197
|
-
|
|
156
|
+
def _wait_for_traces(self, predicate) -> list[_CapturedTrace]:
|
|
157
|
+
"""Flush and poll until *predicate(traces)* holds, then return traces.
|
|
158
|
+
|
|
159
|
+
Stream mode batches spans and may deliver them to the transport from a
|
|
160
|
+
background thread, so a single ``flush()`` followed by an immediate
|
|
161
|
+
read can race the delivery. Poll (bounded by a timeout) instead; on
|
|
162
|
+
timeout return what was captured so the caller's assertion reports it.
|
|
163
|
+
"""
|
|
164
|
+
deadline = time.monotonic() + _TRACE_WAIT_TIMEOUT
|
|
165
|
+
while True:
|
|
166
|
+
sentry_sdk.flush()
|
|
167
|
+
traces = self._transport.snapshot_traces()
|
|
168
|
+
if predicate(traces) or time.monotonic() >= deadline:
|
|
169
|
+
return traces
|
|
170
|
+
time.sleep(0.01)
|
|
198
171
|
|
|
199
|
-
def
|
|
200
|
-
"""Return the single captured root
|
|
172
|
+
def task_trace(self, name: str) -> _CapturedTrace:
|
|
173
|
+
"""Return the single captured trace (root or child span) named *name*.
|
|
201
174
|
|
|
202
|
-
|
|
203
|
-
|
|
204
|
-
position. Flushes first because 3.0 stream mode sends spans
|
|
205
|
-
asynchronously in batches.
|
|
175
|
+
The Django integration auto-instruments DB/signal spans, so the
|
|
176
|
+
transport sees many spans; select ours by name rather than by position.
|
|
206
177
|
"""
|
|
207
|
-
|
|
208
|
-
|
|
209
|
-
|
|
178
|
+
traces = self._wait_for_traces(
|
|
179
|
+
lambda traces: any(t.name == name for t in traces)
|
|
180
|
+
)
|
|
181
|
+
matches = [t for t in traces if t.name == name]
|
|
210
182
|
assert len(matches) == 1, (
|
|
211
183
|
f"expected exactly one trace named {name!r}, "
|
|
212
184
|
f"got {[t.name for t in traces]}"
|
|
@@ -214,25 +186,15 @@ class _Captured:
|
|
|
214
186
|
return matches[0]
|
|
215
187
|
|
|
216
188
|
def root_names(self) -> list[str]:
|
|
217
|
-
"""Names of all captured root
|
|
189
|
+
"""Names of all captured root segments (not child spans).
|
|
218
190
|
|
|
219
191
|
Used to assert that a task does not create its own root when it runs
|
|
220
|
-
inside an already-active trace (the Lambda case).
|
|
192
|
+
inside an already-active trace (the Lambda case). Call ``task_trace``
|
|
193
|
+
for the spans you expect first, so delivery has been awaited.
|
|
221
194
|
"""
|
|
222
195
|
sentry_sdk.flush()
|
|
223
196
|
return [t.name for t in self._transport.snapshot_traces() if t.is_root]
|
|
224
197
|
|
|
225
|
-
def task_trace(self, name: str) -> _CapturedTrace:
|
|
226
|
-
"""Return the single captured trace (root or child span) named *name*."""
|
|
227
|
-
sentry_sdk.flush()
|
|
228
|
-
traces = self._transport.snapshot_traces()
|
|
229
|
-
matches = [t for t in traces if t.name == name]
|
|
230
|
-
assert len(matches) == 1, (
|
|
231
|
-
f"expected exactly one trace named {name!r}, "
|
|
232
|
-
f"got {[t.name for t in traces]}"
|
|
233
|
-
)
|
|
234
|
-
return matches[0]
|
|
235
|
-
|
|
236
198
|
|
|
237
199
|
@pytest.fixture
|
|
238
200
|
def sentry():
|
|
@@ -259,10 +221,10 @@ def sentry_with_logging():
|
|
|
259
221
|
"""Like ``sentry`` but with ``LoggingIntegration(event_level=ERROR)``.
|
|
260
222
|
|
|
261
223
|
Mirrors a host application that wants ``logger.error(...)`` calls promoted
|
|
262
|
-
to Sentry events.
|
|
224
|
+
to Sentry events. The default is
|
|
263
225
|
``event_level=None``, so the integration must be configured explicitly for
|
|
264
226
|
error logs to surface. Testing with it enabled proves ``task_logger.error``
|
|
265
|
-
is reported
|
|
227
|
+
is reported.
|
|
266
228
|
"""
|
|
267
229
|
import logging
|
|
268
230
|
|
|
@@ -301,7 +263,7 @@ class TestTaskScope:
|
|
|
301
263
|
with task_scope(task_name="a.b.c", message_id="mid-1", n_retries=2):
|
|
302
264
|
pass
|
|
303
265
|
|
|
304
|
-
assert sentry.
|
|
266
|
+
assert sentry.task_trace("a.b.c").name == "a.b.c"
|
|
305
267
|
|
|
306
268
|
def test_error_event_attributed_to_task_name(self, sentry):
|
|
307
269
|
with task_scope(task_name="a.b.c", message_id="mid-1", n_retries=2):
|
|
@@ -318,9 +280,9 @@ class TestTaskScope:
|
|
|
318
280
|
with task_scope(task_name="a.b.c", message_id="mid-1", n_retries=2):
|
|
319
281
|
pass
|
|
320
282
|
|
|
321
|
-
# Metadata lands as
|
|
283
|
+
# Metadata lands as span attributes;
|
|
322
284
|
# the captured trace normalises both into `meta`.
|
|
323
|
-
meta = sentry.
|
|
285
|
+
meta = sentry.task_trace("a.b.c").meta
|
|
324
286
|
assert meta["lambda_task"] == "a.b.c"
|
|
325
287
|
assert meta["lambda_task.message_id"] == "mid-1"
|
|
326
288
|
|
|
@@ -383,15 +345,15 @@ class TestTaskTraceNesting:
|
|
|
383
345
|
# the task must NOT open a second root transaction — it nests as a
|
|
384
346
|
# child span. This is what keeps task tracing from doubling trace
|
|
385
347
|
# volume and defeating traces_sample_rate.
|
|
386
|
-
with
|
|
348
|
+
with sentry_sdk.start_span(name="lambda-invocation"):
|
|
387
349
|
with task_scope(task_name="myapp.tasks.greet", message_id="m", n_retries=0):
|
|
388
350
|
pass
|
|
389
351
|
|
|
390
352
|
# The task is a child span (not a root), and it did not create its own
|
|
391
353
|
# root transaction — the only root is the invocation.
|
|
392
354
|
assert sentry.task_trace("myapp.tasks.greet").is_root is False
|
|
355
|
+
assert sentry.task_trace("lambda-invocation").is_root is True
|
|
393
356
|
assert "myapp.tasks.greet" not in sentry.root_names()
|
|
394
|
-
assert "lambda-invocation" in sentry.root_names()
|
|
395
357
|
|
|
396
358
|
def test_task_is_root_when_no_trace_active(self, sentry):
|
|
397
359
|
# Batch case: no Lambda integration, nothing active, so the task opens
|
|
@@ -404,7 +366,7 @@ class TestTaskTraceNesting:
|
|
|
404
366
|
assert "myapp.tasks.greet" in sentry.root_names()
|
|
405
367
|
|
|
406
368
|
def test_task_child_span_carries_metadata(self, sentry):
|
|
407
|
-
with
|
|
369
|
+
with sentry_sdk.start_span(name="lambda-invocation"):
|
|
408
370
|
with task_scope(
|
|
409
371
|
task_name="myapp.tasks.greet", message_id="mid-9", n_retries=1
|
|
410
372
|
):
|
|
@@ -433,7 +395,7 @@ class TestExecuteImmediatelySentry:
|
|
|
433
395
|
assert TaskRecord.objects.get(pk=message_id).status == (
|
|
434
396
|
TaskRecord.TaskStatus.SUCCEEDED
|
|
435
397
|
)
|
|
436
|
-
assert sentry.
|
|
398
|
+
assert sentry.task_trace(task_name).name == task_name
|
|
437
399
|
assert sentry.errors[0]["transaction"] == task_name
|
|
438
400
|
assert sentry.errors[0]["tags"]["lambda_task.message_id"] == message_id
|
|
439
401
|
|
|
@@ -442,7 +404,7 @@ class TestExecuteImmediatelySentry:
|
|
|
442
404
|
):
|
|
443
405
|
# The task body is a plain `raise`. The library logs it at ERROR, which
|
|
444
406
|
# the host's LoggingIntegration turns into a Sentry event — attributed
|
|
445
|
-
# to the task via the active task_scope tags.
|
|
407
|
+
# to the task via the active task_scope tags.
|
|
446
408
|
sentry = sentry_with_logging
|
|
447
409
|
task_name = _task_name(_sentry_task_raises)
|
|
448
410
|
message = _make_message(task_name=task_name, kwargs={"msg": "boom"})
|
|
@@ -473,7 +435,7 @@ class TestTaskFailureReporting:
|
|
|
473
435
|
def test_terminal_failure_reports_exception_event(self, sentry_with_logging):
|
|
474
436
|
# Plain-failure branch: the library logs the exception at ERROR; with the
|
|
475
437
|
# host's LoggingIntegration that becomes a single Sentry event with the
|
|
476
|
-
# task's exception type
|
|
438
|
+
# task's exception type.
|
|
477
439
|
sentry = sentry_with_logging
|
|
478
440
|
task_name = _task_name(_sentry_task_raises)
|
|
479
441
|
message = _make_message(task_name=task_name, kwargs={"msg": "kaboom"})
|
|
@@ -550,7 +512,7 @@ class TestTaskFailureReporting:
|
|
|
550
512
|
):
|
|
551
513
|
# task_logger.error(...) inside a task surfaces as a Sentry event when
|
|
552
514
|
# the host enables LoggingIntegration(event_level=ERROR) — the explicit
|
|
553
|
-
# config needed on 3.0
|
|
515
|
+
# config needed on 3.0.
|
|
554
516
|
task_name = _task_name(_sentry_task_logs_error)
|
|
555
517
|
message = _make_message(task_name=task_name, kwargs={"msg": "logged failure"})
|
|
556
518
|
message_id = str(uuid.uuid4())
|
|
@@ -1,87 +0,0 @@
|
|
|
1
|
-
name: CI
|
|
2
|
-
|
|
3
|
-
on:
|
|
4
|
-
push:
|
|
5
|
-
pull_request:
|
|
6
|
-
workflow_call:
|
|
7
|
-
|
|
8
|
-
env:
|
|
9
|
-
MINIMUM_PYTHON_VERSION: '3.11'
|
|
10
|
-
|
|
11
|
-
concurrency:
|
|
12
|
-
group: ${{ github.head_ref || github.run_id }}
|
|
13
|
-
cancel-in-progress: true
|
|
14
|
-
|
|
15
|
-
jobs:
|
|
16
|
-
|
|
17
|
-
precommit:
|
|
18
|
-
runs-on: ubuntu-latest
|
|
19
|
-
steps:
|
|
20
|
-
- uses: actions/checkout@3d3c42e5aac5ba805825da76410c181273ba90b1 # v7.0.1
|
|
21
|
-
- name: Install uv and set the python version
|
|
22
|
-
uses: astral-sh/setup-uv@68559e99cc807c1eb7e9238fd43a15bba460eec2 # v10.3.3
|
|
23
|
-
with:
|
|
24
|
-
python-version: ${{ env.MINIMUM_PYTHON_VERSION }}
|
|
25
|
-
- name: Run static code inspections
|
|
26
|
-
run: uv run pre-commit run --all-files
|
|
27
|
-
|
|
28
|
-
build:
|
|
29
|
-
runs-on: ubuntu-latest
|
|
30
|
-
strategy:
|
|
31
|
-
matrix:
|
|
32
|
-
python-version: ["3.11", "3.12", "3.13", "3.14", "3.15"]
|
|
33
|
-
services:
|
|
34
|
-
postgres:
|
|
35
|
-
image: postgres:17
|
|
36
|
-
env:
|
|
37
|
-
POSTGRES_DB: lambda_tasks_test
|
|
38
|
-
POSTGRES_USER: postgres
|
|
39
|
-
POSTGRES_PASSWORD: postgres
|
|
40
|
-
ports:
|
|
41
|
-
- 5432:5432
|
|
42
|
-
options: >-
|
|
43
|
-
--health-cmd "pg_isready -U postgres"
|
|
44
|
-
--health-interval 10s
|
|
45
|
-
--health-timeout 5s
|
|
46
|
-
--health-retries 5
|
|
47
|
-
steps:
|
|
48
|
-
- uses: actions/checkout@3d3c42e5aac5ba805825da76410c181273ba90b1 # v7.0.1
|
|
49
|
-
- name: Install uv and set the python version
|
|
50
|
-
uses: astral-sh/setup-uv@68559e99cc807c1eb7e9238fd43a15bba460eec2 # v10.3.3
|
|
51
|
-
with:
|
|
52
|
-
python-version: ${{ matrix.python-version }}
|
|
53
|
-
- name: Run tests
|
|
54
|
-
run: |
|
|
55
|
-
uv run pytest --cov-branch --cov-report term-missing --cov=tests/ --cov=lambda_tasks/
|
|
56
|
-
|
|
57
|
-
sentry-prerelease:
|
|
58
|
-
# Exercise the Sentry integration against the latest 3.x pre-release of
|
|
59
|
-
# sentry-sdk (stream mode). The committed dev dependency is pinned to the
|
|
60
|
-
# stable 2.x line; this job overrides it at runtime via `uv run --with`
|
|
61
|
-
# without touching pyproject.toml, so regressions in the 3.x API are caught
|
|
62
|
-
# before the SDK goes stable.
|
|
63
|
-
runs-on: ubuntu-latest
|
|
64
|
-
services:
|
|
65
|
-
postgres:
|
|
66
|
-
image: postgres:17
|
|
67
|
-
env:
|
|
68
|
-
POSTGRES_DB: lambda_tasks_test
|
|
69
|
-
POSTGRES_USER: postgres
|
|
70
|
-
POSTGRES_PASSWORD: postgres
|
|
71
|
-
ports:
|
|
72
|
-
- 5432:5432
|
|
73
|
-
options: >-
|
|
74
|
-
--health-cmd "pg_isready -U postgres"
|
|
75
|
-
--health-interval 10s
|
|
76
|
-
--health-timeout 5s
|
|
77
|
-
--health-retries 5
|
|
78
|
-
steps:
|
|
79
|
-
- uses: actions/checkout@3d3c42e5aac5ba805825da76410c181273ba90b1 # v7.0.1
|
|
80
|
-
- name: Install uv and set the python version
|
|
81
|
-
uses: astral-sh/setup-uv@68559e99cc807c1eb7e9238fd43a15bba460eec2 # v10.3.3
|
|
82
|
-
with:
|
|
83
|
-
python-version: '3.14'
|
|
84
|
-
- name: Run tests against the latest sentry-sdk 3.x pre-release
|
|
85
|
-
run: |
|
|
86
|
-
uv run --prerelease=allow --with "sentry-sdk>=3.0.0b1" \
|
|
87
|
-
pytest --cov-branch --cov-report term-missing --cov=tests/ --cov=lambda_tasks/
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
{django_lambda_tasks-0.11.2 → django_lambda_tasks-0.12.0}/.kiro/specs/async-local-execution/tasks.md
RENAMED
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
{django_lambda_tasks-0.11.2 → django_lambda_tasks-0.12.0}/.kiro/specs/deferred-task-enqueue/tasks.md
RENAMED
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
{django_lambda_tasks-0.11.2 → django_lambda_tasks-0.12.0}/.kiro/specs/retry-delay/.config.kiro
RENAMED
|
File without changes
|
|
File without changes
|
{django_lambda_tasks-0.11.2 → django_lambda_tasks-0.12.0}/.kiro/specs/retry-delay/requirements.md
RENAMED
|
File without changes
|
|
File without changes
|
|
File without changes
|
{django_lambda_tasks-0.11.2 → django_lambda_tasks-0.12.0}/.kiro/specs/rse-background-tasks/design.md
RENAMED
|
File without changes
|
|
File without changes
|
{django_lambda_tasks-0.11.2 → django_lambda_tasks-0.12.0}/.kiro/specs/rse-background-tasks/tasks.md
RENAMED
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
{django_lambda_tasks-0.11.2 → django_lambda_tasks-0.12.0}/.kiro/specs/singleton-task/.config.kiro
RENAMED
|
File without changes
|
{django_lambda_tasks-0.11.2 → django_lambda_tasks-0.12.0}/.kiro/specs/singleton-task/design.md
RENAMED
|
File without changes
|
{django_lambda_tasks-0.11.2 → django_lambda_tasks-0.12.0}/.kiro/specs/singleton-task/requirements.md
RENAMED
|
File without changes
|
{django_lambda_tasks-0.11.2 → django_lambda_tasks-0.12.0}/.kiro/specs/singleton-task/tasks.md
RENAMED
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
{django_lambda_tasks-0.11.2 → django_lambda_tasks-0.12.0}/.kiro/specs/task-retry/.config.kiro
RENAMED
|
File without changes
|
|
File without changes
|
{django_lambda_tasks-0.11.2 → django_lambda_tasks-0.12.0}/.kiro/specs/task-retry/requirements.md
RENAMED
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
{django_lambda_tasks-0.11.2 → django_lambda_tasks-0.12.0}/example/example_project/__init__.py
RENAMED
|
File without changes
|
{django_lambda_tasks-0.11.2 → django_lambda_tasks-0.12.0}/example/example_project/settings.py
RENAMED
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
{django_lambda_tasks-0.11.2 → django_lambda_tasks-0.12.0}/lambda_tasks/environment_loader.py
RENAMED
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
{django_lambda_tasks-0.11.2 → django_lambda_tasks-0.12.0}/lambda_tasks/migrations/0001_initial.py
RENAMED
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
{django_lambda_tasks-0.11.2 → django_lambda_tasks-0.12.0}/lambda_tasks/migrations/__init__.py
RENAMED
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|