sentry-setup-logging by getsentry/sentry-agent-skills
npx skills add https://github.com/getsentry/sentry-agent-skills --skill sentry-setup-logging配置 Sentry 的结构化日志记录功能。
Sentry.logger 或 sentry_sdk.logger 的信息重要提示: 下面的 SDK 版本、API 名称和代码示例仅供参考。在实施前,请务必根据 docs.sentry.io 进行验证,因为 API 和最低版本可能已发生变化。
| 平台 | 最低 SDK | 启用标志 | 日志记录器 API |
|---|---|---|---|
| JavaScript | 9.41.0+ | enableLogs: true | Sentry.logger.* |
广告位招租
在这里展示您的产品或服务
触达数万 AI 开发者,精准高效
| Python | 2.35.0+ | enable_logs=True | sentry_sdk.logger.* |
| Ruby | 5.24.0+ | config.enable_logs = true | Sentry.logger.* |
grep -E '"@sentry/(nextjs|react|node|browser)"' package.json
Sentry.init({
dsn: "YOUR_DSN",
enableLogs: true,
});
integrations: [
Sentry.consoleLoggingIntegration({ levels: ["warn", "error"] }),
],
Sentry.logger.info("User logged in", { userId: "123" });
Sentry.logger.error("Payment failed", { orderId: "456", amount: 99.99 });
// 模板字面量(创建可搜索的属性)
Sentry.logger.info(Sentry.logger.fmt`User ${userId} purchased ${productName}`);
| 库 | 集成 | 最低 SDK |
|---|---|---|
| Consola | Sentry.createConsolaReporter() | 10.12.0+ |
| Console capture | Sentry.consoleLoggingIntegration() | 10.13.0+ |
pip show sentry-sdk | grep Version
sentry_sdk.init(
dsn="YOUR_DSN",
enable_logs=True,
)
from sentry_sdk.integrations.logging import LoggingIntegration
integrations=[LoggingIntegration(sentry_logs_level=logging.INFO)]
from sentry_sdk import logger as sentry_logger
sentry_logger.info("User logged in: {user_id}", user_id="123")
sentry_logger.error("Payment failed", order_id="456", amount=99.99)
from sentry_sdk.integrations.loguru import LoguruIntegration
integrations=[LoguruIntegration(sentry_logs_level=LoggingLevels.INFO.value)]
bundle show sentry-ruby
Sentry.init do |config|
config.dsn = "YOUR_DSN"
config.enable_logs = true
config.enabled_patches << :logger # 可选:捕获标准库 Logger
end
Sentry.logger.info("User logged in")
Sentry.logger.error("Payment failed. Order: %{order_id}", order_id: "456")
beforeSendLog: (log) => log.level === "info" ? null : log,
def before_send_log(log, hint):
return None if log["severity_text"] == "info" else log
启用日志记录后,发出一个测试日志并检查 Sentry 日志仪表板(探索 > 日志):
Sentry.logger.info("Sentry logging test");
| 问题 | 解决方案 |
|---|---|
| 日志未出现 | 验证 SDK 版本,检查是否设置了 enableLogs/enable_logs |
| 日志过多 | 使用 beforeSendLog 进行过滤,减少捕获的级别 |
| 控制台未捕获 | 将 consoleLoggingIntegration 添加到集成数组中 |
每周安装次数
261
代码仓库
GitHub 星标数
19
首次出现
2026年1月20日
安全审计
安装于
opencode225
codex222
gemini-cli215
claude-code205
github-copilot204
cursor190
Configure Sentry's structured logging feature.
Sentry.logger or sentry_sdk.loggerImportant: The SDK versions, API names, and code samples below are examples. Always verify against docs.sentry.io before implementing, as APIs and minimum versions may have changed.
| Platform | Min SDK | Enable Flag | Logger API |
|---|---|---|---|
| JavaScript | 9.41.0+ | enableLogs: true | Sentry.logger.* |
| Python | 2.35.0+ | enable_logs=True | sentry_sdk.logger.* |
| Ruby | 5.24.0+ | config.enable_logs = true | Sentry.logger.* |
grep -E '"@sentry/(nextjs|react|node|browser)"' package.json
Sentry.init({
dsn: "YOUR_DSN",
enableLogs: true,
});
integrations: [
Sentry.consoleLoggingIntegration({ levels: ["warn", "error"] }),
],
Sentry.logger.info("User logged in", { userId: "123" });
Sentry.logger.error("Payment failed", { orderId: "456", amount: 99.99 });
// Template literals (creates searchable attributes)
Sentry.logger.info(Sentry.logger.fmt`User ${userId} purchased ${productName}`);
| Library | Integration | Min SDK |
|---|---|---|
| Consola | Sentry.createConsolaReporter() | 10.12.0+ |
| Console capture | Sentry.consoleLoggingIntegration() | 10.13.0+ |
pip show sentry-sdk | grep Version
sentry_sdk.init(
dsn="YOUR_DSN",
enable_logs=True,
)
from sentry_sdk.integrations.logging import LoggingIntegration
integrations=[LoggingIntegration(sentry_logs_level=logging.INFO)]
from sentry_sdk import logger as sentry_logger
sentry_logger.info("User logged in: {user_id}", user_id="123")
sentry_logger.error("Payment failed", order_id="456", amount=99.99)
from sentry_sdk.integrations.loguru import LoguruIntegration
integrations=[LoguruIntegration(sentry_logs_level=LoggingLevels.INFO.value)]
bundle show sentry-ruby
Sentry.init do |config|
config.dsn = "YOUR_DSN"
config.enable_logs = true
config.enabled_patches << :logger # Optional: capture stdlib Logger
end
Sentry.logger.info("User logged in")
Sentry.logger.error("Payment failed. Order: %{order_id}", order_id: "456")
beforeSendLog: (log) => log.level === "info" ? null : log,
def before_send_log(log, hint):
return None if log["severity_text"] == "info" else log
After enabling logs, emit a test log and check the Sentry Logs dashboard (Explore > Logs):
Sentry.logger.info("Sentry logging test");
| Issue | Solution |
|---|---|
| Logs not appearing | Verify SDK version, check enableLogs/enable_logs is set |
| Too many logs | Use beforeSendLog to filter, reduce captured levels |
| Console not captured | Add consoleLoggingIntegration to integrations array |
Weekly Installs
261
Repository
GitHub Stars
19
First Seen
Jan 20, 2026
Security Audits
Gen Agent Trust HubPassSocketPassSnykPass
Installed on
opencode225
codex222
gemini-cli215
claude-code205
github-copilot204
cursor190
Azure 升级评估与自动化工具 - 轻松迁移 Functions 计划、托管层级和 SKU
68,100 周安装