Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fix json object with invalid value and new features #4

Merged
merged 8 commits into from
Aug 10, 2021
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
7 changes: 4 additions & 3 deletions raven/init.lua
Original file line number Diff line number Diff line change
Expand Up @@ -137,7 +137,8 @@ function _M.new(conf)
tags = conf.tags or nil,
extra = conf.extra or nil,
environment = conf.environment or nil,
release = conf.release or nil
release = conf.release or nil,
server_name = conf.server_name or nil
}

return setmetatable(obj, raven_mt)
Expand Down Expand Up @@ -339,8 +340,8 @@ function raven_mt:send_report(json, conf)
end

json.request = _M.get_request_data()
json.server_name = _M.get_server_name()
json.releae = _M.get_release()
json.server_name = self.server_name or _M.get_server_name()
json.release = self.release or _M.get_release()

local json_str = json_encode(json)
local ok, err = self.sender:send(json_str)
Expand Down
37 changes: 37 additions & 0 deletions raven/senders/ngx.lua
Original file line number Diff line number Diff line change
Expand Up @@ -240,4 +240,41 @@ function _M.get_server_name()
return "undefined"
end

--- Returns the value of the `request_data` variable if possible.
-- Otherwise (wrong phase), this will return {}.
--
-- It is intended to be used as a `get_request_data` override on the main raven
-- instance.
--
-- @usage
-- local raven_ngx = require("raven.senders.ngx")
-- local rvn = raven.new(...)
-- rvn.get_request_data = raven_ngx.get_request_data
function _M.get_request_data()
local phase = ngx.get_phase()
-- the ngx.var.* API is not available in all contexts
if phase == "set" or
phase == "rewrite" or
phase == "access" or
phase == "content" or
phase == "header_filter" or
phase == "body_filter" or
phase == "log"
then
return {
caller = "nginx",
method = ngx.var.request_method or nil,
host = ngx.var.http_host or nil,
url = ngx.var.request_uri or nil,
query_string = ngx.var.query_string or nil,
env = {
REMOTE_ADDR = ngx.var.remote_addr or nil,
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This is great! I've been meaning to add this. :)

},
}
end
return {
caller = "nginx",
}
end

return _M