Skip to content

Commit

Permalink
Merge branch 'master' into potel-base
Browse files Browse the repository at this point in the history
  • Loading branch information
sentrivana committed Sep 11, 2024
2 parents 3b54bbf + c635e3e commit 3610e85
Show file tree
Hide file tree
Showing 9 changed files with 92 additions and 5 deletions.
24 changes: 24 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,5 +1,29 @@
# Changelog

## 2.14.0

### Various fixes & improvements

- New `SysExitIntegration` (#3401) by @szokeasaurusrex

For more information, see the documentation for the [SysExitIntegration](https://docs.sentry.io/platforms/python/integrations/sys_exit).

- Add `SENTRY_SPOTLIGHT` env variable support (#3443) by @BYK
- Support Strawberry `0.239.2` (#3491) by @szokeasaurusrex
- Add separate `pii_denylist` to `EventScrubber` and run it always (#3463) by @sl0thentr0py
- Celery: Add wrapper for `Celery().send_task` to support behavior as `Task.apply_async` (#2377) by @divaltor
- Django: SentryWrappingMiddleware.__init__ fails if super() is object (#2466) by @cameron-simpson
- Fix data_category for sessions envelope items (#3473) by @sl0thentr0py
- Fix non-UTC timestamps (#3461) by @szokeasaurusrex
- Remove obsolete object as superclass (#3480) by @sentrivana
- Replace custom `TYPE_CHECKING` with stdlib `typing.TYPE_CHECKING` (#3447) by @dev-satoshi
- Refactor `tracing_utils.py` (#3452) by @rominf
- Explicitly export symbol in subpackages instead of ignoring (#3400) by @hartungstenio
- Better test coverage reports (#3498) by @antonpirker
- Fixed config for old coverage versions (#3504) by @antonpirker
- Fix AWS Lambda tests (#3495) by @antonpirker
- Remove broken Bottle tests (#3505) by @sentrivana

## 2.13.0

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

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


Expand Down
2 changes: 1 addition & 1 deletion sentry_sdk/consts.py
Original file line number Diff line number Diff line change
Expand Up @@ -561,4 +561,4 @@ def _get_default_options():
del _get_default_options


VERSION = "2.13.0"
VERSION = "2.14.0"
9 changes: 9 additions & 0 deletions sentry_sdk/metrics.py
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@
import sys
import threading
import time
import warnings
import zlib
from abc import ABC, abstractmethod
from contextlib import contextmanager
Expand Down Expand Up @@ -54,6 +55,14 @@
from sentry_sdk._types import MetricValue


warnings.warn(
"The sentry_sdk.metrics module is deprecated and will be removed in the next major release. "
"Sentry will reject all metrics sent after October 7, 2024. "
"Learn more: https://sentry.zendesk.com/hc/en-us/articles/26369339769883-Upcoming-API-Changes-to-Metrics",
DeprecationWarning,
stacklevel=2,
)

_in_metrics = ContextVar("in_metrics", default=False)
_set = set # set is shadowed below

Expand Down
12 changes: 11 additions & 1 deletion sentry_sdk/scope.py
Original file line number Diff line number Diff line change
Expand Up @@ -30,6 +30,7 @@
capture_internal_exception,
capture_internal_exceptions,
ContextVar,
datetime_from_isoformat,
disable_capture_event,
event_from_exception,
exc_info_from_error,
Expand Down Expand Up @@ -1252,7 +1253,16 @@ def _apply_breadcrumbs_to_event(self, event, hint, options):
event.setdefault("breadcrumbs", {}).setdefault("values", []).extend(
self._breadcrumbs
)
event["breadcrumbs"]["values"].sort(key=lambda crumb: crumb["timestamp"])

# Attempt to sort timestamps
try:
for crumb in event["breadcrumbs"]["values"]:
if isinstance(crumb["timestamp"], str):
crumb["timestamp"] = datetime_from_isoformat(crumb["timestamp"])

event["breadcrumbs"]["values"].sort(key=lambda crumb: crumb["timestamp"])
except Exception:
pass

def _apply_user_to_event(self, event, hint, options):
# type: (Event, Hint, Optional[Dict[str, Any]]) -> None
Expand Down
6 changes: 5 additions & 1 deletion sentry_sdk/tracing.py
Original file line number Diff line number Diff line change
Expand Up @@ -1605,4 +1605,8 @@ async def my_async_function():
has_tracing_enabled,
maybe_create_breadcrumbs_from_span,
)
from sentry_sdk.metrics import LocalAggregator

with warnings.catch_warnings():
# The code in this file which uses `LocalAggregator` is only called from the deprecated `metrics` module.
warnings.simplefilter("ignore", DeprecationWarning)
from sentry_sdk.metrics import LocalAggregator
9 changes: 9 additions & 0 deletions sentry_sdk/utils.py
Original file line number Diff line number Diff line change
Expand Up @@ -239,6 +239,15 @@ def format_timestamp(value):
return utctime.strftime("%Y-%m-%dT%H:%M:%S.%fZ")


def datetime_from_isoformat(value):
# type: (str) -> datetime
try:
return datetime.fromisoformat(value)
except AttributeError:
# py 3.6
return datetime.strptime(value, "%Y-%m-%dT%H:%M:%S.%f")


def event_hint_with_exc_info(exc_info=None):
# type: (Optional[ExcInfo]) -> Dict[str, Optional[ExcInfo]]
"""Creates a hint with the exc info filled in."""
Expand Down
2 changes: 1 addition & 1 deletion setup.py
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,7 @@ def get_file_text(file_name):

setup(
name="sentry-sdk",
version="2.13.0",
version="2.14.0",
author="Sentry Team and Contributors",
author_email="hello@sentry.io",
url="https://github.com/getsentry/sentry-python",
Expand Down
31 changes: 31 additions & 0 deletions tests/test_basics.py
Original file line number Diff line number Diff line change
Expand Up @@ -352,6 +352,37 @@ def test_breadcrumb_ordering(sentry_init, capture_events):
assert timestamps_from_event == sorted(timestamps)


def test_breadcrumb_ordering_different_types(sentry_init, capture_events):
sentry_init()
events = capture_events()

timestamps = [
datetime.datetime.now() - datetime.timedelta(days=10),
datetime.datetime.now() - datetime.timedelta(days=8),
datetime.datetime.now() - datetime.timedelta(days=12),
]

for i, timestamp in enumerate(timestamps):
add_breadcrumb(
message="Authenticated at %s" % timestamp,
category="auth",
level="info",
timestamp=timestamp if i % 2 == 0 else timestamp.isoformat(),
)

capture_exception(ValueError())
(event,) = events

assert len(event["breadcrumbs"]["values"]) == len(timestamps)
timestamps_from_event = [
datetime.datetime.strptime(
x["timestamp"].replace("Z", ""), "%Y-%m-%dT%H:%M:%S.%f"
)
for x in event["breadcrumbs"]["values"]
]
assert timestamps_from_event == sorted(timestamps)


def test_attachments(sentry_init, capture_envelopes):
sentry_init()
envelopes = capture_envelopes()
Expand Down

0 comments on commit 3610e85

Please sign in to comment.