新 SDK sentry-sdk/sentry-python 中的 SENTRY_USER_ATTRS 相当于什么?

What is the equivalent of SENTRY_USER_ATTRS in the new SDK sentry-sdk/sentry-python?

当使用 send_default_pii=True 和 flask-login 用于 Sentry Unified Python SDK 时,如何配置发送的用户数据?

文档说:

If you use flask-login and have set send_default_pii=True in your call to init, user data (current user id, email address, username) is attached to the event.

但是,这样做只会传递 ID 和电子邮件。如何配置要发送的更多属性?

在之前版本的SDK中(raven-python),可以这样配置SENTRY_USER_ATTRS

使用before_send:

def before_send(event, hint):
    try:
        user = flask_login.current_user
        user_info = event.setdefault("user", {})
        user_info["myattribute"] = user.myattribute
    except Exception:
        pass
    return event


init(..., before_send=before_send)

更多信息:https://docs.sentry.io/learn/filtering/?platform=python#before-send