Skip to content
Permalink

Comparing changes

Choose two branches to see what’s changed or to start a new pull request. If you need to, you can also or learn more about diff comparisons.

Open a pull request

Create a new pull request by comparing changes across two branches. If you need to, you can also . Learn more about diff comparisons here.
base repository: getsentry/sentry-python
Failed to load repositories. Confirm that selected base ref is valid, then try again.
Loading
base: 2.8.0
Choose a base ref
...
head repository: getsentry/sentry-python
Failed to load repositories. Confirm that selected head ref is valid, then try again.
Loading
compare: 2.9.0
Choose a head ref
  • 12 commits
  • 24 files changed
  • 4 contributors

Commits on Jul 8, 2024

  1. Merge branch 'release/2.8.0'

    getsentry-bot committed Jul 8, 2024
    Copy the full SHA
    70b12c3 View commit details
  2. ref(transport): Improve event data category typing

    Done to more clearly define event data categories, in preparation for #3229.
    szokeasaurusrex committed Jul 8, 2024

    Verified

    This commit was signed with the committer’s verified signature.
    szokeasaurusrex Daniel Szoke
    Copy the full SHA
    9b6a718 View commit details
  3. test: Fix non-idempotent test

    Fix `tests/test_basic.py::test_event_processor_drop_records_client_report` so that the test is idempotent on failure. Previously, the test was only idempotent on success; if the test failed, it would cause many other unrelated tests to fail with it.
    szokeasaurusrex committed Jul 8, 2024

    Verified

    This commit was signed with the committer’s verified signature.
    szokeasaurusrex Daniel Szoke
    Copy the full SHA
    9c9f709 View commit details
  4. test: Introduce capture_record_lost_event_calls fixture

    `capture_record_lost_event_calls` replaces the `capture_client_reports` fixture. The fixture records calls to `Transport.record_lost_event` by noting the arguments passed to each call.
    
    This change is being introduced in preparation for #3244, which changes `Transport.record_lost_event`'s signature and behavior.
    szokeasaurusrex committed Jul 8, 2024

    Verified

    This commit was signed with the committer’s verified signature.
    szokeasaurusrex Daniel Szoke
    Copy the full SHA
    69ecd87 View commit details
  5. test(transport): Non-order-dependent discarded events assertion

    Make the `report["discarded_events"]` assertion logic (in `test_data_category_limits_reporting`) not rely on the ordering of events or any sorting logic. Done in preparation of #3244, where the sorting logic cannot be relied on anymore, since the same number of spans will be discarded as transactions.
    szokeasaurusrex committed Jul 8, 2024

    Verified

    This commit was signed with the committer’s verified signature.
    szokeasaurusrex Daniel Szoke
    Copy the full SHA
    54b32f2 View commit details

Commits on Jul 9, 2024

  1. test(sampling): Replace custom logic with `capture_record_lost_event_…

    …calls`
    
    Replace custom `record_lost_event` call capturing logic in `test_sampling.py` with the `capture_record_lost_event_calls` Pytest fixture. This change will simplify implementation of #3244.
    szokeasaurusrex committed Jul 9, 2024

    Verified

    This commit was signed with the committer’s verified signature.
    szokeasaurusrex Daniel Szoke
    Copy the full SHA
    ee84c81 View commit details
  2. feat(tracing): Record lost spans in client reports

    Also, update existing transport tests so they pass against the changes introduced in this commit.
    
    Resolves #3229
    szokeasaurusrex committed Jul 9, 2024

    Verified

    This commit was signed with the committer’s verified signature.
    szokeasaurusrex Daniel Szoke
    Copy the full SHA
    f84413d View commit details
  3. test(transport): Test new client report features

      - Add test for `record_lost_event` method's new `quantity` parameter
      - Add test for `record_lost_event` when passed a transaction item
    szokeasaurusrex committed Jul 9, 2024

    Verified

    This commit was signed with the committer’s verified signature.
    szokeasaurusrex Daniel Szoke
    Copy the full SHA
    c34a71e View commit details
  4. test(client): Add tests for dropped span client reports

    szokeasaurusrex committed Jul 9, 2024

    Verified

    This commit was signed with the committer’s verified signature.
    szokeasaurusrex Daniel Szoke
    Copy the full SHA
    79e8970 View commit details

