diff --git a/MIGRATION_GUIDE.md b/MIGRATION_GUIDE.md index a2322d504d..3e3a36a211 100644 --- a/MIGRATION_GUIDE.md +++ b/MIGRATION_GUIDE.md @@ -28,6 +28,7 @@ Looking to upgrade from Sentry SDK 2.x to 3.x? Here's a comprehensive list of wh - We changed the way we emit warnings. Deprecations will from now on be always emitted using `warnings.warn()`, while all other warnings will be emitted using `logger.warning()`. - `sentry_sdk.init()` can no longer be used as a context manager. - The `@trace` decorator doesn't accept a `template` parameter anymore. +- The option `attach_stacktrace` is now `True` by default, meaning the SDK will attach stack traces to messages. ### Logging diff --git a/sentry_sdk/consts.py b/sentry_sdk/consts.py index b55460aee7..7cd35a08a0 100644 --- a/sentry_sdk/consts.py +++ b/sentry_sdk/consts.py @@ -1300,7 +1300,7 @@ def __init__( before_send: "Optional[EventProcessor]" = None, before_breadcrumb: "Optional[BreadcrumbProcessor]" = None, debug: "Optional[bool]" = None, - attach_stacktrace: bool = False, + attach_stacktrace: bool = True, ca_certs: "Optional[str]" = None, traces_sample_rate: "Optional[float]" = None, traces_sampler: "Optional[TracesSampler]" = None, diff --git a/tests/integrations/logging/test_logging.py b/tests/integrations/logging/test_logging.py index ed069efbbb..e86b529948 100644 --- a/tests/integrations/logging/test_logging.py +++ b/tests/integrations/logging/test_logging.py @@ -37,10 +37,6 @@ def test_logging_defaults(sentry_init, capture_events): sentry_sdk.flush() - for event in events: - print(event) - print() - # Without adding the integration explicitly, only the message should be # captured (no logs), and it shouldn't have any breadcrumbs assert len(events) == 1 @@ -160,6 +156,7 @@ def test_event_logging_stack_trace( integrations=[ LoggingIntegration(breadcrumb_level=logging.INFO, event_level=logging.ERROR) ], + attach_stacktrace=False, ) events = capture_events() diff --git a/tests/test_client.py b/tests/test_client.py index 624fc7f713..09f6a5e2d5 100644 --- a/tests/test_client.py +++ b/tests/test_client.py @@ -504,6 +504,25 @@ def bar(): assert functions == ["foo", "bar"] +def test_attach_stacktrace_default(sentry_init, capture_events): + sentry_init() + events = capture_events() + + def foo(): + bar() + + def bar(): + capture_message("HI") + + foo() + + (event,) = events + (thread,) = event["threads"]["values"] + functions = [x["function"] for x in thread["stacktrace"]["frames"]] + + assert functions[-2:] == ["foo", "bar"] + + def test_attach_stacktrace_enabled(sentry_init, capture_events): sentry_init(attach_stacktrace=True) events = capture_events()