Skip to content

Commit

Permalink
Merge pull request #6 from logtail/ah/context-with
Browse files Browse the repository at this point in the history
Add relevant logging contexts only for the duration of the request
  • Loading branch information
adikus authored Dec 12, 2022
2 parents 585d0cc + 1b837f4 commit f9d19cc
Show file tree
Hide file tree
Showing 3 changed files with 9 additions and 6 deletions.
5 changes: 3 additions & 2 deletions lib/logtail-rack/http_context.rb
Original file line number Diff line number Diff line change
Expand Up @@ -18,8 +18,9 @@ def call(env)
request_id: request.request_id
)

CurrentContext.add(context.to_hash)
@app.call(env)
CurrentContext.with(context.to_hash) do
@app.call(env)
end
end
end
end
Expand Down
8 changes: 5 additions & 3 deletions lib/logtail-rack/user_context.rb
Original file line number Diff line number Diff line change
Expand Up @@ -67,10 +67,12 @@ def custom_user_hash
def call(env)
user_hash = get_user_hash(env)
if user_hash
CurrentContext.add({user: user_hash})
CurrentContext.with({user: user_hash}) do
@app.call(env)
end
else
@app.call(env)
end

@app.call(env)
end

private
Expand Down
2 changes: 1 addition & 1 deletion lib/logtail-rack/version.rb
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
module Logtail
module Integrations
module Rack
VERSION = "0.1.6"
VERSION = "0.2.0"
end
end
end

0 comments on commit f9d19cc

Please sign in to comment.