Skip to content
GitLab
菜单
为什么选择 GitLab
定价
联系销售
探索
为什么选择 GitLab
定价
联系销售
探索
登录
获取免费试用
主导航
搜索或转到…
项目
GitLab
管理
动态
成员
标记
计划
议题
议题看板
里程碑
迭代
需求
代码
合并请求
仓库
分支
提交
标签
仓库图
比较修订版本
代码片段
锁定的文件
构建
流水线
作业
流水线计划
测试用例
产物
部署
发布
Package registry
Container registry
模型注册表
运维
环境
Terraform 模块
监控
事件
服务台
分析
价值流分析
贡献者分析
CI/CD 分析
仓库分析
代码评审分析
议题分析
洞察
模型实验
效能分析
帮助
帮助
支持
GitLab 文档
比较 GitLab 各版本
社区论坛
为极狐GitLab 提交贡献
提交反馈
隐私声明
快捷键
?
新增功能
4
代码片段
群组
项目
显示更多面包屑
gitlab-cn
GitLab
提交
8fb38237
未验证
提交
8fb38237
编辑于
4 years ago
作者:
Mehmet Emin INAC
浏览文件
操作
下载
补丁
差异文件
Refactor `Gitlab::ErrorTracking.track_exception specs
上级
b9590f39
No related branches found
分支 包含提交
No related tags found
标签 包含提交
无相关合并请求
变更
1
隐藏空白变更内容
行内
左右并排
显示
1 个更改的文件
spec/lib/gitlab/error_tracking_spec.rb
+43
-52
43 个添加, 52 个删除
spec/lib/gitlab/error_tracking_spec.rb
有
43 个添加
和
52 个删除
spec/lib/gitlab/error_tracking_spec.rb
+
43
−
52
浏览文件 @
8fb38237
...
...
@@ -198,47 +198,39 @@
end
describe
'.track_exception'
do
it
'calls Raven.capture_exception'
do
expected_extras
=
{
some_other_info:
'info'
,
issue_url:
issue_url
}
let
(
:extra
)
{
{
issue_url:
issue_url
,
some_other_info:
'info'
}
}
expected_tags
=
{
correlation_id:
'cid'
}
subject
(
:track_exception
)
{
described_class
.
track_exception
(
exception
,
extra
)
}
expect
(
Raven
).
to
receive
(
:capture_exception
)
.
with
(
exception
,
tags:
a_hash_including
(
expected_tags
),
extra:
a_hash_including
(
expected_extras
))
described_class
.
track_exception
(
exception
,
issue_url:
issue_url
,
some_other_info:
'info'
)
before
do
allow
(
Raven
).
to
receive
(
:capture_exception
).
and_call_original
allow
(
Gitlab
::
ErrorTracking
::
Logger
).
to
receive
(
:error
)
end
it
'calls Raven.capture_exception'
do
track_exception
expect
(
Raven
).
to
have_received
(
:capture_exception
)
.
with
(
exception
,
tags:
a_hash_including
(
correlation_id:
'cid'
),
extra:
a_hash_including
(
some_other_info:
'info'
,
issue_url:
issue_url
))
end
it
'calls Gitlab::ErrorTracking::Logger.error with formatted payload'
do
expect
(
Gitlab
::
ErrorTracking
::
Logger
).
to
receive
(
:error
)
.
with
(
a_hash_including
(
*
expected_payload_includes
))
track_exception
described_class
.
track_exception
(
exception
,
issue_url:
issue_url
,
some_other_info:
'info'
)
expect
(
Gitlab
::
ErrorTracking
::
Logger
).
to
have_received
(
:error
)
.
with
(
a_hash_including
(
*
expected_payload_includes
))
end
context
'with filterable parameters'
do
let
(
:extra
)
{
{
test:
1
,
my_token:
'test'
}
}
it
'filters parameters'
do
expect
(
Gitlab
::
ErrorTracking
::
Logger
).
to
receive
(
:error
).
with
(
hash_including
({
'extra.test'
=>
1
,
'extra.my_token'
=>
'[FILTERED]'
}))
track_exception
described_class
.
track_exception
(
exception
,
extra
)
expect
(
Gitlab
::
ErrorTracking
::
Logger
).
to
have_received
(
:error
)
.
with
(
hash_including
({
'extra.test'
=>
1
,
'extra.my_token'
=>
'[FILTERED]'
}))
end
end
...
...
@@ -247,56 +239,55 @@
let
(
:exception
)
{
double
(
message:
'bang!'
,
sentry_extra_data:
extra_info
,
backtrace:
caller
)
}
it
'includes the extra data from the exception in the tracking information'
do
expect
(
Raven
).
to
receive
(
:capture_exception
)
.
with
(
exception
,
a_hash_including
(
extra:
a_hash_including
(
extra_info
)))
track_exception
described_class
.
track_exception
(
exception
)
expect
(
Raven
).
to
have_received
(
:capture_exception
)
.
with
(
exception
,
a_hash_including
(
extra:
a_hash_including
(
extra_info
)))
end
end
context
'the exception implements :sentry_extra_data, which returns nil'
do
let
(
:exception
)
{
double
(
message:
'bang!'
,
sentry_extra_data:
nil
,
backtrace:
caller
)
}
let
(
:extra
)
{
{
issue_url:
issue_url
}
}
it
'just includes the other extra info'
do
extra_info
=
{
issue_url:
issue_url
}
expect
(
Raven
).
to
receive
(
:capture_exception
)
.
with
(
exception
,
a_hash_including
(
extra:
a_hash_including
(
extra_info
)))
track_exception
described_class
.
track_exception
(
exception
,
extra_info
)
expect
(
Raven
).
to
have_received
(
:capture_exception
)
.
with
(
exception
,
a_hash_including
(
extra:
a_hash_including
(
extra
)))
end
end
context
'with sidekiq args'
do
it
'ensures extra.sidekiq.args is a string
'
do
extra
=
{
sidekiq:
{
'class'
=>
'PostReceive'
,
'args'
=>
[
1
,
{
'id'
=>
2
,
'name'
=>
'hello'
},
'some-value'
,
'another-value'
]
}
}
context
'when the args does not have anything sensitive
'
do
let
(
:
extra
)
{
{
sidekiq:
{
'class'
=>
'PostReceive'
,
'args'
=>
[
1
,
{
'id'
=>
2
,
'name'
=>
'hello'
},
'some-value'
,
'another-value'
]
}
}
}
expect
(
Gitlab
::
ErrorTracking
::
Logger
).
to
receive
(
:error
).
with
(
hash_including
({
'extra.sidekiq'
=>
{
'class'
=>
'PostReceive'
,
'args'
=>
[
'1'
,
'{"id"=>2, "name"=>"hello"}'
,
'some-value'
,
'another-value'
]
}
}))
it
'ensures extra.sidekiq.args is a string'
do
track_exception
described_class
.
track_exception
(
exception
,
extra
)
expect
(
Gitlab
::
ErrorTracking
::
Logger
).
to
have_received
(
:error
).
with
(
hash_including
({
'extra.sidekiq'
=>
{
'class'
=>
'PostReceive'
,
'args'
=>
[
'1'
,
'{"id"=>2, "name"=>"hello"}'
,
'some-value'
,
'another-value'
]
}
}))
end
end
it
'filters sensitive arguments before sending'
do
extra
=
{
sidekiq:
{
'class'
=>
'UnknownWorker'
,
'args'
=>
[
'sensitive string'
,
1
,
2
]
}
}
expect
(
Gitlab
::
ErrorTracking
::
Logger
).
to
receive
(
:error
).
with
(
hash_including
(
'extra.sidekiq'
=>
{
'class'
=>
'UnknownWorker'
,
'args'
=>
[
'[FILTERED]'
,
'1'
,
'2'
]
}))
context
'when the args has sensitive information'
do
let
(
:extra
)
{
{
sidekiq:
{
'class'
=>
'UnknownWorker'
,
'args'
=>
[
'sensitive string'
,
1
,
2
]
}
}
}
described_class
.
track_exception
(
exception
,
extra
)
it
'filters sensitive arguments before sending'
do
track_exception
expect
(
sentry_event
.
dig
(
'extra'
,
'sidekiq'
,
'args'
)).
to
eq
([
'[FILTERED]'
,
1
,
2
])
expect
(
sentry_event
.
dig
(
'extra'
,
'sidekiq'
,
'args'
)).
to
eq
([
'[FILTERED]'
,
1
,
2
])
expect
(
Gitlab
::
ErrorTracking
::
Logger
).
to
have_received
(
:error
).
with
(
hash_including
(
'extra.sidekiq'
=>
{
'class'
=>
'UnknownWorker'
,
'args'
=>
[
'[FILTERED]'
,
'1'
,
'2'
]
}))
end
end
end
context
'when the error is kind of an `ActiveRecord::StatementInvalid`'
do
let
(
:exception
)
{
ActiveRecord
::
StatementInvalid
.
new
(
sql: :foo
)
}
before
do
allow
(
Raven
).
to
receive
(
:capture_exception
)
end
it
'injects the sql query into extra'
do
described_class
.
track_exception
(
exception
)
track_exception
expect
(
Raven
).
to
have_received
(
:capture_exception
)
.
with
(
exception
,
a_hash_including
(
extra:
a_hash_including
(
sql: :foo
)))
...
...
此差异已折叠。
点击以展开。
预览
0%
加载中
请重试
或
添加新附件
.
取消
You are about to add
0
people
to the discussion. Proceed with caution.
先完成此消息的编辑!
保存评论
取消
想要评论请
注册
或
登录