|
@@ -28,6 +28,8 @@ from sentry.utils.rust import RustInfoIntegration
|
|
|
|
|
|
# Can't import models in utils because utils should be the bottom of the food chain
|
|
|
if TYPE_CHECKING:
|
|
|
+ from sentry_sdk.types import Event, Hint
|
|
|
+
|
|
|
from sentry.models.organization import Organization
|
|
|
from sentry.services.hybrid_cloud.organization import RpcOrganization
|
|
|
|
|
@@ -199,7 +201,7 @@ def traces_sampler(sampling_context):
|
|
|
return float(settings.SENTRY_BACKEND_APM_SAMPLING or 0)
|
|
|
|
|
|
|
|
|
-def before_send_transaction(event, _):
|
|
|
+def before_send_transaction(event: Event, _: Hint) -> Event | None:
|
|
|
# Discard generic redirects.
|
|
|
# This condition can be removed once https://github.com/getsentry/team-sdks/issues/48 is fixed.
|
|
|
if (
|
|
@@ -210,14 +212,14 @@ def before_send_transaction(event, _):
|
|
|
|
|
|
# Occasionally the span limit is hit and we drop spans from transactions, this helps find transactions where this occurs.
|
|
|
num_of_spans = len(event["spans"])
|
|
|
- event["tags"]["spans_over_limit"] = num_of_spans >= 1000
|
|
|
+ event["tags"]["spans_over_limit"] = str(num_of_spans >= 1000)
|
|
|
if not event["measurements"]:
|
|
|
event["measurements"] = {}
|
|
|
event["measurements"]["num_of_spans"] = {"value": num_of_spans}
|
|
|
return event
|
|
|
|
|
|
|
|
|
-def before_send(event, _):
|
|
|
+def before_send(event: Event, _: Hint) -> Event | None:
|
|
|
if event.get("tags"):
|
|
|
if settings.SILO_MODE:
|
|
|
event["tags"]["silo_mode"] = str(settings.SILO_MODE)
|
|
@@ -270,8 +272,6 @@ def configure_sdk():
|
|
|
"""
|
|
|
Setup and initialize the Sentry SDK.
|
|
|
"""
|
|
|
- assert sentry_sdk.Hub.main.client is None
|
|
|
-
|
|
|
sdk_options, dsns = _get_sdk_options()
|
|
|
|
|
|
internal_project_key = get_project_key()
|
|
@@ -566,21 +566,20 @@ def check_current_scope_transaction(
|
|
|
Note: Ignores scope `transaction` values with `source = "custom"`, indicating a value which has
|
|
|
been set maunually.
|
|
|
"""
|
|
|
+ scope = sentry_sdk.Scope.get_current_scope()
|
|
|
+ transaction_from_request = get_transaction_name_from_request(request)
|
|
|
|
|
|
- with configure_scope() as scope:
|
|
|
- transaction_from_request = get_transaction_name_from_request(request)
|
|
|
-
|
|
|
- if (
|
|
|
- scope._transaction is not None
|
|
|
- and scope._transaction != transaction_from_request
|
|
|
- and scope._transaction_info.get("source") != "custom"
|
|
|
- ):
|
|
|
- return {
|
|
|
- "scope_transaction": scope._transaction,
|
|
|
- "request_transaction": transaction_from_request,
|
|
|
- }
|
|
|
- else:
|
|
|
- return None
|
|
|
+ if (
|
|
|
+ scope._transaction is not None
|
|
|
+ and scope._transaction != transaction_from_request
|
|
|
+ and scope._transaction_info.get("source") != "custom"
|
|
|
+ ):
|
|
|
+ return {
|
|
|
+ "scope_transaction": scope._transaction,
|
|
|
+ "request_transaction": transaction_from_request,
|
|
|
+ }
|
|
|
+ else:
|
|
|
+ return None
|
|
|
|
|
|
|
|
|
def capture_exception_with_scope_check(
|
|
@@ -679,7 +678,7 @@ def bind_ambiguous_org_context(
|
|
|
|
|
|
def set_measurement(measurement_name, value, unit=None):
|
|
|
try:
|
|
|
- transaction = sentry_sdk.Hub.current.scope.transaction
|
|
|
+ transaction = sentry_sdk.Scope.get_current_scope().transaction
|
|
|
if transaction is not None:
|
|
|
transaction.set_measurement(measurement_name, value, unit)
|
|
|
except Exception:
|