Add files using upload-large-folder tool
Browse filesThis view is limited to 50 files because it contains too many changes. See raw diff
- videollama2/lib/python3.10/site-packages/sentry_sdk/integrations/__pycache__/__init__.cpython-310.pyc +0 -0
- videollama2/lib/python3.10/site-packages/sentry_sdk/integrations/__pycache__/_wsgi_common.cpython-310.pyc +0 -0
- videollama2/lib/python3.10/site-packages/sentry_sdk/integrations/__pycache__/anthropic.cpython-310.pyc +0 -0
- videollama2/lib/python3.10/site-packages/sentry_sdk/integrations/__pycache__/argv.cpython-310.pyc +0 -0
- videollama2/lib/python3.10/site-packages/sentry_sdk/integrations/__pycache__/arq.cpython-310.pyc +0 -0
- videollama2/lib/python3.10/site-packages/sentry_sdk/integrations/__pycache__/asgi.cpython-310.pyc +0 -0
- videollama2/lib/python3.10/site-packages/sentry_sdk/integrations/__pycache__/asyncio.cpython-310.pyc +0 -0
- videollama2/lib/python3.10/site-packages/sentry_sdk/integrations/__pycache__/asyncpg.cpython-310.pyc +0 -0
- videollama2/lib/python3.10/site-packages/sentry_sdk/integrations/__pycache__/aws_lambda.cpython-310.pyc +0 -0
- videollama2/lib/python3.10/site-packages/sentry_sdk/integrations/__pycache__/beam.cpython-310.pyc +0 -0
- videollama2/lib/python3.10/site-packages/sentry_sdk/integrations/__pycache__/bottle.cpython-310.pyc +0 -0
- videollama2/lib/python3.10/site-packages/sentry_sdk/integrations/__pycache__/clickhouse_driver.cpython-310.pyc +0 -0
- videollama2/lib/python3.10/site-packages/sentry_sdk/integrations/__pycache__/cloud_resource_context.cpython-310.pyc +0 -0
- videollama2/lib/python3.10/site-packages/sentry_sdk/integrations/__pycache__/cohere.cpython-310.pyc +0 -0
- videollama2/lib/python3.10/site-packages/sentry_sdk/integrations/__pycache__/dedupe.cpython-310.pyc +0 -0
- videollama2/lib/python3.10/site-packages/sentry_sdk/integrations/__pycache__/dramatiq.cpython-310.pyc +0 -0
- videollama2/lib/python3.10/site-packages/sentry_sdk/integrations/__pycache__/executing.cpython-310.pyc +0 -0
- videollama2/lib/python3.10/site-packages/sentry_sdk/integrations/__pycache__/falcon.cpython-310.pyc +0 -0
- videollama2/lib/python3.10/site-packages/sentry_sdk/integrations/__pycache__/flask.cpython-310.pyc +0 -0
- videollama2/lib/python3.10/site-packages/sentry_sdk/integrations/__pycache__/gcp.cpython-310.pyc +0 -0
- videollama2/lib/python3.10/site-packages/sentry_sdk/integrations/__pycache__/gnu_backtrace.cpython-310.pyc +0 -0
- videollama2/lib/python3.10/site-packages/sentry_sdk/integrations/__pycache__/gql.cpython-310.pyc +0 -0
- videollama2/lib/python3.10/site-packages/sentry_sdk/integrations/__pycache__/graphene.cpython-310.pyc +0 -0
- videollama2/lib/python3.10/site-packages/sentry_sdk/integrations/__pycache__/httpx.cpython-310.pyc +0 -0
- videollama2/lib/python3.10/site-packages/sentry_sdk/integrations/__pycache__/huggingface_hub.cpython-310.pyc +0 -0
- videollama2/lib/python3.10/site-packages/sentry_sdk/integrations/__pycache__/langchain.cpython-310.pyc +0 -0
- videollama2/lib/python3.10/site-packages/sentry_sdk/integrations/__pycache__/litestar.cpython-310.pyc +0 -0
- videollama2/lib/python3.10/site-packages/sentry_sdk/integrations/__pycache__/logging.cpython-310.pyc +0 -0
- videollama2/lib/python3.10/site-packages/sentry_sdk/integrations/__pycache__/loguru.cpython-310.pyc +0 -0
- videollama2/lib/python3.10/site-packages/sentry_sdk/integrations/__pycache__/openai.cpython-310.pyc +0 -0
- videollama2/lib/python3.10/site-packages/sentry_sdk/integrations/__pycache__/pure_eval.cpython-310.pyc +0 -0
- videollama2/lib/python3.10/site-packages/sentry_sdk/integrations/__pycache__/pymongo.cpython-310.pyc +0 -0
- videollama2/lib/python3.10/site-packages/sentry_sdk/integrations/__pycache__/pyramid.cpython-310.pyc +0 -0
- videollama2/lib/python3.10/site-packages/sentry_sdk/integrations/__pycache__/quart.cpython-310.pyc +0 -0
- videollama2/lib/python3.10/site-packages/sentry_sdk/integrations/__pycache__/sanic.cpython-310.pyc +0 -0
- videollama2/lib/python3.10/site-packages/sentry_sdk/integrations/__pycache__/socket.cpython-310.pyc +0 -0
- videollama2/lib/python3.10/site-packages/sentry_sdk/integrations/__pycache__/sqlalchemy.cpython-310.pyc +0 -0
- videollama2/lib/python3.10/site-packages/sentry_sdk/integrations/__pycache__/starlette.cpython-310.pyc +0 -0
- videollama2/lib/python3.10/site-packages/sentry_sdk/integrations/__pycache__/starlite.cpython-310.pyc +0 -0
- videollama2/lib/python3.10/site-packages/sentry_sdk/integrations/__pycache__/stdlib.cpython-310.pyc +0 -0
- videollama2/lib/python3.10/site-packages/sentry_sdk/integrations/__pycache__/threading.cpython-310.pyc +0 -0
- videollama2/lib/python3.10/site-packages/sentry_sdk/integrations/__pycache__/tornado.cpython-310.pyc +0 -0
- videollama2/lib/python3.10/site-packages/sentry_sdk/integrations/__pycache__/wsgi.cpython-310.pyc +0 -0
- videollama2/lib/python3.10/site-packages/sentry_sdk/integrations/celery/__init__.py +514 -0
- videollama2/lib/python3.10/site-packages/sentry_sdk/integrations/django/__init__.py +737 -0
- videollama2/lib/python3.10/site-packages/sentry_sdk/integrations/django/__pycache__/caching.cpython-310.pyc +0 -0
- videollama2/lib/python3.10/site-packages/sentry_sdk/integrations/django/asgi.py +237 -0
- videollama2/lib/python3.10/site-packages/sentry_sdk/integrations/django/caching.py +180 -0
- videollama2/lib/python3.10/site-packages/sentry_sdk/integrations/django/templates.py +187 -0
- videollama2/lib/python3.10/site-packages/sentry_sdk/integrations/django/transactions.py +159 -0
videollama2/lib/python3.10/site-packages/sentry_sdk/integrations/__pycache__/__init__.cpython-310.pyc
ADDED
|
Binary file (7.02 kB). View file
|
|
|
videollama2/lib/python3.10/site-packages/sentry_sdk/integrations/__pycache__/_wsgi_common.cpython-310.pyc
ADDED
|
Binary file (5.13 kB). View file
|
|
|
videollama2/lib/python3.10/site-packages/sentry_sdk/integrations/__pycache__/anthropic.cpython-310.pyc
ADDED
|
Binary file (4.73 kB). View file
|
|
|
videollama2/lib/python3.10/site-packages/sentry_sdk/integrations/__pycache__/argv.cpython-310.pyc
ADDED
|
Binary file (1.13 kB). View file
|
|
|
videollama2/lib/python3.10/site-packages/sentry_sdk/integrations/__pycache__/arq.cpython-310.pyc
ADDED
|
Binary file (6.64 kB). View file
|
|
|
videollama2/lib/python3.10/site-packages/sentry_sdk/integrations/__pycache__/asgi.cpython-310.pyc
ADDED
|
Binary file (7.54 kB). View file
|
|
|
videollama2/lib/python3.10/site-packages/sentry_sdk/integrations/__pycache__/asyncio.cpython-310.pyc
ADDED
|
Binary file (2.74 kB). View file
|
|
|
videollama2/lib/python3.10/site-packages/sentry_sdk/integrations/__pycache__/asyncpg.cpython-310.pyc
ADDED
|
Binary file (5.83 kB). View file
|
|
|
videollama2/lib/python3.10/site-packages/sentry_sdk/integrations/__pycache__/aws_lambda.cpython-310.pyc
ADDED
|
Binary file (9.02 kB). View file
|
|
|
videollama2/lib/python3.10/site-packages/sentry_sdk/integrations/__pycache__/beam.cpython-310.pyc
ADDED
|
Binary file (4.13 kB). View file
|
|
|
videollama2/lib/python3.10/site-packages/sentry_sdk/integrations/__pycache__/bottle.cpython-310.pyc
ADDED
|
Binary file (5.72 kB). View file
|
|
|
videollama2/lib/python3.10/site-packages/sentry_sdk/integrations/__pycache__/clickhouse_driver.cpython-310.pyc
ADDED
|
Binary file (4.44 kB). View file
|
|
|
videollama2/lib/python3.10/site-packages/sentry_sdk/integrations/__pycache__/cloud_resource_context.cpython-310.pyc
ADDED
|
Binary file (5.5 kB). View file
|
|
|
videollama2/lib/python3.10/site-packages/sentry_sdk/integrations/__pycache__/cohere.cpython-310.pyc
ADDED
|
Binary file (6.41 kB). View file
|
|
|
videollama2/lib/python3.10/site-packages/sentry_sdk/integrations/__pycache__/dedupe.cpython-310.pyc
ADDED
|
Binary file (1.4 kB). View file
|
|
|
videollama2/lib/python3.10/site-packages/sentry_sdk/integrations/__pycache__/dramatiq.cpython-310.pyc
ADDED
|
Binary file (5.5 kB). View file
|
|
|
videollama2/lib/python3.10/site-packages/sentry_sdk/integrations/__pycache__/executing.cpython-310.pyc
ADDED
|
Binary file (2.01 kB). View file
|
|
|
videollama2/lib/python3.10/site-packages/sentry_sdk/integrations/__pycache__/falcon.cpython-310.pyc
ADDED
|
Binary file (7.43 kB). View file
|
|
|
videollama2/lib/python3.10/site-packages/sentry_sdk/integrations/__pycache__/flask.cpython-310.pyc
ADDED
|
Binary file (6.78 kB). View file
|
|
|
videollama2/lib/python3.10/site-packages/sentry_sdk/integrations/__pycache__/gcp.cpython-310.pyc
ADDED
|
Binary file (6.11 kB). View file
|
|
|
videollama2/lib/python3.10/site-packages/sentry_sdk/integrations/__pycache__/gnu_backtrace.cpython-310.pyc
ADDED
|
Binary file (2.6 kB). View file
|
|
|
videollama2/lib/python3.10/site-packages/sentry_sdk/integrations/__pycache__/gql.cpython-310.pyc
ADDED
|
Binary file (3.98 kB). View file
|
|
|
videollama2/lib/python3.10/site-packages/sentry_sdk/integrations/__pycache__/graphene.cpython-310.pyc
ADDED
|
Binary file (4.14 kB). View file
|
|
|
videollama2/lib/python3.10/site-packages/sentry_sdk/integrations/__pycache__/httpx.cpython-310.pyc
ADDED
|
Binary file (3.72 kB). View file
|
|
|
videollama2/lib/python3.10/site-packages/sentry_sdk/integrations/__pycache__/huggingface_hub.cpython-310.pyc
ADDED
|
Binary file (4.5 kB). View file
|
|
|
videollama2/lib/python3.10/site-packages/sentry_sdk/integrations/__pycache__/langchain.cpython-310.pyc
ADDED
|
Binary file (13.1 kB). View file
|
|
|
videollama2/lib/python3.10/site-packages/sentry_sdk/integrations/__pycache__/litestar.cpython-310.pyc
ADDED
|
Binary file (7.96 kB). View file
|
|
|
videollama2/lib/python3.10/site-packages/sentry_sdk/integrations/__pycache__/logging.cpython-310.pyc
ADDED
|
Binary file (6.85 kB). View file
|
|
|
videollama2/lib/python3.10/site-packages/sentry_sdk/integrations/__pycache__/loguru.cpython-310.pyc
ADDED
|
Binary file (2.86 kB). View file
|
|
|
videollama2/lib/python3.10/site-packages/sentry_sdk/integrations/__pycache__/openai.cpython-310.pyc
ADDED
|
Binary file (6.69 kB). View file
|
|
|
videollama2/lib/python3.10/site-packages/sentry_sdk/integrations/__pycache__/pure_eval.cpython-310.pyc
ADDED
|
Binary file (3.99 kB). View file
|
|
|
videollama2/lib/python3.10/site-packages/sentry_sdk/integrations/__pycache__/pymongo.cpython-310.pyc
ADDED
|
Binary file (4.71 kB). View file
|
|
|
videollama2/lib/python3.10/site-packages/sentry_sdk/integrations/__pycache__/pyramid.cpython-310.pyc
ADDED
|
Binary file (6.83 kB). View file
|
|
|
videollama2/lib/python3.10/site-packages/sentry_sdk/integrations/__pycache__/quart.cpython-310.pyc
ADDED
|
Binary file (6.03 kB). View file
|
|
|
videollama2/lib/python3.10/site-packages/sentry_sdk/integrations/__pycache__/sanic.cpython-310.pyc
ADDED
|
Binary file (9.63 kB). View file
|
|
|
videollama2/lib/python3.10/site-packages/sentry_sdk/integrations/__pycache__/socket.cpython-310.pyc
ADDED
|
Binary file (2.63 kB). View file
|
|
|
videollama2/lib/python3.10/site-packages/sentry_sdk/integrations/__pycache__/sqlalchemy.cpython-310.pyc
ADDED
|
Binary file (3.72 kB). View file
|
|
|
videollama2/lib/python3.10/site-packages/sentry_sdk/integrations/__pycache__/starlette.cpython-310.pyc
ADDED
|
Binary file (16.2 kB). View file
|
|
|
videollama2/lib/python3.10/site-packages/sentry_sdk/integrations/__pycache__/starlite.cpython-310.pyc
ADDED
|
Binary file (8.21 kB). View file
|
|
|
videollama2/lib/python3.10/site-packages/sentry_sdk/integrations/__pycache__/stdlib.cpython-310.pyc
ADDED
|
Binary file (6.52 kB). View file
|
|
|
videollama2/lib/python3.10/site-packages/sentry_sdk/integrations/__pycache__/threading.cpython-310.pyc
ADDED
|
Binary file (3.2 kB). View file
|
|
|
videollama2/lib/python3.10/site-packages/sentry_sdk/integrations/__pycache__/tornado.cpython-310.pyc
ADDED
|
Binary file (7.12 kB). View file
|
|
|
videollama2/lib/python3.10/site-packages/sentry_sdk/integrations/__p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
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
import sys
|
| 2 |
+
from collections.abc import Mapping
|
| 3 |
+
from functools import wraps
|
| 4 |
+
|
| 5 |
+
import sentry_sdk
|
| 6 |
+
from sentry_sdk import isolation_scope
|
| 7 |
+
from sentry_sdk.api import continue_trace
|
| 8 |
+
from sentry_sdk.consts import OP, SPANSTATUS, SPANDATA
|
| 9 |
+
from sentry_sdk.integrations import Integration, DidNotEnable
|
| 10 |
+
from sentry_sdk.integrations.celery.beat import (
|
| 11 |
+
_patch_beat_apply_entry,
|
| 12 |
+
_patch_redbeat_maybe_due,
|
| 13 |
+
_setup_celery_beat_signals,
|
| 14 |
+
)
|
| 15 |
+
from sentry_sdk.integrations.celery.utils import _now_seconds_since_epoch
|
| 16 |
+
from sentry_sdk.integrations.logging import ignore_logger
|
| 17 |
+
from sentry_sdk.tracing import BAGGAGE_HEADER_NAME, TRANSACTION_SOURCE_TASK
|
| 18 |
+
from sentry_sdk._types import TYPE_CHECKING
|
| 19 |
+
from sentry_sdk.tracing_utils import Baggage
|
| 20 |
+
from sentry_sdk.utils import (
|
| 21 |
+
capture_internal_exceptions,
|
| 22 |
+
ensure_integration_enabled,
|
| 23 |
+
event_from_exception,
|
| 24 |
+
reraise,
|
| 25 |
+
)
|
| 26 |
+
|
| 27 |
+
if TYPE_CHECKING:
|
| 28 |
+
from typing import Any
|
| 29 |
+
from typing import Callable
|
| 30 |
+
from typing import List
|
| 31 |
+
from typing import Optional
|
| 32 |
+
from typing import TypeVar
|
| 33 |
+
from typing import Union
|
| 34 |
+
|
| 35 |
+
from sentry_sdk._types import EventProcessor, Event, Hint, ExcInfo
|
| 36 |
+
from sentry_sdk.tracing import Span
|
| 37 |
+
|
| 38 |
+
F = TypeVar("F", bound=Callable[..., Any])
|
| 39 |
+
|
| 40 |
+
|
| 41 |
+
try:
|
| 42 |
+
from celery import VERSION as CELERY_VERSION # type: ignore
|
| 43 |
+
from celery.app.trace import task_has_custom
|
| 44 |
+
from celery.exceptions import ( # type: ignore
|
| 45 |
+
Ignore,
|
| 46 |
+
Reject,
|
| 47 |
+
Retry,
|
| 48 |
+
SoftTimeLimitExceeded,
|
| 49 |
+
)
|
| 50 |
+
from kombu import Producer # type: ignore
|
| 51 |
+
except ImportError:
|
| 52 |
+
raise DidNotEnable("Celery not installed")
|
| 53 |
+
|
| 54 |
+
|
| 55 |
+
CELERY_CONTROL_FLOW_EXCEPTIONS = (Retry, Ignore, Reject)
|
| 56 |
+
|
| 57 |
+
|
| 58 |
+
class CeleryIntegration(Integration):
|
| 59 |
+
identifier = "celery"
|
| 60 |
+
origin = f"auto.queue.{identifier}"
|
| 61 |
+
|
| 62 |
+
def __init__(
|
| 63 |
+
self,
|
| 64 |
+
propagate_traces=True,
|
| 65 |
+
monitor_beat_tasks=False,
|
| 66 |
+
exclude_beat_tasks=None,
|
| 67 |
+
):
|
| 68 |
+
# type: (bool, bool, Optional[List[str]]) -> None
|
| 69 |
+
self.propagate_traces = propagate_traces
|
| 70 |
+
self.monitor_beat_tasks = monitor_beat_tasks
|
| 71 |
+
self.exclude_beat_tasks = exclude_beat_tasks
|
| 72 |
+
|
| 73 |
+
_patch_beat_apply_entry()
|
| 74 |
+
_patch_redbeat_maybe_due()
|
| 75 |
+
_setup_celery_beat_signals(monitor_beat_tasks)
|
| 76 |
+
|
| 77 |
+
@staticmethod
|
| 78 |
+
def setup_once():
|
| 79 |
+
# type: () -> None
|
| 80 |
+
if CELERY_VERSION < (4, 4, 7):
|
| 81 |
+
raise DidNotEnable("Celery 4.4.7 or newer required.")
|
| 82 |
+
|
| 83 |
+
_patch_build_tracer()
|
| 84 |
+
_patch_task_apply_async()
|
| 85 |
+
_patch_worker_exit()
|
| 86 |
+
_patch_producer_publish()
|
| 87 |
+
|
| 88 |
+
# This logger logs every status of every task that ran on the worker.
|
| 89 |
+
# Meaning that every task's breadcrumbs are full of stuff like "Task
|
| 90 |
+
# <foo> raised unexpected <bar>".
|
| 91 |
+
ignore_logger("celery.worker.job")
|
| 92 |
+
ignore_logger("celery.app.trace")
|
| 93 |
+
|
| 94 |
+
# This is stdout/err redirected to a logger, can't deal with this
|
| 95 |
+
# (need event_level=logging.WARN to reproduce)
|
| 96 |
+
ignore_logger("celery.redirected")
|
| 97 |
+
|
| 98 |
+
|
| 99 |
+
def _set_status(status):
|
| 100 |
+
# type: (str) -> None
|
| 101 |
+
with capture_internal_exceptions():
|
| 102 |
+
scope = sentry_sdk.get_current_scope()
|
| 103 |
+
if scope.span is not None:
|
| 104 |
+
scope.span.set_status(status)
|
| 105 |
+
|
| 106 |
+
|
| 107 |
+
def _capture_exception(task, exc_info):
|
| 108 |
+
# type: (Any, ExcInfo) -> None
|
| 109 |
+
client = sentry_sdk.get_client()
|
| 110 |
+
if client.get_integration(CeleryIntegration) is None:
|
| 111 |
+
return
|
| 112 |
+
|
| 113 |
+
if isinstance(exc_info[1], CELERY_CONTROL_FLOW_EXCEPTIONS):
|
| 114 |
+
# ??? Doesn't map to anything
|
| 115 |
+
_set_status("aborted")
|
| 116 |
+
return
|
| 117 |
+
|
| 118 |
+
_set_status("internal_error")
|
| 119 |
+
|
| 120 |
+
if hasattr(task, "throws") and isinstance(exc_info[1], task.throws):
|
| 121 |
+
return
|
| 122 |
+
|
| 123 |
+
event, hint = event_from_exception(
|
| 124 |
+
exc_info,
|
| 125 |
+
client_options=client.options,
|
| 126 |
+
mechanism={"type": "celery", "handled": False},
|
| 127 |
+
)
|
| 128 |
+
|
| 129 |
+
sentry_sdk.capture_event(event, hint=hint)
|
| 130 |
+
|
| 131 |
+
|
| 132 |
+
def _make_event_processor(task, uuid, args, kwargs, request=None):
|
| 133 |
+
# type: (Any, Any, Any, Any, Optional[Any]) -> EventProcessor
|
| 134 |
+
def event_processor(event, hint):
|
| 135 |
+
# type: (Event, Hint) -> Optional[Event]
|
| 136 |
+
|
| 137 |
+
with capture_internal_exceptions():
|
| 138 |
+
tags = event.setdefault("tags", {})
|
| 139 |
+
tags["celery_task_id"] = uuid
|
| 140 |
+
extra = event.setdefault("extra", {})
|
| 141 |
+
extra["celery-job"] = {
|
| 142 |
+
"task_name": task.name,
|
| 143 |
+
"args": args,
|
| 144 |
+
"kwargs": kwargs,
|
| 145 |
+
}
|
| 146 |
+
|
| 147 |
+
if "exc_info" in hint:
|
| 148 |
+
with capture_internal_exceptions():
|
| 149 |
+
if issubclass(hint["exc_info"][0], SoftTimeLimitExceeded):
|
| 150 |
+
event["fingerprint"] = [
|
| 151 |
+
"celery",
|
| 152 |
+
"SoftTimeLimitExceeded",
|
| 153 |
+
getattr(task, "name", task),
|
| 154 |
+
]
|
| 155 |
+
|
| 156 |
+
return event
|
| 157 |
+
|
| 158 |
+
return event_processor
|
| 159 |
+
|
| 160 |
+
|
| 161 |
+
def _update_celery_task_headers(original_headers, span, monitor_beat_tasks):
|
| 162 |
+
# type: (dict[str, Any], Optional[Span], bool) -> dict[str, Any]
|
| 163 |
+
"""
|
| 164 |
+
Updates the headers of the Celery task with the tracing information
|
| 165 |
+
and eventually Sentry Crons monitoring information for beat tasks.
|
| 166 |
+
"""
|
| 167 |
+
updated_headers = original_headers.copy()
|
| 168 |
+
with capture_internal_exceptions():
|
| 169 |
+
# if span is None (when the task was started by Celery Beat)
|
| 170 |
+
# this will return the trace headers from the scope.
|
| 171 |
+
headers = dict(
|
| 172 |
+
sentry_sdk.get_isolation_scope().iter_trace_propagation_headers(span=span)
|
| 173 |
+
)
|
| 174 |
+
|
| 175 |
+
if monitor_beat_tasks:
|
| 176 |
+
headers.update(
|
| 177 |
+
{
|
| 178 |
+
"sentry-monitor-start-timestamp-s": "%.9f"
|
| 179 |
+
% _now_seconds_since_epoch(),
|
| 180 |
+
}
|
| 181 |
+
)
|
| 182 |
+
|
| 183 |
+
# Add the time the task was enqueued to the headers
|
| 184 |
+
# This is used in the consumer to calculate the latency
|
| 185 |
+
updated_headers.update(
|
| 186 |
+
{"sentry-task-enqueued-time": _now_seconds_since_epoch()}
|
| 187 |
+
)
|
| 188 |
+
|
| 189 |
+
if headers:
|
| 190 |
+
existing_baggage = updated_headers.get(BAGGAGE_HEADER_NAME)
|
| 191 |
+
sentry_baggage = headers.get(BAGGAGE_HEADER_NAME)
|
| 192 |
+
|
| 193 |
+
combined_baggage = sentry_baggage or existing_baggage
|
| 194 |
+
if sentry_baggage and existing_baggage:
|
| 195 |
+
# Merge incoming and sentry baggage, where the sentry trace information
|
| 196 |
+
# in the incoming baggage takes precedence and the third-party items
|
| 197 |
+
# are concatenated.
|
| 198 |
+
incoming = Baggage.from_incoming_header(existing_baggage)
|
| 199 |
+
combined = Baggage.from_incoming_header(sentry_baggage)
|
| 200 |
+
combined.sentry_items.update(incoming.sentry_items)
|
| 201 |
+
combined.third_party_items = ",".join(
|
| 202 |
+
[
|
| 203 |
+
x
|
| 204 |
+
for x in [
|
| 205 |
+
combined.third_party_items,
|
| 206 |
+
incoming.third_party_items,
|
| 207 |
+
]
|
| 208 |
+
if x is not None and x != ""
|
| 209 |
+
]
|
| 210 |
+
)
|
| 211 |
+
combined_baggage = combined.serialize(include_third_party=True)
|
| 212 |
+
|
| 213 |
+
updated_headers.update(headers)
|
| 214 |
+
if combined_baggage:
|
| 215 |
+
updated_headers[BAGGAGE_HEADER_NAME] = combined_baggage
|
| 216 |
+
|
| 217 |
+
# https://github.com/celery/celery/issues/4875
|
| 218 |
+
#
|
| 219 |
+
# Need to setdefault the inner headers too since other
|
| 220 |
+
# tracing tools (dd-trace-py) also employ this exact
|
| 221 |
+
# workaround and we don't want to break them.
|
| 222 |
+
updated_headers.setdefault("headers", {}).update(headers)
|
| 223 |
+
if combined_baggage:
|
| 224 |
+
updated_headers["headers"][BAGGAGE_HEADER_NAME] = combined_baggage
|
| 225 |
+
|
| 226 |
+
# Add the Sentry options potentially added in `sentry_apply_entry`
|
| 227 |
+
# to the headers (done when auto-instrumenting Celery Beat tasks)
|
| 228 |
+
for key, value in updated_headers.items():
|
| 229 |
+
if key.startswith("sentry-"):
|
| 230 |
+
updated_headers["headers"][key] = value
|
| 231 |
+
|
| 232 |
+
return updated_headers
|
| 233 |
+
|
| 234 |
+
|
| 235 |
+
class NoOpMgr:
|
| 236 |
+
def __enter__(self):
|
| 237 |
+
# type: () -> None
|
| 238 |
+
return None
|
| 239 |
+
|
| 240 |
+
def __exit__(self, exc_type, exc_value, traceback):
|
| 241 |
+
# type: (Any, Any, Any) -> None
|
| 242 |
+
return None
|
| 243 |
+
|
| 244 |
+
|
| 245 |
+
def _wrap_apply_async(f):
|
| 246 |
+
# type: (F) -> F
|
| 247 |
+
@wraps(f)
|
| 248 |
+
@ensure_integration_enabled(CeleryIntegration, f)
|
| 249 |
+
def apply_async(*args, **kwargs):
|
| 250 |
+
# type: (*Any, **Any) -> Any
|
| 251 |
+
# Note: kwargs can contain headers=None, so no setdefault!
|
| 252 |
+
# Unsure which backend though.
|
| 253 |
+
kwarg_headers = kwargs.get("headers") or {}
|
| 254 |
+
integration = sentry_sdk.get_client().get_integration(CeleryIntegration)
|
| 255 |
+
propagate_traces = kwarg_headers.pop(
|
| 256 |
+
"sentry-propagate-traces", integration.propagate_traces
|
| 257 |
+
)
|
| 258 |
+
|
| 259 |
+
if not propagate_traces:
|
| 260 |
+
return f(*args, **kwargs)
|
| 261 |
+
|
| 262 |
+
task = args[0]
|
| 263 |
+
|
| 264 |
+
task_started_from_beat = sentry_sdk.get_isolation_scope()._name == "celery-beat"
|
| 265 |
+
|
| 266 |
+
span_mgr = (
|
| 267 |
+
sentry_sdk.start_span(
|
| 268 |
+
op=OP.QUEUE_SUBMIT_CELERY,
|
| 269 |
+
description=task.name,
|
| 270 |
+
origin=CeleryIntegration.origin,
|
| 271 |
+
)
|
| 272 |
+
if not task_started_from_beat
|
| 273 |
+
else NoOpMgr()
|
| 274 |
+
) # type: Union[Span, NoOpMgr]
|
| 275 |
+
|
| 276 |
+
with span_mgr as span:
|
| 277 |
+
kwargs["headers"] = _update_celery_task_headers(
|
| 278 |
+
kwarg_headers, span, integration.monitor_beat_tasks
|
| 279 |
+
)
|
| 280 |
+
return f(*args, **kwargs)
|
| 281 |
+
|
| 282 |
+
return apply_async # type: ignore
|
| 283 |
+
|
| 284 |
+
|
| 285 |
+
def _wrap_tracer(task, f):
|
| 286 |
+
# type: (Any, F) -> F
|
| 287 |
+
|
| 288 |
+
# Need to wrap tracer for pushing the scope before prerun is sent, and
|
| 289 |
+
# popping it after postrun is sent.
|
| 290 |
+
#
|
| 291 |
+
# This is the reason we don't use signals for hooking in the first place.
|
| 292 |
+
# Also because in Celery 3, signal dispatch returns early if one handler
|
| 293 |
+
# crashes.
|
| 294 |
+
@wraps(f)
|
| 295 |
+
@ensure_integration_enabled(CeleryIntegration, f)
|
| 296 |
+
def _inner(*args, **kwargs):
|
| 297 |
+
# type: (*Any, **Any) -> Any
|
| 298 |
+
with isolation_scope() as scope:
|
| 299 |
+
scope._name = "celery"
|
| 300 |
+
scope.clear_breadcrumbs()
|
| 301 |
+
scope.add_event_processor(_make_event_processor(task, *args, **kwargs))
|
| 302 |
+
|
| 303 |
+
transaction = None
|
| 304 |
+
|
| 305 |
+
# Celery task objects are not a thing to be trusted. Even
|
| 306 |
+
# something such as attribute access can fail.
|
| 307 |
+
with capture_internal_exceptions():
|
| 308 |
+
headers = args[3].get("headers") or {}
|
| 309 |
+
transaction = continue_trace(
|
| 310 |
+
headers,
|
| 311 |
+
op=OP.QUEUE_TASK_CELERY,
|
| 312 |
+
name="unknown celery task",
|
| 313 |
+
source=TRANSACTION_SOURCE_TASK,
|
| 314 |
+
origin=CeleryIntegration.origin,
|
| 315 |
+
)
|
| 316 |
+
transaction.name = task.name
|
| 317 |
+
transaction.set_status(SPANSTATUS.OK)
|
| 318 |
+
|
| 319 |
+
if transaction is None:
|
| 320 |
+
return f(*args, **kwargs)
|
| 321 |
+
|
| 322 |
+
with sentry_sdk.start_transaction(
|
| 323 |
+
transaction,
|
| 324 |
+
custom_sampling_context={
|
| 325 |
+
"celery_job": {
|
| 326 |
+
"task": task.name,
|
| 327 |
+
# for some reason, args[1] is a list if non-empty but a
|
| 328 |
+
# tuple if empty
|
| 329 |
+
"args": list(args[1]),
|
| 330 |
+
"kwargs": args[2],
|
| 331 |
+
}
|
| 332 |
+
},
|
| 333 |
+
):
|
| 334 |
+
return f(*args, **kwargs)
|
| 335 |
+
|
| 336 |
+
return _inner # type: ignore
|
| 337 |
+
|
| 338 |
+
|
| 339 |
+
def _set_messaging_destination_name(task, span):
|
| 340 |
+
# type: (Any, Span) -> None
|
| 341 |
+
"""Set "messaging.destination.name" tag for span"""
|
| 342 |
+
with capture_internal_exceptions():
|
| 343 |
+
delivery_info = task.request.delivery_info
|
| 344 |
+
if delivery_info:
|
| 345 |
+
routing_key = delivery_info.get("routing_key")
|
| 346 |
+
if delivery_info.get("exchange") == "" and routing_key is not None:
|
| 347 |
+
# Empty exchange indicates the default exchange, meaning the tasks
|
| 348 |
+
# are sent to the queue with the same name as the routing key.
|
| 349 |
+
span.set_data(SPANDATA.MESSAGING_DESTINATION_NAME, routing_key)
|
| 350 |
+
|
| 351 |
+
|
| 352 |
+
def _wrap_task_call(task, f):
|
| 353 |
+
# type: (Any, F) -> F
|
| 354 |
+
|
| 355 |
+
# Need to wrap task call because the exception is caught before we get to
|
| 356 |
+
# see it. Also celery's reported stacktrace is untrustworthy.
|
| 357 |
+
|
| 358 |
+
# functools.wraps is important here because celery-once looks at this
|
| 359 |
+
# method's name. @ensure_integration_enabled internally calls functools.wraps,
|
| 360 |
+
# but if we ever remove the @ensure_integration_enabled decorator, we need
|
| 361 |
+
# to add @functools.wraps(f) here.
|
| 362 |
+
# https://github.com/getsentry/sentry-python/issues/421
|
| 363 |
+
@ensure_integration_enabled(CeleryIntegration, f)
|
| 364 |
+
def _inner(*args, **kwargs):
|
| 365 |
+
# type: (*Any, **Any) -> Any
|
| 366 |
+
try:
|
| 367 |
+
with sentry_sdk.start_span(
|
| 368 |
+
op=OP.QUEUE_PROCESS,
|
| 369 |
+
description=task.name,
|
| 370 |
+
origin=CeleryIntegration.origin,
|
| 371 |
+
) as span:
|
| 372 |
+
_set_messaging_destination_name(task, span)
|
| 373 |
+
|
| 374 |
+
latency = None
|
| 375 |
+
with capture_internal_exceptions():
|
| 376 |
+
if (
|
| 377 |
+
task.request.headers is not None
|
| 378 |
+
and "sentry-task-enqueued-time" in task.request.headers
|
| 379 |
+
):
|
| 380 |
+
latency = _now_seconds_since_epoch() - task.request.headers.pop(
|
| 381 |
+
"sentry-task-enqueued-time"
|
| 382 |
+
)
|
| 383 |
+
|
| 384 |
+
if latency is not None:
|
| 385 |
+
span.set_data(SPANDATA.MESSAGING_MESSAGE_RECEIVE_LATENCY, latency)
|
| 386 |
+
|
| 387 |
+
with capture_internal_exceptions():
|
| 388 |
+
span.set_data(SPANDATA.MESSAGING_MESSAGE_ID, task.request.id)
|
| 389 |
+
|
| 390 |
+
with capture_internal_exceptions():
|
| 391 |
+
span.set_data(
|
| 392 |
+
SPANDATA.MESSAGING_MESSAGE_RETRY_COUNT, task.request.retries
|
| 393 |
+
)
|
| 394 |
+
|
| 395 |
+
with capture_internal_exceptions():
|
| 396 |
+
span.set_data(
|
| 397 |
+
SPANDATA.MESSAGING_SYSTEM,
|
| 398 |
+
task.app.connection().transport.driver_type,
|
| 399 |
+
)
|
| 400 |
+
|
| 401 |
+
return f(*args, **kwargs)
|
| 402 |
+
except Exception:
|
| 403 |
+
exc_info = sys.exc_info()
|
| 404 |
+
with capture_internal_exceptions():
|
| 405 |
+
_capture_exception(task, exc_info)
|
| 406 |
+
reraise(*exc_info)
|
| 407 |
+
|
| 408 |
+
return _inner # type: ignore
|
| 409 |
+
|
| 410 |
+
|
| 411 |
+
def _patch_build_tracer():
|
| 412 |
+
# type: () -> None
|
| 413 |
+
import celery.app.trace as trace # type: ignore
|
| 414 |
+
|
| 415 |
+
original_build_tracer = trace.build_tracer
|
| 416 |
+
|
| 417 |
+
def sentry_build_tracer(name, task, *args, **kwargs):
|
| 418 |
+
# type: (Any, Any, *Any, **Any) -> Any
|
| 419 |
+
if not getattr(task, "_sentry_is_patched", False):
|
| 420 |
+
# determine whether Celery will use __call__ or run and patch
|
| 421 |
+
# accordingly
|
| 422 |
+
if task_has_custom(task, "__call__"):
|
| 423 |
+
type(task).__call__ = _wrap_task_call(task, type(task).__call__)
|
| 424 |
+
else:
|
| 425 |
+
task.run = _wrap_task_call(task, task.run)
|
| 426 |
+
|
| 427 |
+
# `build_tracer` is apparently called for every task
|
| 428 |
+
# invocation. Can't wrap every celery task for every invocation
|
| 429 |
+
# or we will get infinitely nested wrapper functions.
|
| 430 |
+
task._sentry_is_patched = True
|
| 431 |
+
|
| 432 |
+
return _wrap_tracer(task, original_build_tracer(name, task, *args, **kwargs))
|
| 433 |
+
|
| 434 |
+
trace.build_tracer = sentry_build_tracer
|
| 435 |
+
|
| 436 |
+
|
| 437 |
+
def _patch_task_apply_async():
|
| 438 |
+
# type: () -> None
|
| 439 |
+
from celery.app.task import Task # type: ignore
|
| 440 |
+
|
| 441 |
+
Task.apply_async = _wrap_apply_async(Task.apply_async)
|
| 442 |
+
|
| 443 |
+
|
| 444 |
+
def _patch_worker_exit():
|
| 445 |
+
# type: () -> None
|
| 446 |
+
|
| 447 |
+
# Need to flush queue before worker shutdown because a crashing worker will
|
| 448 |
+
# call os._exit
|
| 449 |
+
from billiard.pool import Worker # type: ignore
|
| 450 |
+
|
| 451 |
+
original_workloop = Worker.workloop
|
| 452 |
+
|
| 453 |
+
def sentry_workloop(*args, **kwargs):
|
| 454 |
+
# type: (*Any, **Any) -> Any
|
| 455 |
+
try:
|
| 456 |
+
return original_workloop(*args, **kwargs)
|
| 457 |
+
finally:
|
| 458 |
+
with capture_internal_exceptions():
|
| 459 |
+
if (
|
| 460 |
+
sentry_sdk.get_client().get_integration(CeleryIntegration)
|
| 461 |
+
is not None
|
| 462 |
+
):
|
| 463 |
+
sentry_sdk.flush()
|
| 464 |
+
|
| 465 |
+
Worker.workloop = sentry_workloop
|
| 466 |
+
|
| 467 |
+
|
| 468 |
+
def _patch_producer_publish():
|
| 469 |
+
# type: () -> None
|
| 470 |
+
original_publish = Producer.publish
|
| 471 |
+
|
| 472 |
+
@ensure_integration_enabled(CeleryIntegration, original_publish)
|
| 473 |
+
def sentry_publish(self, *args, **kwargs):
|
| 474 |
+
# type: (Producer, *Any, **Any) -> Any
|
| 475 |
+
kwargs_headers = kwargs.get("headers", {})
|
| 476 |
+
if not isinstance(kwargs_headers, Mapping):
|
| 477 |
+
# Ensure kwargs_headers is a Mapping, so we can safely call get().
|
| 478 |
+
# We don't expect this to happen, but it's better to be safe. Even
|
| 479 |
+
# if it does happen, only our instrumentation breaks. This line
|
| 480 |
+
# does not overwrite kwargs["headers"], so the original publish
|
| 481 |
+
# method will still work.
|
| 482 |
+
kwargs_headers = {}
|
| 483 |
+
|
| 484 |
+
task_name = kwargs_headers.get("task")
|
| 485 |
+
task_id = kwargs_headers.get("id")
|
| 486 |
+
retries = kwargs_headers.get("retries")
|
| 487 |
+
|
| 488 |
+
routing_key = kwargs.get("routing_key")
|
| 489 |
+
exchange = kwargs.get("exchange")
|
| 490 |
+
|
| 491 |
+
with sentry_sdk.start_span(
|
| 492 |
+
op=OP.QUEUE_PUBLISH,
|
| 493 |
+
description=task_name,
|
| 494 |
+
origin=CeleryIntegration.origin,
|
| 495 |
+
) as span:
|
| 496 |
+
if task_id is not None:
|
| 497 |
+
span.set_data(SPANDATA.MESSAGING_MESSAGE_ID, task_id)
|
| 498 |
+
|
| 499 |
+
if exchange == "" and routing_key is not None:
|
| 500 |
+
# Empty exchange indicates the default exchange, meaning messages are
|
| 501 |
+
# routed to the queue with the same name as the routing key.
|
| 502 |
+
span.set_data(SPANDATA.MESSAGING_DESTINATION_NAME, routing_key)
|
| 503 |
+
|
| 504 |
+
if retries is not None:
|
| 505 |
+
span.set_data(SPANDATA.MESSAGING_MESSAGE_RETRY_COUNT, retries)
|
| 506 |
+
|
| 507 |
+
with capture_internal_exceptions():
|
| 508 |
+
span.set_data(
|
| 509 |
+
SPANDATA.MESSAGING_SYSTEM, self.connection.transport.driver_type
|
| 510 |
+
)
|
| 511 |
+
|
| 512 |
+
return original_publish(self, *args, **kwargs)
|
| 513 |
+
|
| 514 |
+
Producer.publish = sentry_publish
|
videollama2/lib/python3.10/site-packages/sentry_sdk/integrations/django/__init__.py
ADDED
|
@@ -0,0 +1,737 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|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
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
import inspect
|
| 2 |
+
import sys
|
| 3 |
+
import threading
|
| 4 |
+
import weakref
|
| 5 |
+
from importlib import import_module
|
| 6 |
+
|
| 7 |
+
import sentry_sdk
|
| 8 |
+
from sentry_sdk._types import TYPE_CHECKING
|
| 9 |
+
from sentry_sdk.consts import OP, SPANDATA
|
| 10 |
+
from sentry_sdk.db.explain_plan.django import attach_explain_plan_to_span
|
| 11 |
+
from sentry_sdk.scope import add_global_event_processor, should_send_default_pii
|
| 12 |
+
from sentry_sdk.serializer import add_global_repr_processor
|
| 13 |
+
from sentry_sdk.tracing import SOURCE_FOR_STYLE, TRANSACTION_SOURCE_URL
|
| 14 |
+
from sentry_sdk.tracing_utils import add_query_source, record_sql_queries
|
| 15 |
+
from sentry_sdk.utils import (
|
| 16 |
+
AnnotatedValue,
|
| 17 |
+
HAS_REAL_CONTEXTVARS,
|
| 18 |
+
CONTEXTVARS_ERROR_MESSAGE,
|
| 19 |
+
SENSITIVE_DATA_SUBSTITUTE,
|
| 20 |
+
logger,
|
| 21 |
+
capture_internal_exceptions,
|
| 22 |
+
ensure_integration_enabled,
|
| 23 |
+
event_from_exception,
|
| 24 |
+
transaction_from_function,
|
| 25 |
+
walk_exception_chain,
|
| 26 |
+
)
|
| 27 |
+
from sentry_sdk.integrations import Integration, DidNotEnable
|
| 28 |
+
from sentry_sdk.integrations.logging import ignore_logger
|
| 29 |
+
from sentry_sdk.integrations.wsgi import SentryWsgiMiddleware
|
| 30 |
+
from sentry_sdk.integrations._wsgi_common import RequestExtractor
|
| 31 |
+
|
| 32 |
+
try:
|
| 33 |
+
from django import VERSION as DJANGO_VERSION
|
| 34 |
+
from django.conf import settings as django_settings
|
| 35 |
+
from django.core import signals
|
| 36 |
+
from django.conf import settings
|
| 37 |
+
|
| 38 |
+
try:
|
| 39 |
+
from django.urls import resolve
|
| 40 |
+
except ImportError:
|
| 41 |
+
from django.core.urlresolvers import resolve
|
| 42 |
+
|
| 43 |
+
try:
|
| 44 |
+
from django.urls import Resolver404
|
| 45 |
+
except ImportError:
|
| 46 |
+
from django.core.urlresolvers import Resolver404
|
| 47 |
+
|
| 48 |
+
# Only available in Django 3.0+
|
| 49 |
+
try:
|
| 50 |
+
from django.core.handlers.asgi import ASGIRequest
|
| 51 |
+
except Exception:
|
| 52 |
+
ASGIRequest = None
|
| 53 |
+
|
| 54 |
+
except ImportError:
|
| 55 |
+
raise DidNotEnable("Django not installed")
|
| 56 |
+
|
| 57 |
+
from sentry_sdk.integrations.django.transactions import LEGACY_RESOLVER
|
| 58 |
+
from sentry_sdk.integrations.django.templates import (
|
| 59 |
+
get_template_frame_from_exception,
|
| 60 |
+
patch_templates,
|
| 61 |
+
)
|
| 62 |
+
from sentry_sdk.integrations.django.middleware import patch_django_middlewares
|
| 63 |
+
from sentry_sdk.integrations.django.signals_handlers import patch_signals
|
| 64 |
+
from sentry_sdk.integrations.django.views import patch_views
|
| 65 |
+
|
| 66 |
+
if DJANGO_VERSION[:2] > (1, 8):
|
| 67 |
+
from sentry_sdk.integrations.django.caching import patch_caching
|
| 68 |
+
else:
|
| 69 |
+
patch_caching = None # type: ignore
|
| 70 |
+
|
| 71 |
+
|
| 72 |
+
if TYPE_CHECKING:
|
| 73 |
+
from typing import Any
|
| 74 |
+
from typing import Callable
|
| 75 |
+
from typing import Dict
|
| 76 |
+
from typing import Optional
|
| 77 |
+
from typing import Union
|
| 78 |
+
from typing import List
|
| 79 |
+
|
| 80 |
+
from django.core.handlers.wsgi import WSGIRequest
|
| 81 |
+
from django.http.response import HttpResponse
|
| 82 |
+
from django.http.request import QueryDict
|
| 83 |
+
from django.utils.datastructures import MultiValueDict
|
| 84 |
+
|
| 85 |
+
from sentry_sdk.tracing import Span
|
| 86 |
+
from sentry_sdk.integrations.wsgi import _ScopedResponse
|
| 87 |
+
from sentry_sdk._types import Event, Hint, EventProcessor, NotImplementedType
|
| 88 |
+
|
| 89 |
+
|
| 90 |
+
if DJANGO_VERSION < (1, 10):
|
| 91 |
+
|
| 92 |
+
def is_authenticated(request_user):
|
| 93 |
+
# type: (Any) -> bool
|
| 94 |
+
return request_user.is_authenticated()
|
| 95 |
+
|
| 96 |
+
else:
|
| 97 |
+
|
| 98 |
+
def is_authenticated(request_user):
|
| 99 |
+
# type: (Any) -> bool
|
| 100 |
+
return request_user.is_authenticated
|
| 101 |
+
|
| 102 |
+
|
| 103 |
+
TRANSACTION_STYLE_VALUES = ("function_name", "url")
|
| 104 |
+
|
| 105 |
+
|
| 106 |
+
class DjangoIntegration(Integration):
|
| 107 |
+
"""
|
| 108 |
+
Auto instrument a Django application.
|
| 109 |
+
|
| 110 |
+
:param transaction_style: How to derive transaction names. Either `"function_name"` or `"url"`. Defaults to `"url"`.
|
| 111 |
+
:param middleware_spans: Whether to create spans for middleware. Defaults to `True`.
|
| 112 |
+
:param signals_spans: Whether to create spans for signals. Defaults to `True`.
|
| 113 |
+
:param signals_denylist: A list of signals to ignore when creating spans.
|
| 114 |
+
:param cache_spans: Whether to create spans for cache operations. Defaults to `False`.
|
| 115 |
+
"""
|
| 116 |
+
|
| 117 |
+
identifier = "django"
|
| 118 |
+
origin = f"auto.http.{identifier}"
|
| 119 |
+
origin_db = f"auto.db.{identifier}"
|
| 120 |
+
|
| 121 |
+
transaction_style = ""
|
| 122 |
+
middleware_spans = None
|
| 123 |
+
signals_spans = None
|
| 124 |
+
cache_spans = None
|
| 125 |
+
signals_denylist = [] # type: list[signals.Signal]
|
| 126 |
+
|
| 127 |
+
def __init__(
|
| 128 |
+
self,
|
| 129 |
+
transaction_style="url",
|
| 130 |
+
middleware_spans=True,
|
| 131 |
+
signals_spans=True,
|
| 132 |
+
cache_spans=False,
|
| 133 |
+
signals_denylist=None,
|
| 134 |
+
):
|
| 135 |
+
# type: (str, bool, bool, bool, Optional[list[signals.Signal]]) -> None
|
| 136 |
+
if transaction_style not in TRANSACTION_STYLE_VALUES:
|
| 137 |
+
raise ValueError(
|
| 138 |
+
"Invalid value for transaction_style: %s (must be in %s)"
|
| 139 |
+
% (transaction_style, TRANSACTION_STYLE_VALUES)
|
| 140 |
+
)
|
| 141 |
+
self.transaction_style = transaction_style
|
| 142 |
+
self.middleware_spans = middleware_spans
|
| 143 |
+
|
| 144 |
+
self.signals_spans = signals_spans
|
| 145 |
+
self.signals_denylist = signals_denylist or []
|
| 146 |
+
|
| 147 |
+
self.cache_spans = cache_spans
|
| 148 |
+
|
| 149 |
+
@staticmethod
|
| 150 |
+
def setup_once():
|
| 151 |
+
# type: () -> None
|
| 152 |
+
|
| 153 |
+
if DJANGO_VERSION < (1, 8):
|
| 154 |
+
raise DidNotEnable("Django 1.8 or newer is required.")
|
| 155 |
+
|
| 156 |
+
install_sql_hook()
|
| 157 |
+
# Patch in our custom middleware.
|
| 158 |
+
|
| 159 |
+
# logs an error for every 500
|
| 160 |
+
ignore_logger("django.server")
|
| 161 |
+
ignore_logger("django.request")
|
| 162 |
+
|
| 163 |
+
from django.core.handlers.wsgi import WSGIHandler
|
| 164 |
+
|
| 165 |
+
old_app = WSGIHandler.__call__
|
| 166 |
+
|
| 167 |
+
@ensure_integration_enabled(DjangoIntegration, old_app)
|
| 168 |
+
def sentry_patched_wsgi_handler(self, environ, start_response):
|
| 169 |
+
# type: (Any, Dict[str, str], Callable[..., Any]) -> _ScopedResponse
|
| 170 |
+
bound_old_app = old_app.__get__(self, WSGIHandler)
|
| 171 |
+
|
| 172 |
+
from django.conf import settings
|
| 173 |
+
|
| 174 |
+
use_x_forwarded_for = settings.USE_X_FORWARDED_HOST
|
| 175 |
+
|
| 176 |
+
middleware = SentryWsgiMiddleware(
|
| 177 |
+
bound_old_app,
|
| 178 |
+
use_x_forwarded_for,
|
| 179 |
+
span_origin=DjangoIntegration.origin,
|
| 180 |
+
)
|
| 181 |
+
return middleware(environ, start_response)
|
| 182 |
+
|
| 183 |
+
WSGIHandler.__call__ = sentry_patched_wsgi_handler
|
| 184 |
+
|
| 185 |
+
_patch_get_response()
|
| 186 |
+
|
| 187 |
+
_patch_django_asgi_handler()
|
| 188 |
+
|
| 189 |
+
signals.got_request_exception.connect(_got_request_exception)
|
| 190 |
+
|
| 191 |
+
@add_global_event_processor
|
| 192 |
+
def process_django_templates(event, hint):
|
| 193 |
+
# type: (Event, Optional[Hint]) -> Optional[Event]
|
| 194 |
+
if hint is None:
|
| 195 |
+
return event
|
| 196 |
+
|
| 197 |
+
exc_info = hint.get("exc_info", None)
|
| 198 |
+
|
| 199 |
+
if exc_info is None:
|
| 200 |
+
return event
|
| 201 |
+
|
| 202 |
+
exception = event.get("exception", None)
|
| 203 |
+
|
| 204 |
+
if exception is None:
|
| 205 |
+
return event
|
| 206 |
+
|
| 207 |
+
values = exception.get("values", None)
|
| 208 |
+
|
| 209 |
+
if values is None:
|
| 210 |
+
return event
|
| 211 |
+
|
| 212 |
+
for exception, (_, exc_value, _) in zip(
|
| 213 |
+
reversed(values), walk_exception_chain(exc_info)
|
| 214 |
+
):
|
| 215 |
+
frame = get_template_frame_from_exception(exc_value)
|
| 216 |
+
if frame is not None:
|
| 217 |
+
frames = exception.get("stacktrace", {}).get("frames", [])
|
| 218 |
+
|
| 219 |
+
for i in reversed(range(len(frames))):
|
| 220 |
+
f = frames[i]
|
| 221 |
+
if (
|
| 222 |
+
f.get("function") in ("Parser.parse", "parse", "render")
|
| 223 |
+
and f.get("module") == "django.template.base"
|
| 224 |
+
):
|
| 225 |
+
i += 1
|
| 226 |
+
break
|
| 227 |
+
else:
|
| 228 |
+
i = len(frames)
|
| 229 |
+
|
| 230 |
+
frames.insert(i, frame)
|
| 231 |
+
|
| 232 |
+
return event
|
| 233 |
+
|
| 234 |
+
@add_global_repr_processor
|
| 235 |
+
def _django_queryset_repr(value, hint):
|
| 236 |
+
# type: (Any, Dict[str, Any]) -> Union[NotImplementedType, str]
|
| 237 |
+
try:
|
| 238 |
+
# Django 1.6 can fail to import `QuerySet` when Django settings
|
| 239 |
+
# have not yet been initialized.
|
| 240 |
+
#
|
| 241 |
+
# If we fail to import, return `NotImplemented`. It's at least
|
| 242 |
+
# unlikely that we have a query set in `value` when importing
|
| 243 |
+
# `QuerySet` fails.
|
| 244 |
+
from django.db.models.query import QuerySet
|
| 245 |
+
except Exception:
|
| 246 |
+
return NotImplemented
|
| 247 |
+
|
| 248 |
+
if not isinstance(value, QuerySet) or value._result_cache:
|
| 249 |
+
return NotImplemented
|
| 250 |
+
|
| 251 |
+
return "<%s from %s at 0x%x>" % (
|
| 252 |
+
value.__class__.__name__,
|
| 253 |
+
value.__module__,
|
| 254 |
+
id(value),
|
| 255 |
+
)
|
| 256 |
+
|
| 257 |
+
_patch_channels()
|
| 258 |
+
patch_django_middlewares()
|
| 259 |
+
patch_views()
|
| 260 |
+
patch_templates()
|
| 261 |
+
patch_signals()
|
| 262 |
+
|
| 263 |
+
if patch_caching is not None:
|
| 264 |
+
patch_caching()
|
| 265 |
+
|
| 266 |
+
|
| 267 |
+
_DRF_PATCHED = False
|
| 268 |
+
_DRF_PATCH_LOCK = threading.Lock()
|
| 269 |
+
|
| 270 |
+
|
| 271 |
+
def _patch_drf():
|
| 272 |
+
# type: () -> None
|
| 273 |
+
"""
|
| 274 |
+
Patch Django Rest Framework for more/better request data. DRF's request
|
| 275 |
+
type is a wrapper around Django's request type. The attribute we're
|
| 276 |
+
interested in is `request.data`, which is a cached property containing a
|
| 277 |
+
parsed request body. Reading a request body from that property is more
|
| 278 |
+
reliable than reading from any of Django's own properties, as those don't
|
| 279 |
+
hold payloads in memory and therefore can only be accessed once.
|
| 280 |
+
|
| 281 |
+
We patch the Django request object to include a weak backreference to the
|
| 282 |
+
DRF request object, such that we can later use either in
|
| 283 |
+
`DjangoRequestExtractor`.
|
| 284 |
+
|
| 285 |
+
This function is not called directly on SDK setup, because importing almost
|
| 286 |
+
any part of Django Rest Framework will try to access Django settings (where
|
| 287 |
+
`sentry_sdk.init()` might be called from in the first place). Instead we
|
| 288 |
+
run this function on every request and do the patching on the first
|
| 289 |
+
request.
|
| 290 |
+
"""
|
| 291 |
+
|
| 292 |
+
global _DRF_PATCHED
|
| 293 |
+
|
| 294 |
+
if _DRF_PATCHED:
|
| 295 |
+
# Double-checked locking
|
| 296 |
+
return
|
| 297 |
+
|
| 298 |
+
with _DRF_PATCH_LOCK:
|
| 299 |
+
if _DRF_PATCHED:
|
| 300 |
+
return
|
| 301 |
+
|
| 302 |
+
# We set this regardless of whether the code below succeeds or fails.
|
| 303 |
+
# There is no point in trying to patch again on the next request.
|
| 304 |
+
_DRF_PATCHED = True
|
| 305 |
+
|
| 306 |
+
with capture_internal_exceptions():
|
| 307 |
+
try:
|
| 308 |
+
from rest_framework.views import APIView # type: ignore
|
| 309 |
+
except ImportError:
|
| 310 |
+
pass
|
| 311 |
+
else:
|
| 312 |
+
old_drf_initial = APIView.initial
|
| 313 |
+
|
| 314 |
+
def sentry_patched_drf_initial(self, request, *args, **kwargs):
|
| 315 |
+
# type: (APIView, Any, *Any, **Any) -> Any
|
| 316 |
+
with capture_internal_exceptions():
|
| 317 |
+
request._request._sentry_drf_request_backref = weakref.ref(
|
| 318 |
+
request
|
| 319 |
+
)
|
| 320 |
+
pass
|
| 321 |
+
return old_drf_initial(self, request, *args, **kwargs)
|
| 322 |
+
|
| 323 |
+
APIView.initial = sentry_patched_drf_initial
|
| 324 |
+
|
| 325 |
+
|
| 326 |
+
def _patch_channels():
|
| 327 |
+
# type: () -> None
|
| 328 |
+
try:
|
| 329 |
+
from channels.http import AsgiHandler # type: ignore
|
| 330 |
+
except ImportError:
|
| 331 |
+
return
|
| 332 |
+
|
| 333 |
+
if not HAS_REAL_CONTEXTVARS:
|
| 334 |
+
# We better have contextvars or we're going to leak state between
|
| 335 |
+
# requests.
|
| 336 |
+
#
|
| 337 |
+
# We cannot hard-raise here because channels may not be used at all in
|
| 338 |
+
# the current process. That is the case when running traditional WSGI
|
| 339 |
+
# workers in gunicorn+gevent and the websocket stuff in a separate
|
| 340 |
+
# process.
|
| 341 |
+
logger.warning(
|
| 342 |
+
"We detected that you are using Django channels 2.0."
|
| 343 |
+
+ CONTEXTVARS_ERROR_MESSAGE
|
| 344 |
+
)
|
| 345 |
+
|
| 346 |
+
from sentry_sdk.integrations.django.asgi import patch_channels_asgi_handler_impl
|
| 347 |
+
|
| 348 |
+
patch_channels_asgi_handler_impl(AsgiHandler)
|
| 349 |
+
|
| 350 |
+
|
| 351 |
+
def _patch_django_asgi_handler():
|
| 352 |
+
# type: () -> None
|
| 353 |
+
try:
|
| 354 |
+
from django.core.handlers.asgi import ASGIHandler
|
| 355 |
+
except ImportError:
|
| 356 |
+
return
|
| 357 |
+
|
| 358 |
+
if not HAS_REAL_CONTEXTVARS:
|
| 359 |
+
# We better have contextvars or we're going to leak state between
|
| 360 |
+
# requests.
|
| 361 |
+
#
|
| 362 |
+
# We cannot hard-raise here because Django's ASGI stuff may not be used
|
| 363 |
+
# at all.
|
| 364 |
+
logger.warning(
|
| 365 |
+
"We detected that you are using Django 3." + CONTEXTVARS_ERROR_MESSAGE
|
| 366 |
+
)
|
| 367 |
+
|
| 368 |
+
from sentry_sdk.integrations.django.asgi import patch_django_asgi_handler_impl
|
| 369 |
+
|
| 370 |
+
patch_django_asgi_handler_impl(ASGIHandler)
|
| 371 |
+
|
| 372 |
+
|
| 373 |
+
def _set_transaction_name_and_source(scope, transaction_style, request):
|
| 374 |
+
# type: (sentry_sdk.Scope, str, WSGIRequest) -> None
|
| 375 |
+
try:
|
| 376 |
+
transaction_name = None
|
| 377 |
+
if transaction_style == "function_name":
|
| 378 |
+
fn = resolve(request.path).func
|
| 379 |
+
transaction_name = transaction_from_function(getattr(fn, "view_class", fn))
|
| 380 |
+
|
| 381 |
+
elif transaction_style == "url":
|
| 382 |
+
if hasattr(request, "urlconf"):
|
| 383 |
+
transaction_name = LEGACY_RESOLVER.resolve(
|
| 384 |
+
request.path_info, urlconf=request.urlconf
|
| 385 |
+
)
|
| 386 |
+
else:
|
| 387 |
+
transaction_name = LEGACY_RESOLVER.resolve(request.path_info)
|
| 388 |
+
|
| 389 |
+
if transaction_name is None:
|
| 390 |
+
transaction_name = request.path_info
|
| 391 |
+
source = TRANSACTION_SOURCE_URL
|
| 392 |
+
else:
|
| 393 |
+
source = SOURCE_FOR_STYLE[transaction_style]
|
| 394 |
+
|
| 395 |
+
scope.set_transaction_name(
|
| 396 |
+
transaction_name,
|
| 397 |
+
source=source,
|
| 398 |
+
)
|
| 399 |
+
except Resolver404:
|
| 400 |
+
urlconf = import_module(settings.ROOT_URLCONF)
|
| 401 |
+
# This exception only gets thrown when transaction_style is `function_name`
|
| 402 |
+
# So we don't check here what style is configured
|
| 403 |
+
if hasattr(urlconf, "handler404"):
|
| 404 |
+
handler = urlconf.handler404
|
| 405 |
+
if isinstance(handler, str):
|
| 406 |
+
scope.transaction = handler
|
| 407 |
+
else:
|
| 408 |
+
scope.transaction = transaction_from_function(
|
| 409 |
+
getattr(handler, "view_class", handler)
|
| 410 |
+
)
|
| 411 |
+
except Exception:
|
| 412 |
+
pass
|
| 413 |
+
|
| 414 |
+
|
| 415 |
+
@ensure_integration_enabled(DjangoIntegration)
|
| 416 |
+
def _before_get_response(request):
|
| 417 |
+
# type: (WSGIRequest) -> None
|
| 418 |
+
integration = sentry_sdk.get_client().get_integration(DjangoIntegration)
|
| 419 |
+
|
| 420 |
+
_patch_drf()
|
| 421 |
+
|
| 422 |
+
scope = sentry_sdk.get_current_scope()
|
| 423 |
+
# Rely on WSGI middleware to start a trace
|
| 424 |
+
_set_transaction_name_and_source(scope, integration.transaction_style, request)
|
| 425 |
+
|
| 426 |
+
scope.add_event_processor(
|
| 427 |
+
_make_wsgi_request_event_processor(weakref.ref(request), integration)
|
| 428 |
+
)
|
| 429 |
+
|
| 430 |
+
|
| 431 |
+
def _attempt_resolve_again(request, scope, transaction_style):
|
| 432 |
+
# type: (WSGIRequest, sentry_sdk.Scope, str) -> None
|
| 433 |
+
"""
|
| 434 |
+
Some django middlewares overwrite request.urlconf
|
| 435 |
+
so we need to respect that contract,
|
| 436 |
+
so we try to resolve the url again.
|
| 437 |
+
"""
|
| 438 |
+
if not hasattr(request, "urlconf"):
|
| 439 |
+
return
|
| 440 |
+
|
| 441 |
+
_set_transaction_name_and_source(scope, transaction_style, request)
|
| 442 |
+
|
| 443 |
+
|
| 444 |
+
@ensure_integration_enabled(DjangoIntegration)
|
| 445 |
+
def _after_get_response(request):
|
| 446 |
+
# type: (WSGIRequest) -> None
|
| 447 |
+
integration = sentry_sdk.get_client().get_integration(DjangoIntegration)
|
| 448 |
+
if integration.transaction_style != "url":
|
| 449 |
+
return
|
| 450 |
+
|
| 451 |
+
scope = sentry_sdk.get_current_scope()
|
| 452 |
+
_attempt_resolve_again(request, scope, integration.transaction_style)
|
| 453 |
+
|
| 454 |
+
|
| 455 |
+
def _patch_get_response():
|
| 456 |
+
# type: () -> None
|
| 457 |
+
"""
|
| 458 |
+
patch get_response, because at that point we have the Django request object
|
| 459 |
+
"""
|
| 460 |
+
from django.core.handlers.base import BaseHandler
|
| 461 |
+
|
| 462 |
+
old_get_response = BaseHandler.get_response
|
| 463 |
+
|
| 464 |
+
def sentry_patched_get_response(self, request):
|
| 465 |
+
# type: (Any, WSGIRequest) -> Union[HttpResponse, BaseException]
|
| 466 |
+
_before_get_response(request)
|
| 467 |
+
rv = old_get_response(self, request)
|
| 468 |
+
_after_get_response(request)
|
| 469 |
+
return rv
|
| 470 |
+
|
| 471 |
+
BaseHandler.get_response = sentry_patched_get_response
|
| 472 |
+
|
| 473 |
+
if hasattr(BaseHandler, "get_response_async"):
|
| 474 |
+
from sentry_sdk.integrations.django.asgi import patch_get_response_async
|
| 475 |
+
|
| 476 |
+
patch_get_response_async(BaseHandler, _before_get_response)
|
| 477 |
+
|
| 478 |
+
|
| 479 |
+
def _make_wsgi_request_event_processor(weak_request, integration):
|
| 480 |
+
# type: (Callable[[], WSGIRequest], DjangoIntegration) -> EventProcessor
|
| 481 |
+
def wsgi_request_event_processor(event, hint):
|
| 482 |
+
# type: (Event, dict[str, Any]) -> Event
|
| 483 |
+
# if the request is gone we are fine not logging the data from
|
| 484 |
+
# it. This might happen if the processor is pushed away to
|
| 485 |
+
# another thread.
|
| 486 |
+
request = weak_request()
|
| 487 |
+
if request is None:
|
| 488 |
+
return event
|
| 489 |
+
|
| 490 |
+
django_3 = ASGIRequest is not None
|
| 491 |
+
if django_3 and type(request) == ASGIRequest:
|
| 492 |
+
# We have a `asgi_request_event_processor` for this.
|
| 493 |
+
return event
|
| 494 |
+
|
| 495 |
+
try:
|
| 496 |
+
drf_request = request._sentry_drf_request_backref()
|
| 497 |
+
if drf_request is not None:
|
| 498 |
+
request = drf_request
|
| 499 |
+
except AttributeError:
|
| 500 |
+
pass
|
| 501 |
+
|
| 502 |
+
with capture_internal_exceptions():
|
| 503 |
+
DjangoRequestExtractor(request).extract_into_event(event)
|
| 504 |
+
|
| 505 |
+
if should_send_default_pii():
|
| 506 |
+
with capture_internal_exceptions():
|
| 507 |
+
_set_user_info(request, event)
|
| 508 |
+
|
| 509 |
+
return event
|
| 510 |
+
|
| 511 |
+
return wsgi_request_event_processor
|
| 512 |
+
|
| 513 |
+
|
| 514 |
+
@ensure_integration_enabled(DjangoIntegration)
|
| 515 |
+
def _got_request_exception(request=None, **kwargs):
|
| 516 |
+
# type: (WSGIRequest, **Any) -> None
|
| 517 |
+
client = sentry_sdk.get_client()
|
| 518 |
+
integration = client.get_integration(DjangoIntegration)
|
| 519 |
+
|
| 520 |
+
if request is not None and integration.transaction_style == "url":
|
| 521 |
+
scope = sentry_sdk.get_current_scope()
|
| 522 |
+
_attempt_resolve_again(request, scope, integration.transaction_style)
|
| 523 |
+
|
| 524 |
+
event, hint = event_from_exception(
|
| 525 |
+
sys.exc_info(),
|
| 526 |
+
client_options=client.options,
|
| 527 |
+
mechanism={"type": "django", "handled": False},
|
| 528 |
+
)
|
| 529 |
+
sentry_sdk.capture_event(event, hint=hint)
|
| 530 |
+
|
| 531 |
+
|
| 532 |
+
class DjangoRequestExtractor(RequestExtractor):
|
| 533 |
+
def env(self):
|
| 534 |
+
# type: () -> Dict[str, str]
|
| 535 |
+
return self.request.META
|
| 536 |
+
|
| 537 |
+
def cookies(self):
|
| 538 |
+
# type: () -> Dict[str, Union[str, AnnotatedValue]]
|
| 539 |
+
privacy_cookies = [
|
| 540 |
+
django_settings.CSRF_COOKIE_NAME,
|
| 541 |
+
django_settings.SESSION_COOKIE_NAME,
|
| 542 |
+
]
|
| 543 |
+
|
| 544 |
+
clean_cookies = {} # type: Dict[str, Union[str, AnnotatedValue]]
|
| 545 |
+
for key, val in self.request.COOKIES.items():
|
| 546 |
+
if key in privacy_cookies:
|
| 547 |
+
clean_cookies[key] = SENSITIVE_DATA_SUBSTITUTE
|
| 548 |
+
else:
|
| 549 |
+
clean_cookies[key] = val
|
| 550 |
+
|
| 551 |
+
return clean_cookies
|
| 552 |
+
|
| 553 |
+
def raw_data(self):
|
| 554 |
+
# type: () -> bytes
|
| 555 |
+
return self.request.body
|
| 556 |
+
|
| 557 |
+
def form(self):
|
| 558 |
+
# type: () -> QueryDict
|
| 559 |
+
return self.request.POST
|
| 560 |
+
|
| 561 |
+
def files(self):
|
| 562 |
+
# type: () -> MultiValueDict
|
| 563 |
+
return self.request.FILES
|
| 564 |
+
|
| 565 |
+
def size_of_file(self, file):
|
| 566 |
+
# type: (Any) -> int
|
| 567 |
+
return file.size
|
| 568 |
+
|
| 569 |
+
def parsed_body(self):
|
| 570 |
+
# type: () -> Optional[Dict[str, Any]]
|
| 571 |
+
try:
|
| 572 |
+
return self.request.data
|
| 573 |
+
except AttributeError:
|
| 574 |
+
return RequestExtractor.parsed_body(self)
|
| 575 |
+
|
| 576 |
+
|
| 577 |
+
def _set_user_info(request, event):
|
| 578 |
+
# type: (WSGIRequest, Event) -> None
|
| 579 |
+
user_info = event.setdefault("user", {})
|
| 580 |
+
|
| 581 |
+
user = getattr(request, "user", None)
|
| 582 |
+
|
| 583 |
+
if user is None or not is_authenticated(user):
|
| 584 |
+
return
|
| 585 |
+
|
| 586 |
+
try:
|
| 587 |
+
user_info.setdefault("id", str(user.pk))
|
| 588 |
+
except Exception:
|
| 589 |
+
pass
|
| 590 |
+
|
| 591 |
+
try:
|
| 592 |
+
user_info.setdefault("email", user.email)
|
| 593 |
+
except Exception:
|
| 594 |
+
pass
|
| 595 |
+
|
| 596 |
+
try:
|
| 597 |
+
user_info.setdefault("username", user.get_username())
|
| 598 |
+
except Exception:
|
| 599 |
+
pass
|
| 600 |
+
|
| 601 |
+
|
| 602 |
+
def install_sql_hook():
|
| 603 |
+
# type: () -> None
|
| 604 |
+
"""If installed this causes Django's queries to be captured."""
|
| 605 |
+
try:
|
| 606 |
+
from django.db.backends.utils import CursorWrapper
|
| 607 |
+
except ImportError:
|
| 608 |
+
from django.db.backends.util import CursorWrapper
|
| 609 |
+
|
| 610 |
+
try:
|
| 611 |
+
# django 1.6 and 1.7 compatability
|
| 612 |
+
from django.db.backends import BaseDatabaseWrapper
|
| 613 |
+
except ImportError:
|
| 614 |
+
# django 1.8 or later
|
| 615 |
+
from django.db.backends.base.base import BaseDatabaseWrapper
|
| 616 |
+
|
| 617 |
+
try:
|
| 618 |
+
real_execute = CursorWrapper.execute
|
| 619 |
+
real_executemany = CursorWrapper.executemany
|
| 620 |
+
real_connect = BaseDatabaseWrapper.connect
|
| 621 |
+
except AttributeError:
|
| 622 |
+
# This won't work on Django versions < 1.6
|
| 623 |
+
return
|
| 624 |
+
|
| 625 |
+
@ensure_integration_enabled(DjangoIntegration, real_execute)
|
| 626 |
+
def execute(self, sql, params=None):
|
| 627 |
+
# type: (CursorWrapper, Any, Optional[Any]) -> Any
|
| 628 |
+
with record_sql_queries(
|
| 629 |
+
cursor=self.cursor,
|
| 630 |
+
query=sql,
|
| 631 |
+
params_list=params,
|
| 632 |
+
paramstyle="format",
|
| 633 |
+
executemany=False,
|
| 634 |
+
span_origin=DjangoIntegration.origin_db,
|
| 635 |
+
) as span:
|
| 636 |
+
_set_db_data(span, self)
|
| 637 |
+
options = (
|
| 638 |
+
sentry_sdk.get_client()
|
| 639 |
+
.options["_experiments"]
|
| 640 |
+
.get("attach_explain_plans")
|
| 641 |
+
)
|
| 642 |
+
if options is not None:
|
| 643 |
+
attach_explain_plan_to_span(
|
| 644 |
+
span,
|
| 645 |
+
self.cursor.connection,
|
| 646 |
+
sql,
|
| 647 |
+
params,
|
| 648 |
+
self.mogrify,
|
| 649 |
+
options,
|
| 650 |
+
)
|
| 651 |
+
result = real_execute(self, sql, params)
|
| 652 |
+
|
| 653 |
+
with capture_internal_exceptions():
|
| 654 |
+
add_query_source(span)
|
| 655 |
+
|
| 656 |
+
return result
|
| 657 |
+
|
| 658 |
+
@ensure_integration_enabled(DjangoIntegration, real_executemany)
|
| 659 |
+
def executemany(self, sql, param_list):
|
| 660 |
+
# type: (CursorWrapper, Any, List[Any]) -> Any
|
| 661 |
+
with record_sql_queries(
|
| 662 |
+
cursor=self.cursor,
|
| 663 |
+
query=sql,
|
| 664 |
+
params_list=param_list,
|
| 665 |
+
paramstyle="format",
|
| 666 |
+
executemany=True,
|
| 667 |
+
span_origin=DjangoIntegration.origin_db,
|
| 668 |
+
) as span:
|
| 669 |
+
_set_db_data(span, self)
|
| 670 |
+
|
| 671 |
+
result = real_executemany(self, sql, param_list)
|
| 672 |
+
|
| 673 |
+
with capture_internal_exceptions():
|
| 674 |
+
add_query_source(span)
|
| 675 |
+
|
| 676 |
+
return result
|
| 677 |
+
|
| 678 |
+
@ensure_integration_enabled(DjangoIntegration, real_connect)
|
| 679 |
+
def connect(self):
|
| 680 |
+
# type: (BaseDatabaseWrapper) -> None
|
| 681 |
+
with capture_internal_exceptions():
|
| 682 |
+
sentry_sdk.add_breadcrumb(message="connect", category="query")
|
| 683 |
+
|
| 684 |
+
with sentry_sdk.start_span(
|
| 685 |
+
op=OP.DB,
|
| 686 |
+
description="connect",
|
| 687 |
+
origin=DjangoIntegration.origin_db,
|
| 688 |
+
) as span:
|
| 689 |
+
_set_db_data(span, self)
|
| 690 |
+
return real_connect(self)
|
| 691 |
+
|
| 692 |
+
CursorWrapper.execute = execute
|
| 693 |
+
CursorWrapper.executemany = executemany
|
| 694 |
+
BaseDatabaseWrapper.connect = connect
|
| 695 |
+
ignore_logger("django.db.backends")
|
| 696 |
+
|
| 697 |
+
|
| 698 |
+
def _set_db_data(span, cursor_or_db):
|
| 699 |
+
# type: (Span, Any) -> None
|
| 700 |
+
db = cursor_or_db.db if hasattr(cursor_or_db, "db") else cursor_or_db
|
| 701 |
+
vendor = db.vendor
|
| 702 |
+
span.set_data(SPANDATA.DB_SYSTEM, vendor)
|
| 703 |
+
|
| 704 |
+
# Some custom backends override `__getattr__`, making it look like `cursor_or_db`
|
| 705 |
+
# actually has a `connection` and the `connection` has a `get_dsn_parameters`
|
| 706 |
+
# attribute, only to throw an error once you actually want to call it.
|
| 707 |
+
# Hence the `inspect` check whether `get_dsn_parameters` is an actual callable
|
| 708 |
+
# function.
|
| 709 |
+
is_psycopg2 = (
|
| 710 |
+
hasattr(cursor_or_db, "connection")
|
| 711 |
+
and hasattr(cursor_or_db.connection, "get_dsn_parameters")
|
| 712 |
+
and inspect.isroutine(cursor_or_db.connection.get_dsn_parameters)
|
| 713 |
+
)
|
| 714 |
+
if is_psycopg2:
|
| 715 |
+
connection_params = cursor_or_db.connection.get_dsn_parameters()
|
| 716 |
+
else:
|
| 717 |
+
try:
|
| 718 |
+
# psycopg3
|
| 719 |
+
connection_params = cursor_or_db.connection.info.get_parameters()
|
| 720 |
+
except Exception:
|
| 721 |
+
connection_params = db.get_connection_params()
|
| 722 |
+
|
| 723 |
+
db_name = connection_params.get("dbname") or connection_params.get("database")
|
| 724 |
+
if db_name is not None:
|
| 725 |
+
span.set_data(SPANDATA.DB_NAME, db_name)
|
| 726 |
+
|
| 727 |
+
server_address = connection_params.get("host")
|
| 728 |
+
if server_address is not None:
|
| 729 |
+
span.set_data(SPANDATA.SERVER_ADDRESS, server_address)
|
| 730 |
+
|
| 731 |
+
server_port = connection_params.get("port")
|
| 732 |
+
if server_port is not None:
|
| 733 |
+
span.set_data(SPANDATA.SERVER_PORT, str(server_port))
|
| 734 |
+
|
| 735 |
+
server_socket_address = connection_params.get("unix_socket")
|
| 736 |
+
if server_socket_address is not None:
|
| 737 |
+
span.set_data(SPANDATA.SERVER_SOCKET_ADDRESS, server_socket_address)
|
videollama2/lib/python3.10/site-packages/sentry_sdk/integrations/django/__pycache__/caching.cpython-310.pyc
ADDED
|
Binary file (4.2 kB). View file
|
|
|
videollama2/lib/python3.10/site-packages/sentry_sdk/integrations/django/asgi.py
ADDED
|
@@ -0,0 +1,237 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|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
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
"""
|
| 2 |
+
Instrumentation for Django 3.0
|
| 3 |
+
|
| 4 |
+
Since this file contains `async def` it is conditionally imported in
|
| 5 |
+
`sentry_sdk.integrations.django` (depending on the existence of
|
| 6 |
+
`django.core.handlers.asgi`.
|
| 7 |
+
"""
|
| 8 |
+
|
| 9 |
+
import asyncio
|
| 10 |
+
import functools
|
| 11 |
+
import inspect
|
| 12 |
+
|
| 13 |
+
from django.core.handlers.wsgi import WSGIRequest
|
| 14 |
+
|
| 15 |
+
import sentry_sdk
|
| 16 |
+
from sentry_sdk._types import TYPE_CHECKING
|
| 17 |
+
from sentry_sdk.consts import OP
|
| 18 |
+
|
| 19 |
+
from sentry_sdk.integrations.asgi import SentryAsgiMiddleware
|
| 20 |
+
from sentry_sdk.scope import should_send_default_pii
|
| 21 |
+
from sentry_sdk.utils import (
|
| 22 |
+
capture_internal_exceptions,
|
| 23 |
+
ensure_integration_enabled,
|
| 24 |
+
)
|
| 25 |
+
|
| 26 |
+
|
| 27 |
+
if TYPE_CHECKING:
|
| 28 |
+
from typing import Any, Callable, Union, TypeVar
|
| 29 |
+
|
| 30 |
+
from django.core.handlers.asgi import ASGIRequest
|
| 31 |
+
from django.http.response import HttpResponse
|
| 32 |
+
|
| 33 |
+
from sentry_sdk._types import Event, EventProcessor
|
| 34 |
+
|
| 35 |
+
_F = TypeVar("_F", bound=Callable[..., Any])
|
| 36 |
+
|
| 37 |
+
|
| 38 |
+
# Python 3.12 deprecates asyncio.iscoroutinefunction() as an alias for
|
| 39 |
+
# inspect.iscoroutinefunction(), whilst also removing the _is_coroutine marker.
|
| 40 |
+
# The latter is replaced with the inspect.markcoroutinefunction decorator.
|
| 41 |
+
# Until 3.12 is the minimum supported Python version, provide a shim.
|
| 42 |
+
# This was copied from https://github.com/django/asgiref/blob/main/asgiref/sync.py
|
| 43 |
+
if hasattr(inspect, "markcoroutinefunction"):
|
| 44 |
+
iscoroutinefunction = inspect.iscoroutinefunction
|
| 45 |
+
markcoroutinefunction = inspect.markcoroutinefunction
|
| 46 |
+
else:
|
| 47 |
+
iscoroutinefunction = asyncio.iscoroutinefunction # type: ignore[assignment]
|
| 48 |
+
|
| 49 |
+
def markcoroutinefunction(func: "_F") -> "_F":
|
| 50 |
+
func._is_coroutine = asyncio.coroutines._is_coroutine # type: ignore
|
| 51 |
+
return func
|
| 52 |
+
|
| 53 |
+
|
| 54 |
+
def _make_asgi_request_event_processor(request):
|
| 55 |
+
# type: (ASGIRequest) -> EventProcessor
|
| 56 |
+
def asgi_request_event_processor(event, hint):
|
| 57 |
+
# type: (Event, dict[str, Any]) -> Event
|
| 58 |
+
# if the request is gone we are fine not logging the data from
|
| 59 |
+
# it. This might happen if the processor is pushed away to
|
| 60 |
+
# another thread.
|
| 61 |
+
from sentry_sdk.integrations.django import (
|
| 62 |
+
DjangoRequestExtractor,
|
| 63 |
+
_set_user_info,
|
| 64 |
+
)
|
| 65 |
+
|
| 66 |
+
if request is None:
|
| 67 |
+
return event
|
| 68 |
+
|
| 69 |
+
if type(request) == WSGIRequest:
|
| 70 |
+
return event
|
| 71 |
+
|
| 72 |
+
with capture_internal_exceptions():
|
| 73 |
+
DjangoRequestExtractor(request).extract_into_event(event)
|
| 74 |
+
|
| 75 |
+
if should_send_default_pii():
|
| 76 |
+
with capture_internal_exceptions():
|
| 77 |
+
_set_user_info(request, event)
|
| 78 |
+
|
| 79 |
+
return event
|
| 80 |
+
|
| 81 |
+
return asgi_request_event_processor
|
| 82 |
+
|
| 83 |
+
|
| 84 |
+
def patch_django_asgi_handler_impl(cls):
|
| 85 |
+
# type: (Any) -> None
|
| 86 |
+
|
| 87 |
+
from sentry_sdk.integrations.django import DjangoIntegration
|
| 88 |
+
|
| 89 |
+
old_app = cls.__call__
|
| 90 |
+
|
| 91 |
+
async def sentry_patched_asgi_handler(self, scope, receive, send):
|
| 92 |
+
# type: (Any, Any, Any, Any) -> Any
|
| 93 |
+
if sentry_sdk.get_client().get_integration(DjangoIntegration) is None:
|
| 94 |
+
return await old_app(self, scope, receive, send)
|
| 95 |
+
|
| 96 |
+
middleware = SentryAsgiMiddleware(
|
| 97 |
+
old_app.__get__(self, cls),
|
| 98 |
+
unsafe_context_data=True,
|
| 99 |
+
span_origin=DjangoIntegration.origin,
|
| 100 |
+
)._run_asgi3
|
| 101 |
+
|
| 102 |
+
return await middleware(scope, receive, send)
|
| 103 |
+
|
| 104 |
+
cls.__call__ = sentry_patched_asgi_handler
|
| 105 |
+
|
| 106 |
+
modern_django_asgi_support = hasattr(cls, "create_request")
|
| 107 |
+
if modern_django_asgi_support:
|
| 108 |
+
old_create_request = cls.create_request
|
| 109 |
+
|
| 110 |
+
@ensure_integration_enabled(DjangoIntegration, old_create_request)
|
| 111 |
+
def sentry_patched_create_request(self, *args, **kwargs):
|
| 112 |
+
# type: (Any, *Any, **Any) -> Any
|
| 113 |
+
request, error_response = old_create_request(self, *args, **kwargs)
|
| 114 |
+
scope = sentry_sdk.get_isolation_scope()
|
| 115 |
+
scope.add_event_processor(_make_asgi_request_event_processor(request))
|
| 116 |
+
|
| 117 |
+
return request, error_response
|
| 118 |
+
|
| 119 |
+
cls.create_request = sentry_patched_create_request
|
| 120 |
+
|
| 121 |
+
|
| 122 |
+
def patch_get_response_async(cls, _before_get_response):
|
| 123 |
+
# type: (Any, Any) -> None
|
| 124 |
+
old_get_response_async = cls.get_response_async
|
| 125 |
+
|
| 126 |
+
async def sentry_patched_get_response_async(self, request):
|
| 127 |
+
# type: (Any, Any) -> Union[HttpResponse, BaseException]
|
| 128 |
+
_before_get_response(request)
|
| 129 |
+
return await old_get_response_async(self, request)
|
| 130 |
+
|
| 131 |
+
cls.get_response_async = sentry_patched_get_response_async
|
| 132 |
+
|
| 133 |
+
|
| 134 |
+
def patch_channels_asgi_handler_impl(cls):
|
| 135 |
+
# type: (Any) -> None
|
| 136 |
+
import channels # type: ignore
|
| 137 |
+
|
| 138 |
+
from sentry_sdk.integrations.django import DjangoIntegration
|
| 139 |
+
|
| 140 |
+
if channels.__version__ < "3.0.0":
|
| 141 |
+
old_app = cls.__call__
|
| 142 |
+
|
| 143 |
+
async def sentry_patched_asgi_handler(self, receive, send):
|
| 144 |
+
# type: (Any, Any, Any) -> Any
|
| 145 |
+
if sentry_sdk.get_client().get_integration(DjangoIntegration) is None:
|
| 146 |
+
return await old_app(self, receive, send)
|
| 147 |
+
|
| 148 |
+
middleware = SentryAsgiMiddleware(
|
| 149 |
+
lambda _scope: old_app.__get__(self, cls),
|
| 150 |
+
unsafe_context_data=True,
|
| 151 |
+
span_origin=DjangoIntegration.origin,
|
| 152 |
+
)
|
| 153 |
+
|
| 154 |
+
return await middleware(self.scope)(receive, send)
|
| 155 |
+
|
| 156 |
+
cls.__call__ = sentry_patched_asgi_handler
|
| 157 |
+
|
| 158 |
+
else:
|
| 159 |
+
# The ASGI handler in Channels >= 3 has the same signature as
|
| 160 |
+
# the Django handler.
|
| 161 |
+
patch_django_asgi_handler_impl(cls)
|
| 162 |
+
|
| 163 |
+
|
| 164 |
+
def wrap_async_view(callback):
|
| 165 |
+
# type: (Any) -> Any
|
| 166 |
+
from sentry_sdk.integrations.django import DjangoIntegration
|
| 167 |
+
|
| 168 |
+
@functools.wraps(callback)
|
| 169 |
+
async def sentry_wrapped_callback(request, *args, **kwargs):
|
| 170 |
+
# type: (Any, *Any, **Any) -> Any
|
| 171 |
+
sentry_scope = sentry_sdk.get_isolation_scope()
|
| 172 |
+
if sentry_scope.profile is not None:
|
| 173 |
+
sentry_scope.profile.update_active_thread_id()
|
| 174 |
+
|
| 175 |
+
with sentry_sdk.start_span(
|
| 176 |
+
op=OP.VIEW_RENDER,
|
| 177 |
+
description=request.resolver_match.view_name,
|
| 178 |
+
origin=DjangoIntegration.origin,
|
| 179 |
+
):
|
| 180 |
+
return await callback(request, *args, **kwargs)
|
| 181 |
+
|
| 182 |
+
return sentry_wrapped_callback
|
| 183 |
+
|
| 184 |
+
|
| 185 |
+
def _asgi_middleware_mixin_factory(_check_middleware_span):
|
| 186 |
+
# type: (Callable[..., Any]) -> Any
|
| 187 |
+
"""
|
| 188 |
+
Mixin class factory that generates a middleware mixin for handling requests
|
| 189 |
+
in async mode.
|
| 190 |
+
"""
|
| 191 |
+
|
| 192 |
+
class SentryASGIMixin:
|
| 193 |
+
if TYPE_CHECKING:
|
| 194 |
+
_inner = None
|
| 195 |
+
|
| 196 |
+
def __init__(self, get_response):
|
| 197 |
+
# type: (Callable[..., Any]) -> None
|
| 198 |
+
self.get_response = get_response
|
| 199 |
+
self._acall_method = None
|
| 200 |
+
self._async_check()
|
| 201 |
+
|
| 202 |
+
def _async_check(self):
|
| 203 |
+
# type: () -> None
|
| 204 |
+
"""
|
| 205 |
+
If get_response is a coroutine function, turns us into async mode so
|
| 206 |
+
a thread is not consumed during a whole request.
|
| 207 |
+
Taken from django.utils.deprecation::MiddlewareMixin._async_check
|
| 208 |
+
"""
|
| 209 |
+
if iscoroutinefunction(self.get_response):
|
| 210 |
+
markcoroutinefunction(self)
|
| 211 |
+
|
| 212 |
+
def async_route_check(self):
|
| 213 |
+
# type: () -> bool
|
| 214 |
+
"""
|
| 215 |
+
Function that checks if we are in async mode,
|
| 216 |
+
and if we are forwards the handling of requests to __acall__
|
| 217 |
+
"""
|
| 218 |
+
return iscoroutinefunction(self.get_response)
|
| 219 |
+
|
| 220 |
+
async def __acall__(self, *args, **kwargs):
|
| 221 |
+
# type: (*Any, **Any) -> Any
|
| 222 |
+
f = self._acall_method
|
| 223 |
+
if f is None:
|
| 224 |
+
if hasattr(self._inner, "__acall__"):
|
| 225 |
+
self._acall_method = f = self._inner.__acall__ # type: ignore
|
| 226 |
+
else:
|
| 227 |
+
self._acall_method = f = self._inner
|
| 228 |
+
|
| 229 |
+
middleware_span = _check_middleware_span(old_method=f)
|
| 230 |
+
|
| 231 |
+
if middleware_span is None:
|
| 232 |
+
return await f(*args, **kwargs)
|
| 233 |
+
|
| 234 |
+
with middleware_span:
|
| 235 |
+
return await f(*args, **kwargs)
|
| 236 |
+
|
| 237 |
+
return SentryASGIMixin
|
videollama2/lib/python3.10/site-packages/sentry_sdk/integrations/django/caching.py
ADDED
|
@@ -0,0 +1,180 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
import functools
|
| 2 |
+
from typing import TYPE_CHECKING
|
| 3 |
+
from sentry_sdk.integrations.redis.utils import _get_safe_key, _key_as_string
|
| 4 |
+
from urllib3.util import parse_url as urlparse
|
| 5 |
+
|
| 6 |
+
from django import VERSION as DJANGO_VERSION
|
| 7 |
+
from django.core.cache import CacheHandler
|
| 8 |
+
|
| 9 |
+
import sentry_sdk
|
| 10 |
+
from sentry_sdk.consts import OP, SPANDATA
|
| 11 |
+
from sentry_sdk.utils import (
|
| 12 |
+
capture_internal_exceptions,
|
| 13 |
+
ensure_integration_enabled,
|
| 14 |
+
)
|
| 15 |
+
|
| 16 |
+
|
| 17 |
+
if TYPE_CHECKING:
|
| 18 |
+
from typing import Any
|
| 19 |
+
from typing import Callable
|
| 20 |
+
from typing import Optional
|
| 21 |
+
|
| 22 |
+
|
| 23 |
+
METHODS_TO_INSTRUMENT = [
|
| 24 |
+
"set",
|
| 25 |
+
"set_many",
|
| 26 |
+
"get",
|
| 27 |
+
"get_many",
|
| 28 |
+
]
|
| 29 |
+
|
| 30 |
+
|
| 31 |
+
def _get_span_description(method_name, args, kwargs):
|
| 32 |
+
# type: (str, tuple[Any], dict[str, Any]) -> str
|
| 33 |
+
return _key_as_string(_get_safe_key(method_name, args, kwargs))
|
| 34 |
+
|
| 35 |
+
|
| 36 |
+
def _patch_cache_method(cache, method_name, address, port):
|
| 37 |
+
# type: (CacheHandler, str, Optional[str], Optional[int]) -> None
|
| 38 |
+
from sentry_sdk.integrations.django import DjangoIntegration
|
| 39 |
+
|
| 40 |
+
original_method = getattr(cache, method_name)
|
| 41 |
+
|
| 42 |
+
@ensure_integration_enabled(DjangoIntegration, original_method)
|
| 43 |
+
def _instrument_call(
|
| 44 |
+
cache, method_name, original_method, args, kwargs, address, port
|
| 45 |
+
):
|
| 46 |
+
# type: (CacheHandler, str, Callable[..., Any], tuple[Any, ...], dict[str, Any], Optional[str], Optional[int]) -> Any
|
| 47 |
+
is_set_operation = method_name.startswith("set")
|
| 48 |
+
is_get_operation = not is_set_operation
|
| 49 |
+
|
| 50 |
+
op = OP.CACHE_PUT if is_set_operation else OP.CACHE_GET
|
| 51 |
+
description = _get_span_description(method_name, args, kwargs)
|
| 52 |
+
|
| 53 |
+
with sentry_sdk.start_span(
|
| 54 |
+
op=op,
|
| 55 |
+
description=description,
|
| 56 |
+
origin=DjangoIntegration.origin,
|
| 57 |
+
) as span:
|
| 58 |
+
value = original_method(*args, **kwargs)
|
| 59 |
+
|
| 60 |
+
with capture_internal_exceptions():
|
| 61 |
+
if address is not None:
|
| 62 |
+
span.set_data(SPANDATA.NETWORK_PEER_ADDRESS, address)
|
| 63 |
+
|
| 64 |
+
if port is not None:
|
| 65 |
+
span.set_data(SPANDATA.NETWORK_PEER_PORT, port)
|
| 66 |
+
|
| 67 |
+
key = _get_safe_key(method_name, args, kwargs)
|
| 68 |
+
if key is not None:
|
| 69 |
+
span.set_data(SPANDATA.CACHE_KEY, key)
|
| 70 |
+
|
| 71 |
+
item_size = None
|
| 72 |
+
if is_get_operation:
|
| 73 |
+
if value:
|
| 74 |
+
item_size = len(str(value))
|
| 75 |
+
span.set_data(SPANDATA.CACHE_HIT, True)
|
| 76 |
+
else:
|
| 77 |
+
span.set_data(SPANDATA.CACHE_HIT, False)
|
| 78 |
+
else:
|
| 79 |
+
try:
|
| 80 |
+
# 'set' command
|
| 81 |
+
item_size = len(str(args[1]))
|
| 82 |
+
except IndexError:
|
| 83 |
+
# 'set_many' command
|
| 84 |
+
item_size = len(str(args[0]))
|
| 85 |
+
|
| 86 |
+
if item_size is not None:
|
| 87 |
+
span.set_data(SPANDATA.CACHE_ITEM_SIZE, item_size)
|
| 88 |
+
|
| 89 |
+
return value
|
| 90 |
+
|
| 91 |
+
@functools.wraps(original_method)
|
| 92 |
+
def sentry_method(*args, **kwargs):
|
| 93 |
+
# type: (*Any, **Any) -> Any
|
| 94 |
+
return _instrument_call(
|
| 95 |
+
cache, method_name, original_method, args, kwargs, address, port
|
| 96 |
+
)
|
| 97 |
+
|
| 98 |
+
setattr(cache, method_name, sentry_method)
|
| 99 |
+
|
| 100 |
+
|
| 101 |
+
def _patch_cache(cache, address=None, port=None):
|
| 102 |
+
# type: (CacheHandler, Optional[str], Optional[int]) -> None
|
| 103 |
+
if not hasattr(cache, "_sentry_patched"):
|
| 104 |
+
for method_name in METHODS_TO_INSTRUMENT:
|
| 105 |
+
_patch_cache_method(cache, method_name, address, port)
|
| 106 |
+
cache._sentry_patched = True
|
| 107 |
+
|
| 108 |
+
|
| 109 |
+
def _get_address_port(settings):
|
| 110 |
+
# type: (dict[str, Any]) -> tuple[Optional[str], Optional[int]]
|
| 111 |
+
location = settings.get("LOCATION")
|
| 112 |
+
|
| 113 |
+
# TODO: location can also be an array of locations
|
| 114 |
+
# see: https://docs.djangoproject.com/en/5.0/topics/cache/#redis
|
| 115 |
+
# GitHub issue: https://github.com/getsentry/sentry-python/issues/3062
|
| 116 |
+
if not isinstance(location, str):
|
| 117 |
+
return None, None
|
| 118 |
+
|
| 119 |
+
if "://" in location:
|
| 120 |
+
parsed_url = urlparse(location)
|
| 121 |
+
# remove the username and password from URL to not leak sensitive data.
|
| 122 |
+
address = "{}://{}{}".format(
|
| 123 |
+
parsed_url.scheme or "",
|
| 124 |
+
parsed_url.hostname or "",
|
| 125 |
+
parsed_url.path or "",
|
| 126 |
+
)
|
| 127 |
+
port = parsed_url.port
|
| 128 |
+
else:
|
| 129 |
+
address = location
|
| 130 |
+
port = None
|
| 131 |
+
|
| 132 |
+
return address, int(port) if port is not None else None
|
| 133 |
+
|
| 134 |
+
|
| 135 |
+
def patch_caching():
|
| 136 |
+
# type: () -> None
|
| 137 |
+
from sentry_sdk.integrations.django import DjangoIntegration
|
| 138 |
+
|
| 139 |
+
if not hasattr(CacheHandler, "_sentry_patched"):
|
| 140 |
+
if DJANGO_VERSION < (3, 2):
|
| 141 |
+
original_get_item = CacheHandler.__getitem__
|
| 142 |
+
|
| 143 |
+
@functools.wraps(original_get_item)
|
| 144 |
+
def sentry_get_item(self, alias):
|
| 145 |
+
# type: (CacheHandler, str) -> Any
|
| 146 |
+
cache = original_get_item(self, alias)
|
| 147 |
+
|
| 148 |
+
integration = sentry_sdk.get_client().get_integration(DjangoIntegration)
|
| 149 |
+
if integration is not None and integration.cache_spans:
|
| 150 |
+
from django.conf import settings
|
| 151 |
+
|
| 152 |
+
address, port = _get_address_port(
|
| 153 |
+
settings.CACHES[alias or "default"]
|
| 154 |
+
)
|
| 155 |
+
|
| 156 |
+
_patch_cache(cache, address, port)
|
| 157 |
+
|
| 158 |
+
return cache
|
| 159 |
+
|
| 160 |
+
CacheHandler.__getitem__ = sentry_get_item
|
| 161 |
+
CacheHandler._sentry_patched = True
|
| 162 |
+
|
| 163 |
+
else:
|
| 164 |
+
original_create_connection = CacheHandler.create_connection
|
| 165 |
+
|
| 166 |
+
@functools.wraps(original_create_connection)
|
| 167 |
+
def sentry_create_connection(self, alias):
|
| 168 |
+
# type: (CacheHandler, str) -> Any
|
| 169 |
+
cache = original_create_connection(self, alias)
|
| 170 |
+
|
| 171 |
+
integration = sentry_sdk.get_client().get_integration(DjangoIntegration)
|
| 172 |
+
if integration is not None and integration.cache_spans:
|
| 173 |
+
address, port = _get_address_port(self.settings[alias or "default"])
|
| 174 |
+
|
| 175 |
+
_patch_cache(cache, address, port)
|
| 176 |
+
|
| 177 |
+
return cache
|
| 178 |
+
|
| 179 |
+
CacheHandler.create_connection = sentry_create_connection
|
| 180 |
+
CacheHandler._sentry_patched = True
|
videollama2/lib/python3.10/site-packages/sentry_sdk/integrations/django/templates.py
ADDED
|
@@ -0,0 +1,187 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
import functools
|
| 2 |
+
|
| 3 |
+
from django.template import TemplateSyntaxError
|
| 4 |
+
from django.utils.safestring import mark_safe
|
| 5 |
+
from django import VERSION as DJANGO_VERSION
|
| 6 |
+
|
| 7 |
+
import sentry_sdk
|
| 8 |
+
from sentry_sdk._types import TYPE_CHECKING
|
| 9 |
+
from sentry_sdk.consts import OP
|
| 10 |
+
from sentry_sdk.utils import ensure_integration_enabled
|
| 11 |
+
|
| 12 |
+
if TYPE_CHECKING:
|
| 13 |
+
from typing import Any
|
| 14 |
+
from typing import Dict
|
| 15 |
+
from typing import Optional
|
| 16 |
+
from typing import Iterator
|
| 17 |
+
from typing import Tuple
|
| 18 |
+
|
| 19 |
+
try:
|
| 20 |
+
# support Django 1.9
|
| 21 |
+
from django.template.base import Origin
|
| 22 |
+
except ImportError:
|
| 23 |
+
# backward compatibility
|
| 24 |
+
from django.template.loader import LoaderOrigin as Origin
|
| 25 |
+
|
| 26 |
+
|
| 27 |
+
def get_template_frame_from_exception(exc_value):
|
| 28 |
+
# type: (Optional[BaseException]) -> Optional[Dict[str, Any]]
|
| 29 |
+
|
| 30 |
+
# As of Django 1.9 or so the new template debug thing showed up.
|
| 31 |
+
if hasattr(exc_value, "template_debug"):
|
| 32 |
+
return _get_template_frame_from_debug(exc_value.template_debug) # type: ignore
|
| 33 |
+
|
| 34 |
+
# As of r16833 (Django) all exceptions may contain a
|
| 35 |
+
# ``django_template_source`` attribute (rather than the legacy
|
| 36 |
+
# ``TemplateSyntaxError.source`` check)
|
| 37 |
+
if hasattr(exc_value, "django_template_source"):
|
| 38 |
+
return _get_template_frame_from_source(
|
| 39 |
+
exc_value.django_template_source # type: ignore
|
| 40 |
+
)
|
| 41 |
+
|
| 42 |
+
if isinstance(exc_value, TemplateSyntaxError) and hasattr(exc_value, "source"):
|
| 43 |
+
source = exc_value.source
|
| 44 |
+
if isinstance(source, (tuple, list)) and isinstance(source[0], Origin):
|
| 45 |
+
return _get_template_frame_from_source(source) # type: ignore
|
| 46 |
+
|
| 47 |
+
return None
|
| 48 |
+
|
| 49 |
+
|
| 50 |
+
def _get_template_name_description(template_name):
|
| 51 |
+
# type: (str) -> str
|
| 52 |
+
if isinstance(template_name, (list, tuple)):
|
| 53 |
+
if template_name:
|
| 54 |
+
return "[{}, ...]".format(template_name[0])
|
| 55 |
+
else:
|
| 56 |
+
return template_name
|
| 57 |
+
|
| 58 |
+
|
| 59 |
+
def patch_templates():
|
| 60 |
+
# type: () -> None
|
| 61 |
+
from django.template.response import SimpleTemplateResponse
|
| 62 |
+
from sentry_sdk.integrations.django import DjangoIntegration
|
| 63 |
+
|
| 64 |
+
real_rendered_content = SimpleTemplateResponse.rendered_content
|
| 65 |
+
|
| 66 |
+
@property # type: ignore
|
| 67 |
+
@ensure_integration_enabled(DjangoIntegration, real_rendered_content.fget)
|
| 68 |
+
def rendered_content(self):
|
| 69 |
+
# type: (SimpleTemplateResponse) -> str
|
| 70 |
+
with sentry_sdk.start_span(
|
| 71 |
+
op=OP.TEMPLATE_RENDER,
|
| 72 |
+
description=_get_template_name_description(self.template_name),
|
| 73 |
+
origin=DjangoIntegration.origin,
|
| 74 |
+
) as span:
|
| 75 |
+
span.set_data("context", self.context_data)
|
| 76 |
+
return real_rendered_content.fget(self)
|
| 77 |
+
|
| 78 |
+
SimpleTemplateResponse.rendered_content = rendered_content
|
| 79 |
+
|
| 80 |
+
if DJANGO_VERSION < (1, 7):
|
| 81 |
+
return
|
| 82 |
+
import django.shortcuts
|
| 83 |
+
|
| 84 |
+
real_render = django.shortcuts.render
|
| 85 |
+
|
| 86 |
+
@functools.wraps(real_render)
|
| 87 |
+
@ensure_integration_enabled(DjangoIntegration, real_render)
|
| 88 |
+
def render(request, template_name, context=None, *args, **kwargs):
|
| 89 |
+
# type: (django.http.HttpRequest, str, Optional[Dict[str, Any]], *Any, **Any) -> django.http.HttpResponse
|
| 90 |
+
|
| 91 |
+
# Inject trace meta tags into template context
|
| 92 |
+
context = context or {}
|
| 93 |
+
if "sentry_trace_meta" not in context:
|
| 94 |
+
context["sentry_trace_meta"] = mark_safe(
|
| 95 |
+
sentry_sdk.get_current_scope().trace_propagation_meta()
|
| 96 |
+
)
|
| 97 |
+
|
| 98 |
+
with sentry_sdk.start_span(
|
| 99 |
+
op=OP.TEMPLATE_RENDER,
|
| 100 |
+
description=_get_template_name_description(template_name),
|
| 101 |
+
origin=DjangoIntegration.origin,
|
| 102 |
+
) as span:
|
| 103 |
+
span.set_data("context", context)
|
| 104 |
+
return real_render(request, template_name, context, *args, **kwargs)
|
| 105 |
+
|
| 106 |
+
django.shortcuts.render = render
|
| 107 |
+
|
| 108 |
+
|
| 109 |
+
def _get_template_frame_from_debug(debug):
|
| 110 |
+
# type: (Dict[str, Any]) -> Dict[str, Any]
|
| 111 |
+
if debug is None:
|
| 112 |
+
return None
|
| 113 |
+
|
| 114 |
+
lineno = debug["line"]
|
| 115 |
+
filename = debug["name"]
|
| 116 |
+
if filename is None:
|
| 117 |
+
filename = "<django template>"
|
| 118 |
+
|
| 119 |
+
pre_context = []
|
| 120 |
+
post_context = []
|
| 121 |
+
context_line = None
|
| 122 |
+
|
| 123 |
+
for i, line in debug["source_lines"]:
|
| 124 |
+
if i < lineno:
|
| 125 |
+
pre_context.append(line)
|
| 126 |
+
elif i > lineno:
|
| 127 |
+
post_context.append(line)
|
| 128 |
+
else:
|
| 129 |
+
context_line = line
|
| 130 |
+
|
| 131 |
+
return {
|
| 132 |
+
"filename": filename,
|
| 133 |
+
"lineno": lineno,
|
| 134 |
+
"pre_context": pre_context[-5:],
|
| 135 |
+
"post_context": post_context[:5],
|
| 136 |
+
"context_line": context_line,
|
| 137 |
+
"in_app": True,
|
| 138 |
+
}
|
| 139 |
+
|
| 140 |
+
|
| 141 |
+
def _linebreak_iter(template_source):
|
| 142 |
+
# type: (str) -> Iterator[int]
|
| 143 |
+
yield 0
|
| 144 |
+
p = template_source.find("\n")
|
| 145 |
+
while p >= 0:
|
| 146 |
+
yield p + 1
|
| 147 |
+
p = template_source.find("\n", p + 1)
|
| 148 |
+
|
| 149 |
+
|
| 150 |
+
def _get_template_frame_from_source(source):
|
| 151 |
+
# type: (Tuple[Origin, Tuple[int, int]]) -> Optional[Dict[str, Any]]
|
| 152 |
+
if not source:
|
| 153 |
+
return None
|
| 154 |
+
|
| 155 |
+
origin, (start, end) = source
|
| 156 |
+
filename = getattr(origin, "loadname", None)
|
| 157 |
+
if filename is None:
|
| 158 |
+
filename = "<django template>"
|
| 159 |
+
template_source = origin.reload()
|
| 160 |
+
lineno = None
|
| 161 |
+
upto = 0
|
| 162 |
+
pre_context = []
|
| 163 |
+
post_context = []
|
| 164 |
+
context_line = None
|
| 165 |
+
|
| 166 |
+
for num, next in enumerate(_linebreak_iter(template_source)):
|
| 167 |
+
line = template_source[upto:next]
|
| 168 |
+
if start >= upto and end <= next:
|
| 169 |
+
lineno = num
|
| 170 |
+
context_line = line
|
| 171 |
+
elif lineno is None:
|
| 172 |
+
pre_context.append(line)
|
| 173 |
+
else:
|
| 174 |
+
post_context.append(line)
|
| 175 |
+
|
| 176 |
+
upto = next
|
| 177 |
+
|
| 178 |
+
if context_line is None or lineno is None:
|
| 179 |
+
return None
|
| 180 |
+
|
| 181 |
+
return {
|
| 182 |
+
"filename": filename,
|
| 183 |
+
"lineno": lineno,
|
| 184 |
+
"pre_context": pre_context[-5:],
|
| 185 |
+
"post_context": post_context[:5],
|
| 186 |
+
"context_line": context_line,
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
|
|
|
|
|
|
| 1 |
+
"""
|
| 2 |
+
Copied from raven-python.
|
| 3 |
+
|
| 4 |
+
Despite being called "legacy" in some places this resolver is very much still
|
| 5 |
+
in use.
|
| 6 |
+
"""
|
| 7 |
+
|
| 8 |
+
import re
|
| 9 |
+
|
| 10 |
+
from sentry_sdk._types import TYPE_CHECKING
|
| 11 |
+
|
| 12 |
+
if TYPE_CHECKING:
|
| 13 |
+
from django.urls.resolvers import URLResolver
|
| 14 |
+
from typing import Dict
|
| 15 |
+
from typing import List
|
| 16 |
+
from typing import Optional
|
| 17 |
+
from django.urls.resolvers import URLPattern
|
| 18 |
+
from typing import Tuple
|
| 19 |
+
from typing import Union
|
| 20 |
+
from re import Pattern
|
| 21 |
+
|
| 22 |
+
from django import VERSION as DJANGO_VERSION
|
| 23 |
+
|
| 24 |
+
if DJANGO_VERSION >= (2, 0):
|
| 25 |
+
from django.urls.resolvers import RoutePattern
|
| 26 |
+
else:
|
| 27 |
+
RoutePattern = None
|
| 28 |
+
|
| 29 |
+
try:
|
| 30 |
+
from django.urls import get_resolver
|
| 31 |
+
except ImportError:
|
| 32 |
+
from django.core.urlresolvers import get_resolver
|
| 33 |
+
|
| 34 |
+
|
| 35 |
+
def get_regex(resolver_or_pattern):
|
| 36 |
+
# type: (Union[URLPattern, URLResolver]) -> Pattern[str]
|
| 37 |
+
"""Utility method for django's deprecated resolver.regex"""
|
| 38 |
+
try:
|
| 39 |
+
regex = resolver_or_pattern.regex
|
| 40 |
+
except AttributeError:
|
| 41 |
+
regex = resolver_or_pattern.pattern.regex
|
| 42 |
+
return regex
|
| 43 |
+
|
| 44 |
+
|
| 45 |
+
class RavenResolver:
|
| 46 |
+
_new_style_group_matcher = re.compile(
|
| 47 |
+
r"<(?:([^>:]+):)?([^>]+)>"
|
| 48 |
+
) # https://github.com/django/django/blob/21382e2743d06efbf5623e7c9b6dccf2a325669b/django/urls/resolvers.py#L245-L247
|
| 49 |
+
_optional_group_matcher = re.compile(r"\(\?\:([^\)]+)\)")
|
| 50 |
+
_named_group_matcher = re.compile(r"\(\?P<(\w+)>[^\)]+\)+")
|
| 51 |
+
_non_named_group_matcher = re.compile(r"\([^\)]+\)")
|
| 52 |
+
# [foo|bar|baz]
|
| 53 |
+
_either_option_matcher = re.compile(r"\[([^\]]+)\|([^\]]+)\]")
|
| 54 |
+
_camel_re = re.compile(r"([A-Z]+)([a-z])")
|
| 55 |
+
|
| 56 |
+
_cache = {} # type: Dict[URLPattern, str]
|
| 57 |
+
|
| 58 |
+
def _simplify(self, pattern):
|
| 59 |
+
# type: (Union[URLPattern, URLResolver]) -> str
|
| 60 |
+
r"""
|
| 61 |
+
Clean up urlpattern regexes into something readable by humans:
|
| 62 |
+
|
| 63 |
+
From:
|
| 64 |
+
> "^(?P<sport_slug>\w+)/athletes/(?P<athlete_slug>\w+)/$"
|
| 65 |
+
|
| 66 |
+
To:
|
| 67 |
+
> "{sport_slug}/athletes/{athlete_slug}/"
|
| 68 |
+
"""
|
| 69 |
+
# "new-style" path patterns can be parsed directly without turning them
|
| 70 |
+
# into regexes first
|
| 71 |
+
if (
|
| 72 |
+
RoutePattern is not None
|
| 73 |
+
and hasattr(pattern, "pattern")
|
| 74 |
+
and isinstance(pattern.pattern, RoutePattern)
|
| 75 |
+
):
|
| 76 |
+
return self._new_style_group_matcher.sub(
|
| 77 |
+
lambda m: "{%s}" % m.group(2), str(pattern.pattern._route)
|
| 78 |
+
)
|
| 79 |
+
|
| 80 |
+
result = get_regex(pattern).pattern
|
| 81 |
+
|
| 82 |
+
# remove optional params
|
| 83 |
+
# TODO(dcramer): it'd be nice to change these into [%s] but it currently
|
| 84 |
+
# conflicts with the other rules because we're doing regexp matches
|
| 85 |
+
# rather than parsing tokens
|
| 86 |
+
result = self._optional_group_matcher.sub(lambda m: "%s" % m.group(1), result)
|
| 87 |
+
|
| 88 |
+
# handle named groups first
|
| 89 |
+
result = self._named_group_matcher.sub(lambda m: "{%s}" % m.group(1), result)
|
| 90 |
+
|
| 91 |
+
# handle non-named groups
|
| 92 |
+
result = self._non_named_group_matcher.sub("{var}", result)
|
| 93 |
+
|
| 94 |
+
# handle optional params
|
| 95 |
+
result = self._either_option_matcher.sub(lambda m: m.group(1), result)
|
| 96 |
+
|
| 97 |
+
# clean up any outstanding regex-y characters.
|
| 98 |
+
result = (
|
| 99 |
+
result.replace("^", "")
|
| 100 |
+
.replace("$", "")
|
| 101 |
+
.replace("?", "")
|
| 102 |
+
.replace("\\A", "")
|
| 103 |
+
.replace("\\Z", "")
|
| 104 |
+
.replace("//", "/")
|
| 105 |
+
.replace("\\", "")
|
| 106 |
+
)
|
| 107 |
+
|
| 108 |
+
return result
|
| 109 |
+
|
| 110 |
+
def _resolve(self, resolver, path, parents=None):
|
| 111 |
+
# type: (URLResolver, str, Optional[List[URLResolver]]) -> Optional[str]
|
| 112 |
+
|
| 113 |
+
match = get_regex(resolver).search(path) # Django < 2.0
|
| 114 |
+
|
| 115 |
+
if not match:
|
| 116 |
+
return None
|
| 117 |
+
|
| 118 |
+
if parents is None:
|
| 119 |
+
parents = [resolver]
|
| 120 |
+
elif resolver not in parents:
|
| 121 |
+
parents = parents + [resolver]
|
| 122 |
+
|
| 123 |
+
new_path = path[match.end() :]
|
| 124 |
+
for pattern in resolver.url_patterns:
|
| 125 |
+
# this is an include()
|
| 126 |
+
if not pattern.callback:
|
| 127 |
+
match_ = self._resolve(pattern, new_path, parents)
|
| 128 |
+
if match_:
|
| 129 |
+
return match_
|
| 130 |
+
continue
|
| 131 |
+
elif not get_regex(pattern).search(new_path):
|
| 132 |
+
continue
|
| 133 |
+
|
| 134 |
+
try:
|
| 135 |
+
return self._cache[pattern]
|
| 136 |
+
except KeyError:
|
| 137 |
+
pass
|
| 138 |
+
|
| 139 |
+
prefix = "".join(self._simplify(p) for p in parents)
|
| 140 |
+
result = prefix + self._simplify(pattern)
|
| 141 |
+
if not result.startswith("/"):
|
| 142 |
+
result = "/" + result
|
| 143 |
+
self._cache[pattern] = result
|
| 144 |
+
return result
|
| 145 |
+
|
| 146 |
+
return None
|
| 147 |
+
|
| 148 |
+
def resolve(
|
| 149 |
+
self,
|
| 150 |
+
path, # type: str
|
| 151 |
+
urlconf=None, # type: Union[None, Tuple[URLPattern, URLPattern, URLResolver], Tuple[URLPattern]]
|
| 152 |
+
):
|
| 153 |
+
# type: (...) -> Optional[str]
|
| 154 |
+
resolver = get_resolver(urlconf)
|
| 155 |
+
match = self._resolve(resolver, path)
|
| 156 |
+
return match
|
| 157 |
+
|
| 158 |
+
|
| 159 |
+
LEGACY_RESOLVER = RavenResolver()
|