Get event_id in Pyramid exception view


I’d like to return a json message with sentry event_id field as a body of 500 response. How could this be done? Ma exception view looks as follow:

@exception_view_config(Exception, renderer="json")
def exception_view(e: Exception, request: IRequest):
    request.response.status = HTTPStatus.INTERNAL_SERVER_ERROR
    return {"log_id": sentry_event_id}  # where event id is stored?

Thanks in advance!

You should be able to call sentry_sdk.last_event_id() to get that ID

Unfortunately I get null (but the event is sent to Sentry) - it makes me think that the event is sent after the response is served

Ah yes you’re right… I’ve filed a bug here:

I’ll try to find a workaround then, thanks!