我已将Sentry集成到Ruby On Rails
应用程序中,并且希望在发生特定情况时发送自定义事件,我可以使用
Raven.send_event({:message => 'Custom event'})
我如何发送与此相关的其他信息。我需要发送例如user_id
,email_id
,login_name
和其他自定义参数。
答案 0 :(得分:1)
您可以使用Raven.user_context
方法将user_context设置为raven
您可以编写一种方法来在Application Controller中设置上下文,并在操作前调用它
例如
Raven.user_context(
# a unique ID which represents this user
id: current_user.id, # 1
# the actor's email address, if available
email: current_user.email, # "example@example.org"
# the actor's username, if available
username: current_user.username, # "foo"
# the actor's IP address, if available
ip_address: request.ip # '127.0.0.1'
)
您可以在应用程序控制器中编写为
class ApplicationController < ActionController::Base
before_action :set_raven_context, if: proc { Rails.env.production? } //If you want to set only in prod
def set_raven_context
Raven.user_context(
# a unique ID which represents this user
id: current_user.id, # 1
# the actor's email address, if available
email: current_user.email, # "example@example.org"
# the actor's username, if available
username: current_user.username, # "foo"
# the actor's IP address, if available
ip_address: request.ip # '127.0.0.1'
)
#You can also set extra context using `Raven.extra_context`
Raven.extra_context app: url, environment: Rails.env, time: Time.now
end
end
答案 1 :(得分:0)
对于遇到类似问题的任何人,我设法通过在密钥extra
下指定要发送给哨兵以进行进一步调试的任何其他密钥
Raven.capture_message "custom message",
logger: 'logger',
extra: {
time_at: Time.now
},
tags: {
env: Rails.env
}