当在调用堆栈的根部捕获引发的异常时,我可以在 Sentry 中看到调用堆栈每个级别的整个上下文。
但是,当我使用 captureMessage() 时,我在 Sentry 中看不到任何上下文。
如果我像下面的代码一样使用 captureException() ,我只能看到调用堆栈的顶部。
try:
raise Exception('Breakpoint!')
except:
raven_client.captureException()
Run Code Online (Sandbox Code Playgroud)
换句话说,我想在 Sentry 中看到带有完整堆栈跟踪和上下文的记录消息。
我正在尝试部署一个哨兵安装来捕获我的应用程序中的错误,但不知怎的,我真的不明白如何做到这一点。
我有这个示例应用程序:
const express = require('express');
const app = express();
var Raven = require('raven');
Raven.config('http://6c4b87dasdasdf3ecca9@logs.ekaf.com/7').install();
app.use(Raven.requestHandler());
app.get('/', function mainHandler(req, res) {
throw new Error('Broke!');
});
app.use(Raven.errorHandler());
app.use(function onError(err, req, res, next) {
res.statusCode = 500;
res.end(res.sentry + '\n');
});
const PORT = process.env.PORT || 443;
app.listen(PORT, () => {
console.log(`Server is listening on port ${PORT}`);
});
app.get('/OK', (req, res, next) => {
res.send('route OK');
});
app.get('/KO', (req, res, next) => {
res.send(blabla);
});
Run Code Online (Sandbox Code Playgroud)
Sentry 完美地记录了路线上的错误/,但没有记录/KO路线上的任何内容。我想让它记录节点控制台中可能出现的所有错误,而不使用throw …
上周我使用这个 helm Chart stable/sentry在 kubernetes 上部署了哨兵。
Pod 工作正常,但我无法访问该网站,每次访问端点时它都会崩溃。
我检查了worker、sentry-web 和 postgres pod 的日志并看到了这一点。
这是网站 Pod 的日志:
self._result_cache = list(self.iterator())
File "/usr/local/lib/python2.7/site-packages/django/db/models/query.py", line 220, in iterator
for row in compiler.results_iter():
File "/usr/local/lib/python2.7/site-packages/django/db/models/sql/compiler.py", line 713, in results_iter
for rows in self.execute_sql(MULTI):
File "/usr/local/lib/python2.7/site-packages/django/db/models/sql/compiler.py", line 786, in execute_sql
cursor.execute(sql, params)
File "/usr/local/lib/python2.7/site-packages/sentry_sdk/integrations/django/__init__.py", line 396, in execute
return real_execute(self, sql, params)
File "/usr/local/lib/python2.7/site-packages/django/db/backends/util.py", line 53, in execute
return self.cursor.execute(sql, params)
File "/usr/local/lib/python2.7/site-packages/django/db/utils.py", line 99, in __exit__
six.reraise(dj_exc_type, dj_exc_value, traceback)
File "/usr/local/lib/python2.7/site-packages/django/db/backends/util.py", line 53, …Run Code Online (Sandbox Code Playgroud) 我必须使用 2 个不同的 SDK,它们应该报告崩溃。一个是 Firebase Crashlytics,另一个是 Sentry。我在公司需要的第二个用于不同的工具。使用 Firebase,我总体上有一个更好的概述。
我现在的问题是,我只看到 Firebase 中的崩溃,而 Sentry 中看不到。如果我自己创建了一个崩溃,那么它会出现在两者中。我不明白发生了什么。
我所知道的是,当应用程序崩溃时,操作系统会创建报告,并且应用程序中的 SDK 会在应用程序下次启动时进行检查。
对我来说,看起来 Firebase 捕获了崩溃报告而 Sentry 没有得到它。但是为什么我可以在两者中看到我自己创建的崩溃?
您是否有在一个项目中使用这两种框架的经验?
来自https://flutter.dev/docs/cookbook/maintenance/error-reporting,
runZoned<Future<void>>(() async {
runApp(CrashyApp());
}, onError: (error, stackTrace) {
// Whenever an error occurs, call the `_reportError` function. This sends
// Dart errors to the dev console or Sentry depending on the environment.
_reportError(error, stackTrace);
});
Run Code Online (Sandbox Code Playgroud)
但我的 IDE 说onError已弃用。
解决这个问题的正确方法是什么?我无法提供有关 runZonedGuarded 的任何示例。
我们在很多项目中使用 Laravel(5.x 到 7.x),并且全部与 Sentry 集成。
在某些边缘情况下,我们需要捕获一些可恢复的异常,以允许页面流使用回退继续进行,但我们也希望将这些捕获的异常记录到哨兵。
我找不到手动登录 Sentry 的有记录或无记录的方法。
有没有办法将已经捕获的异常记录到哨兵?
我正在使用 SentryBundle 将 Sentry 集成到我的 Symfony 应用程序中。
我不想记录“NotFoundExceptions”,所以我这样配置了捆绑包:
sentry:
dsn: '%env(SENTRY_DSN)%'
register_error_listener: false # Disables the ErrorListener
monolog:
error_handler:
enabled: true
level: error
messenger:
enabled: true # flushes Sentry messages at the end of each message handling
capture_soft_fails: true # captures exceptions marked for retry too
options:
environment: '%kernel.environment%'
# release: '%env(VERSION)%' #your app version
excluded_exceptions:
- Symfony\Component\HttpKernel\Exception\NotFoundHttpException
Run Code Online (Sandbox Code Playgroud)
不幸的是,这似乎还不够,因为异常继续记录在 Sentry 中。
我究竟做错了什么?
我正在使用 docker-compose 作为哨兵本地安装的一部分。
下面是我的 docker-compose.yml 的 nginx 部分的片段。这是提供给我的 nginx 容器配置。您会注意到它有一个现有的卷安装。
nginx:
<< : *restart_policy
ports:
- '$SENTRY_BIND:80/tcp'
image: 'nginx'
volumes:
- type: bind
read_only: true
source: ./nginx
target: /etc/nginx
depends_on:
- web
- relay
Run Code Online (Sandbox Code Playgroud)
问题是我需要额外的安装才能使我的 nginx 配置正常工作。我需要能够安装 SSL 证书。当我对 nginx 部分进行以下修改时......
nginx:
<< : *restart_policy
ports:
- '$SENTRY_BIND:80/tcp'
image: 'nginx'
volumes:
- type: bind
read_only: true
source: ./nginx
target: /etc/nginx
- type: bind
read_only: true
source: ./certs
target: /etc/nginx/certs
depends_on:
- web
- relay
relay:
Run Code Online (Sandbox Code Playgroud)
...使用 docker-compose up -d 时出现以下错误: …
我最近将 Bull 添加到我的项目中,以卸载诸如将文档同步到第三方服务之类的事情,一切都运行良好,除了处理作业时发生的错误不会最终出现在 Sentry 中。他们只登录作业本身,但由于我们在多个配置上运行应用程序,这意味着我必须不断监视所有这些实例是否存在作业处理错误。
我知道我可以向处理器添加错误处理程序,但我已经有很多处理器了,所以我更喜欢另一个更全局的解决方案
有什么方法可以确保这些错误也发送到 Sentry 吗?
每次发生错误/异常时,我一直尝试.log从 python 发送一个“”文件附件到哨兵,但到目前为止没有成功。Sentry不提供python的附件文档,所以我一直在阅读java附件示例(https://docs.sentry.io/platforms/java/enriching-events/attachments/),这是
import io.sentry.Sentry;
import io.sentry.Attachment;
Attachment fileAttachment = new Attachment("your/path/file.log");
// Global Scope
Sentry.configureScope(scope -> {
scope.addAttachment(fileAttachment);
});
// Clear all attachments in the global Scope
Sentry.configureScope(scope -> {
scope.clearAttachments();
});
// Local Scope
Sentry.withScope(scope -> {
scope.addAttachment(fileAttachment);
Sentry.captureMessage("my message");
});
Run Code Online (Sandbox Code Playgroud)
尝试使用sentry_sdk( https://github.com/getsentry/sentry-python/tree/master/sentry_sdk)在python中进行类似的转换,我的代码是:
from sentry_sdk.scope import Scope
from sentry_sdk import configure_scope, push_scope
scope=Scope()
configure_scope(lambda scope: scope.add_attachment(path="sentry.log"))
push_scope(lambda scope: scope.add_attachment(path="sentry.log"))
Run Code Online (Sandbox Code Playgroud)
ps 在 python 中,Attachment()对象是在内部创建的scope.add_attachment(),因此不需要显式赋值。我也尝试过push_scope()但是没有太大效果。
对此问题的任何帮助表示赞赏。