Commits on Jul 10, 2024

  1. Improved handling of span status (#3261)

    antonpirker authored Jul 10, 2024

    Verified

    This commit was created on GitHub.com and signed with GitHub’s verified signature.
    Copy the full SHA
    b7fd54a View commit details
  2. release: 2.9.0

    getsentry-bot committed Jul 10, 2024
    Copy the full SHA
    b157369 View commit details
  3. Updated changelog

    antonpirker committed Jul 10, 2024

    Verified

    This commit was signed with the committer’s verified signature. The key has expired.
    antonpirker Anton Pirker
    Copy the full SHA
    af3c9c4 View commit details
14 changes: 14 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,5 +1,19 @@
# Changelog

## 2.9.0

### Various fixes & improvements

- ref(transport): Improve event data category typing (#3243) by @szokeasaurusrex
- ref(tracing): Improved handling of span status (#3261) by @antonpirker
- test(client): Add tests for dropped span client reports (#3244) by @szokeasaurusrex
- test(transport): Test new client report features (#3244) by @szokeasaurusrex
- feat(tracing): Record lost spans in client reports (#3244) by @szokeasaurusrex
- test(sampling): Replace custom logic with `capture_record_lost_event_calls` (#3257) by @szokeasaurusrex
- test(transport): Non-order-dependent discarded events assertion (#3255) by @szokeasaurusrex
- test(core): Introduce `capture_record_lost_event_calls` fixture (#3254) by @szokeasaurusrex
- test(core): Fix non-idempotent test (#3253) by @szokeasaurusrex

## 2.8.0

### Various fixes & improvements
2 changes: 1 addition & 1 deletion docs/conf.py
Original file line number Diff line number Diff line change
@@ -28,7 +28,7 @@
copyright = "2019-{}, Sentry Team and Contributors".format(datetime.now().year)
author = "Sentry Team and Contributors"

release = "2.8.0"
release = "2.9.0"
version = ".".join(release.split(".")[:2]) # The short X.Y version.


1 change: 1 addition & 0 deletions sentry_sdk/_types.py
Original file line number Diff line number Diff line change
@@ -155,6 +155,7 @@
"profile_chunk",
"metric_bucket",
"monitor",
"span",
]
SessionStatus = Literal["ok", "exited", "crashed", "abnormal"]

28 changes: 27 additions & 1 deletion sentry_sdk/client.py
Original file line number Diff line number Diff line change
@@ -448,6 +448,7 @@ def _prepare_event(

if scope is not None:
is_transaction = event.get("type") == "transaction"
spans_before = len(event.get("spans", []))
event_ = scope.apply_to_event(event, hint, self.options)

# one of the event/error processors returned None
@@ -457,10 +458,22 @@ def _prepare_event(
"event_processor",
data_category=("transaction" if is_transaction else "error"),
)
if is_transaction:
self.transport.record_lost_event(
"event_processor",
data_category="span",
quantity=spans_before + 1, # +1 for the transaction itself
)
return None

event = event_

spans_delta = spans_before - len(event.get("spans", []))
if is_transaction and spans_delta > 0 and self.transport is not None:
self.transport.record_lost_event(
"event_processor", data_category="span", quantity=spans_delta
)

if (
self.options["attach_stacktrace"]
and "exception" not in event
@@ -541,14 +554,27 @@ def _prepare_event(
and event.get("type") == "transaction"
):
new_event = None
spans_before = len(event.get("spans", []))
with capture_internal_exceptions():
new_event = before_send_transaction(event, hint or {})
if new_event is None:
logger.info("before send transaction dropped event")
if self.transport:
self.transport.record_lost_event(
"before_send", data_category="transaction"
reason="before_send", data_category="transaction"
)
self.transport.record_lost_event(
reason="before_send",
data_category="span",
quantity=spans_before + 1, # +1 for the transaction itself
)
else:
spans_delta = spans_before - len(new_event.get("spans", []))
if spans_delta > 0 and self.transport is not None:
self.transport.record_lost_event(
reason="before_send", data_category="span", quantity=spans_delta
)

event = new_event # type: ignore

return event
28 changes: 27 additions & 1 deletion sentry_sdk/consts.py
Original file line number Diff line number Diff line change
@@ -386,6 +386,32 @@ class SPANDATA:
"""


class SPANSTATUS:
"""
The status of a Sentry span.
See: https://develop.sentry.dev/sdk/event-payloads/contexts/#trace-context
"""

ABORTED = "aborted"
ALREADY_EXISTS = "already_exists"
CANCELLED = "cancelled"
DATA_LOSS = "data_loss"
DEADLINE_EXCEEDED = "deadline_exceeded"
FAILED_PRECONDITION = "failed_precondition"
INTERNAL_ERROR = "internal_error"
INVALID_ARGUMENT = "invalid_argument"
NOT_FOUND = "not_found"
OK = "ok"
OUT_OF_RANGE = "out_of_range"
PERMISSION_DENIED = "permission_denied"
RESOURCE_EXHAUSTED = "resource_exhausted"
UNAUTHENTICATED = "unauthenticated"
UNAVAILABLE = "unavailable"
UNIMPLEMENTED = "unimplemented"
UNKNOWN_ERROR = "unknown_error"


class OP:
ANTHROPIC_MESSAGES_CREATE = "ai.messages.create.anthropic"
CACHE_GET = "cache.get"
@@ -529,4 +555,4 @@ def _get_default_options():
del _get_default_options


VERSION = "2.8.0"
VERSION = "2.9.0"
4 changes: 2 additions & 2 deletions sentry_sdk/integrations/aiohttp.py
Original file line number Diff line number Diff line change
@@ -3,7 +3,7 @@

import sentry_sdk
from sentry_sdk.api import continue_trace
from sentry_sdk.consts import OP, SPANDATA
from sentry_sdk.consts import OP, SPANSTATUS, SPANDATA
from sentry_sdk.integrations import Integration, DidNotEnable
from sentry_sdk.integrations.logging import ignore_logger
from sentry_sdk.scope import Scope
@@ -133,7 +133,7 @@ async def sentry_app_handle(self, request, *args, **kwargs):
transaction.set_http_status(e.status_code)
raise
except (asyncio.CancelledError, ConnectionResetError):
transaction.set_status("cancelled")
transaction.set_status(SPANSTATUS.CANCELLED)
raise
except Exception:
# This will probably map to a 500 but seems like we
6 changes: 3 additions & 3 deletions sentry_sdk/integrations/arq.py
Original file line number Diff line number Diff line change
@@ -2,7 +2,7 @@

import sentry_sdk
from sentry_sdk._types import TYPE_CHECKING
from sentry_sdk.consts import OP
from sentry_sdk.consts import OP, SPANSTATUS
from sentry_sdk.integrations import DidNotEnable, Integration
from sentry_sdk.integrations.logging import ignore_logger
from sentry_sdk.scope import Scope, should_send_default_pii
@@ -119,10 +119,10 @@ def _capture_exception(exc_info):

if scope.transaction is not None:
if exc_info[0] in ARQ_CONTROL_FLOW_EXCEPTIONS:
scope.transaction.set_status("aborted")
scope.transaction.set_status(SPANSTATUS.ABORTED)
return

scope.transaction.set_status("internal_error")
scope.transaction.set_status(SPANSTATUS.INTERNAL_ERROR)

event, hint = event_from_exception(
exc_info,
4 changes: 2 additions & 2 deletions sentry_sdk/integrations/celery/__init__.py
Original file line number Diff line number Diff line change
@@ -5,7 +5,7 @@
import sentry_sdk
from sentry_sdk import isolation_scope
from sentry_sdk.api import continue_trace
from sentry_sdk.consts import OP, SPANDATA
from sentry_sdk.consts import OP, SPANSTATUS, SPANDATA
from sentry_sdk.integrations import Integration, DidNotEnable
from sentry_sdk.integrations.celery.beat import (
_patch_beat_apply_entry,
@@ -317,7 +317,7 @@ def _inner(*args, **kwargs):
origin=CeleryIntegration.origin,
)
transaction.name = task.name
transaction.set_status("ok")
transaction.set_status(SPANSTATUS.OK)

if transaction is None:
return f(*args, **kwargs)
8 changes: 4 additions & 4 deletions sentry_sdk/integrations/huey.py
Original file line number Diff line number Diff line change
@@ -4,7 +4,7 @@
import sentry_sdk
from sentry_sdk._types import TYPE_CHECKING
from sentry_sdk.api import continue_trace, get_baggage, get_traceparent
from sentry_sdk.consts import OP
from sentry_sdk.consts import OP, SPANSTATUS
from sentry_sdk.integrations import DidNotEnable, Integration
from sentry_sdk.scope import Scope, should_send_default_pii
from sentry_sdk.tracing import (
@@ -109,10 +109,10 @@ def _capture_exception(exc_info):
scope = Scope.get_current_scope()

if exc_info[0] in HUEY_CONTROL_FLOW_EXCEPTIONS:
scope.transaction.set_status("aborted")
scope.transaction.set_status(SPANSTATUS.ABORTED)
return

scope.transaction.set_status("internal_error")
scope.transaction.set_status(SPANSTATUS.INTERNAL_ERROR)
event, hint = event_from_exception(
exc_info,
client_options=Scope.get_client().options,
@@ -161,7 +161,7 @@ def _sentry_execute(self, task, timestamp=None):
source=TRANSACTION_SOURCE_TASK,
origin=HueyIntegration.origin,
)
transaction.set_status("ok")
transaction.set_status(SPANSTATUS.OK)

if not getattr(task, "_sentry_is_patched", False):
task.execute = _wrap_task_execute(task.execute)
6 changes: 3 additions & 3 deletions sentry_sdk/integrations/opentelemetry/span_processor.py
Original file line number Diff line number Diff line change
@@ -16,7 +16,7 @@
INVALID_TRACE_ID,
)
from sentry_sdk import get_client, start_transaction
from sentry_sdk.consts import INSTRUMENTER
from sentry_sdk.consts import INSTRUMENTER, SPANSTATUS
from sentry_sdk.integrations.opentelemetry.consts import (
SENTRY_BAGGAGE_KEY,
SENTRY_TRACE_KEY,
@@ -299,10 +299,10 @@ def _update_span_with_otel_status(self, sentry_span, otel_span):
return

if otel_span.status.is_ok:
sentry_span.set_status("ok")
sentry_span.set_status(SPANSTATUS.OK)
return

sentry_span.set_status("internal_error")
sentry_span.set_status(SPANSTATUS.INTERNAL_ERROR)

def _update_span_with_otel_data(self, sentry_span, otel_span):
# type: (SentrySpan, OTelSpan) -> None
6 changes: 3 additions & 3 deletions sentry_sdk/integrations/pymongo.py
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
import copy

import sentry_sdk
from sentry_sdk.consts import SPANDATA, OP
from sentry_sdk.consts import SPANSTATUS, SPANDATA, OP
from sentry_sdk.integrations import DidNotEnable, Integration
from sentry_sdk.scope import should_send_default_pii
from sentry_sdk.tracing import Span
@@ -181,7 +181,7 @@ def failed(self, event):

try:
span = self._ongoing_operations.pop(self._operation_key(event))
span.set_status("internal_error")
span.set_status(SPANSTATUS.INTERNAL_ERROR)
span.__exit__(None, None, None)
except KeyError:
return
@@ -193,7 +193,7 @@ def succeeded(self, event):

try:
span = self._ongoing_operations.pop(self._operation_key(event))
span.set_status("ok")
span.set_status(SPANSTATUS.OK)
span.__exit__(None, None, None)
except KeyError:
pass
4 changes: 2 additions & 2 deletions sentry_sdk/integrations/sqlalchemy.py
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
import sentry_sdk
from sentry_sdk._types import TYPE_CHECKING
from sentry_sdk.consts import SPANDATA
from sentry_sdk.consts import SPANSTATUS, SPANDATA
from sentry_sdk.db.explain_plan.sqlalchemy import attach_explain_plan_to_span
from sentry_sdk.integrations import Integration, DidNotEnable
from sentry_sdk.tracing_utils import add_query_source, record_sql_queries
@@ -107,7 +107,7 @@ def _handle_error(context, *args):
span = getattr(execution_context, "_sentry_sql_span", None) # type: Optional[Span]

if span is not None:
span.set_status("internal_error")
span.set_status(SPANSTATUS.INTERNAL_ERROR)

# _after_cursor_execute does not get called for crashing SQL stmts. Judging
# from SQLAlchemy codebase it does seem like any error coming into this
Loading