禁用哨兵日志

Disable sentry logs

我的 Django 应用程序中有哨兵。并且哨兵一直在控制台打印

 [sentry] DEBUG: Discarding transaction because sampled = False
 [sentry] INFO: Discarded session update because of missing release

如何禁用此消息以及它们出现的原因?

这是在 django 中安装 sentry 的方式

sentry_sdk.init(
    dsn=os.environ.get('SENTRY_DSN_PYTHON'),
    integrations=[DjangoIntegration(), CeleryIntegration()],
    debug=False
)

关于调试标志的文档

Turns debug mode on or off. If debug is enabled SDK will attempt to print out useful debugging information if something goes wrong with sending the event. The default is always false. It's generally not recommended to turn it on in production, though turning debug mode on will not cause any safety concerns.

您看到的日志 use this flag

我猜你实际上是 运行 处于调试模式的哨兵。

也许尝试添加 SENTRY_LOG_LEVEL=WARNING 环境变量?

第三个解决方案是更改 LOGGING 中的日志级别。

这是 django 项目 from sentry.

的日志设置示例
LOGGING = {
    'default_level': 'INFO',
    'version': 1,
    'disable_existing_loggers': True,
    'handlers': {
        'null': {
            'class': 'logging.NullHandler',
        },
        'console': {
            'class': 'sentry.logging.handlers.StructLogHandler',
        },
        'internal': {
            'level': 'ERROR',
            'filters': ['sentry:internal'],
            'class': 'sentry_sdk.integrations.logging.EventHandler',
        },
        'metrics': {
            'level': 'WARNING',
            'filters': ['important_django_request'],
            'class': 'sentry.logging.handlers.MetricsLogHandler',
        },
        'django_internal': {
            'level': 'WARNING',
            'filters': ['sentry:internal', 'important_django_request'],
            'class': 'sentry_sdk.integrations.logging.EventHandler',
        },
    },
    'filters': {
        'sentry:internal': {
            '()': 'sentry.utils.sdk.SentryInternalFilter',
        },
        'important_django_request': {
            '()': 'sentry.logging.handlers.MessageContainsFilter',
            'contains': ["CSRF"]
        }
    },
    'root': {
        'level': 'NOTSET',
        'handlers': ['console', 'internal'],
    },
    # LOGGING.overridable is a list of loggers including root that will change
    # based on the overridden level defined above.
    'overridable': ['celery', 'sentry'],
    'loggers': {
        'celery': {
            'level': 'WARNING',
        },
        'sentry': {
            'level': 'INFO',
        },
        'sentry.files': {
            'level': 'WARNING',
        },
        'sentry.minidumps': {
            'handlers': ['internal'],
            'propagate': False,
        },
        'sentry.interfaces': {
            'handlers': ['internal'],
            'propagate': False,
        },
        # This only needs to go to Sentry for now.
        'sentry.similarity': {
            'handlers': ['internal'],
            'propagate': False,
        },
        'sentry.errors': {
            'handlers': ['console'],
            'propagate': False,
        },
        'sentry_sdk.errors': {
            'handlers': ['console'],
            'level': "INFO",
            'propagate': False,
        },
        'sentry.rules': {
            'handlers': ['console'],
            'propagate': False,
        },
    }
}