I'm unable to access last_event_id of SentryAsgiMiddleware on exception handler in Starlette framework.
from sentry_sdk import last_event_id
from sentry_sdk.integrations.asgi import SentryAsgiMiddleware
from starlette.applications import Starlette
from starlette.responses import JSONResponse
from starlette.routing import Route
async def test_endpoint(request):
raise RuntimeError("test")
def exception_handler(*args, **kwargs):
return JSONResponse({"last_event_id": last_event_id()})
app = Starlette(
routes=[Route('/', test_endpoint)],
exception_handlers={
Exception: exception_handler,
}
)
app.add_middleware(SentryAsgiMiddleware)
the problem is probably with usage of Hub's context manager in SentryAsgiMiddleware._run_app() - after throwing exception you are clearing local ContextVar so last_event_id function tries to access wrong Hub instance.
I'm unable to access
last_event_idofSentryAsgiMiddlewareon exception handler inStarletteframework.the problem is probably with usage of Hub's context manager in
SentryAsgiMiddleware._run_app()- after throwing exception you are clearing localContextVarsolast_event_idfunction tries to access wrong Hub instance.