diff --git a/sentry_sdk/__init__.py b/sentry_sdk/__init__.py index 7fd92aaafd..6c44867476 100644 --- a/sentry_sdk/__init__.py +++ b/sentry_sdk/__init__.py @@ -33,7 +33,6 @@ "get_traceparent", "is_initialized", "isolation_scope", - "last_event_id", "new_scope", "push_scope", "set_context", diff --git a/sentry_sdk/api.py b/sentry_sdk/api.py index 7bddda52b2..b56e0873df 100644 --- a/sentry_sdk/api.py +++ b/sentry_sdk/api.py @@ -52,7 +52,6 @@ def overload(x): "get_traceparent", "is_initialized", "isolation_scope", - "last_event_id", "new_scope", "push_scope", "set_context", @@ -282,12 +281,6 @@ def flush( return Scope.get_client().flush(timeout=timeout, callback=callback) -@scopemethod -def last_event_id(): - # type: () -> Optional[str] - return Scope.get_current_scope().last_event_id() - - @scopemethod def start_span( span=None, # type: Optional[Span] diff --git a/sentry_sdk/scope.py b/sentry_sdk/scope.py index 395f55d635..5aac2f6ac9 100644 --- a/sentry_sdk/scope.py +++ b/sentry_sdk/scope.py @@ -156,7 +156,6 @@ class Scope(object): "_propagation_context", "client", "_type", - "_last_event_id", ) def __init__(self, ty=None, client=None): @@ -168,7 +167,6 @@ def __init__(self, ty=None, client=None): self._name = None # type: Optional[str] self._propagation_context = None # type: Optional[Dict[str, Any]] - self._last_event_id = None # type: Optional[str] # deprecated self.client = NonRecordingClient() # type: sentry_sdk.client.BaseClient @@ -281,16 +279,6 @@ def get_global_scope(cls): return _global_scope - def last_event_id(self): - # type: () -> Optional[str] - """ - .. deprecated:: 2.0.0 - This function is deprecated and will be removed in a future release. - - Returns the last event ID. - """ - return self._last_event_id - @classmethod def _merge_scopes(cls, additional_scope=None, additional_scope_kwargs=None): # type: (Optional[Scope], Optional[Dict[str, Any]]) -> Scope @@ -1056,15 +1044,7 @@ def capture_event(self, event, hint=None, scope=None, **scope_kwargs): """ scope = Scope._merge_scopes(scope, scope_kwargs) - last_event_id = Scope.get_client().capture_event( - event=event, hint=hint, scope=scope - ) - - is_transaction = event.get("type") == "transaction" - if last_event_id is not None and not is_transaction: - self._last_event_id = last_event_id - - return last_event_id + return Scope.get_client().capture_event(event=event, hint=hint, scope=scope) def capture_message(self, message, level=None, scope=None, **scope_kwargs): # type: (str, Optional[str], Optional[Scope], Any) -> Optional[str] diff --git a/tests/integrations/django/myapp/views.py b/tests/integrations/django/myapp/views.py index 890899300f..5bce71a367 100644 --- a/tests/integrations/django/myapp/views.py +++ b/tests/integrations/django/myapp/views.py @@ -118,7 +118,7 @@ def mylogin(request): @csrf_exempt def handler500(request): - return HttpResponseServerError("Sentry error: %s" % sentry_sdk.last_event_id()) + return HttpResponseServerError("Sentry error.") class ClassBasedView(ListView): diff --git a/tests/integrations/falcon/test_falcon.py b/tests/integrations/falcon/test_falcon.py index 236cbf5a67..d5cbb42c65 100644 --- a/tests/integrations/falcon/test_falcon.py +++ b/tests/integrations/falcon/test_falcon.py @@ -316,7 +316,7 @@ def on_get(self, req, resp): def http500_handler(ex, req, resp, params): sentry_sdk.capture_exception(ex) - resp.media = {"message": "Sentry error: %s" % sentry_sdk.last_event_id()} + resp.media = {"message": "Sentry error."} app.add_error_handler(Exception, http500_handler) diff --git a/tests/integrations/flask/test_flask.py b/tests/integrations/flask/test_flask.py index 93eb6b41f9..7e59338267 100644 --- a/tests/integrations/flask/test_flask.py +++ b/tests/integrations/flask/test_flask.py @@ -26,7 +26,6 @@ configure_scope, capture_message, capture_exception, - last_event_id, Hub, ) from sentry_sdk.integrations.logging import LoggingIntegration @@ -599,7 +598,7 @@ def wsgi_app(environ, start_response): assert event["exception"]["values"][0]["mechanism"]["type"] == "wsgi" -def test_500(sentry_init, capture_events, app): +def test_500(sentry_init, app): sentry_init(integrations=[flask_sentry.FlaskIntegration()]) app.debug = False @@ -611,15 +610,12 @@ def index(): @app.errorhandler(500) def error_handler(err): - return "Sentry error: %s" % last_event_id() - - events = capture_events() + return "Sentry error." client = app.test_client() response = client.get("/") - (event,) = events - assert response.data.decode("utf-8") == "Sentry error: %s" % event["event_id"] + assert response.data.decode("utf-8") == "Sentry error." def test_error_in_errorhandler(sentry_init, capture_events, app): diff --git a/tests/integrations/quart/test_quart.py b/tests/integrations/quart/test_quart.py index 0f693088c9..d74f690952 100644 --- a/tests/integrations/quart/test_quart.py +++ b/tests/integrations/quart/test_quart.py @@ -9,7 +9,6 @@ configure_scope, capture_message, capture_exception, - last_event_id, ) from sentry_sdk.integrations.logging import LoggingIntegration import sentry_sdk.integrations.quart as quart_sentry @@ -313,7 +312,7 @@ def foo(): @pytest.mark.asyncio -async def test_500(sentry_init, capture_events, app): +async def test_500(sentry_init, app): sentry_init(integrations=[quart_sentry.QuartIntegration()]) @app.route("/") @@ -322,17 +321,12 @@ async def index(): @app.errorhandler(500) async def error_handler(err): - return "Sentry error: %s" % last_event_id() - - events = capture_events() + return "Sentry error." client = app.test_client() response = await client.get("/") - (event,) = events - assert (await response.get_data(as_text=True)) == "Sentry error: %s" % event[ - "event_id" - ] + assert (await response.get_data(as_text=True)) == "Sentry error." @pytest.mark.asyncio diff --git a/tests/integrations/starlette/test_starlette.py b/tests/integrations/starlette/test_starlette.py index eddf0dc957..4fad78370d 100644 --- a/tests/integrations/starlette/test_starlette.py +++ b/tests/integrations/starlette/test_starlette.py @@ -10,7 +10,7 @@ import pytest -from sentry_sdk import last_event_id, capture_exception, capture_message +from sentry_sdk import capture_message from sentry_sdk.integrations.asgi import SentryAsgiMiddleware from sentry_sdk.integrations.starlette import ( StarletteIntegration, @@ -815,30 +815,6 @@ def test_middleware_partial_receive_send(sentry_init, capture_events): idx += 1 -def test_last_event_id(sentry_init, capture_events): - sentry_init( - integrations=[StarletteIntegration()], - ) - events = capture_events() - - def handler(request, exc): - capture_exception(exc) - return starlette.responses.PlainTextResponse(last_event_id(), status_code=500) - - app = starlette_app_factory(debug=False) - app.add_exception_handler(500, handler) - - client = TestClient(SentryAsgiMiddleware(app), raise_server_exceptions=False) - response = client.get("/custom_error") - assert response.status_code == 500 - - event = events[0] - assert response.content.strip().decode("ascii") == event["event_id"] - (exception,) = event["exception"]["values"] - assert exception["type"] == "Exception" - assert exception["value"] == "Too Hot" - - def test_legacy_setup( sentry_init, capture_events, diff --git a/tests/integrations/starlite/test_starlite.py b/tests/integrations/starlite/test_starlite.py index 0412133f5e..5f1b199be6 100644 --- a/tests/integrations/starlite/test_starlite.py +++ b/tests/integrations/starlite/test_starlite.py @@ -2,16 +2,14 @@ import pytest -from sentry_sdk import capture_exception, capture_message, last_event_id +from sentry_sdk import capture_message from sentry_sdk.integrations.starlite import StarliteIntegration from typing import Any, Dict -import starlite from starlite import AbstractMiddleware, LoggingConfig, Starlite, get, Controller from starlite.middleware import LoggingMiddlewareConfig, RateLimitConfig from starlite.middleware.session.memory_backend import MemoryBackendConfig -from starlite.status_codes import HTTP_500_INTERNAL_SERVER_ERROR from starlite.testing import TestClient @@ -291,27 +289,3 @@ def test_middleware_partial_receive_send(sentry_init, capture_events): assert span["op"] == expected[idx]["op"] assert span["description"].startswith(expected[idx]["description"]) assert span["tags"] == expected[idx]["tags"] - - -def test_last_event_id(sentry_init, capture_events): - sentry_init( - integrations=[StarliteIntegration()], - ) - events = capture_events() - - def handler(request, exc): - capture_exception(exc) - return starlite.response.Response(last_event_id(), status_code=500) - - app = starlite_app_factory( - debug=False, exception_handlers={HTTP_500_INTERNAL_SERVER_ERROR: handler} - ) - - client = TestClient(app, raise_server_exceptions=False) - response = client.get("/custom_error") - assert response.status_code == 500 - event = events[-1] - assert response.content.strip().decode("ascii").strip('"') == event["event_id"] - (exception,) = event["exception"]["values"] - assert exception["type"] == "Exception" - assert exception["value"] == "Too Hot" diff --git a/tests/integrations/trytond/test_trytond.py b/tests/integrations/trytond/test_trytond.py index c4593c3060..870b6ccf96 100644 --- a/tests/integrations/trytond/test_trytond.py +++ b/tests/integrations/trytond/test_trytond.py @@ -11,7 +11,6 @@ from trytond.wsgi import app as trytond_app from werkzeug.test import Client -from sentry_sdk import last_event_id from sentry_sdk.integrations.trytond import TrytondWSGIIntegration @@ -79,13 +78,12 @@ def _(request): @pytest.mark.skipif( trytond.__version__.split(".") < ["5", "4"], reason="At least Trytond-5.4 required" ) -def test_rpc_error_page(sentry_init, app, capture_events, get_client): +def test_rpc_error_page(sentry_init, app, get_client): """Test that, after initializing the Trytond-SentrySDK integration a custom error handler can be registered to the Trytond WSGI app so as to inform the event identifiers to the Tryton RPC client""" sentry_init(integrations=[TrytondWSGIIntegration()]) - events = capture_events() @app.route("/rpcerror", methods=["POST"]) def _(request): @@ -96,8 +94,7 @@ def _(app, request, e): if isinstance(e, TrytondBaseException): return else: - event_id = last_event_id() - data = TrytondUserError(str(event_id), str(e)) + data = TrytondUserError("Sentry error.", str(e)) return app.make_response(request, data) client = get_client() @@ -121,9 +118,8 @@ def _(app, request, e): "/rpcerror", content_type="application/json", data=json.dumps(_data) ) - (event,) = events (content, status, headers) = response data = json.loads(next(content)) assert status == "200 OK" assert headers.get("Content-Type") == "application/json" - assert data == dict(id=42, error=["UserError", [event["event_id"], "foo", None]]) + assert data == dict(id=42, error=["UserError", ["Sentry error.", "foo", None]]) diff --git a/tests/test_basics.py b/tests/test_basics.py index 3fab078378..8730990e15 100644 --- a/tests/test_basics.py +++ b/tests/test_basics.py @@ -16,7 +16,6 @@ capture_message, start_transaction, add_breadcrumb, - last_event_id, Hub, ) from sentry_sdk.integrations import ( @@ -108,27 +107,6 @@ def test_auto_enabling_integrations_catches_import_error(sentry_init, caplog): ), "Problem with checking auto enabling {}".format(import_string) -def test_event_id(sentry_init, capture_events): - sentry_init() - events = capture_events() - - try: - raise ValueError("aha!") - except Exception: - event_id = capture_exception() - int(event_id, 16) - assert len(event_id) == 32 - - (event,) = events - assert event["event_id"] == event_id - assert last_event_id() == event_id - - new_event_id = Hub.current.capture_event({"type": "transaction"}) - assert new_event_id is not None - assert new_event_id != event_id - assert last_event_id() == event_id - - def test_generic_mechanism(sentry_init, capture_events): sentry_init() events = capture_events()