Skip to content

Commit f9d19cc

Browse files
authored
Merge pull request #6 from logtail/ah/context-with
Add relevant logging contexts only for the duration of the request
2 parents 585d0cc + 1b837f4 commit f9d19cc

File tree

3 files changed

+9
-6
lines changed

3 files changed

+9
-6
lines changed

lib/logtail-rack/http_context.rb

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -18,8 +18,9 @@ def call(env)
1818
request_id: request.request_id
1919
)
2020

21-
CurrentContext.add(context.to_hash)
22-
@app.call(env)
21+
CurrentContext.with(context.to_hash) do
22+
@app.call(env)
23+
end
2324
end
2425
end
2526
end

lib/logtail-rack/user_context.rb

Lines changed: 5 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -67,10 +67,12 @@ def custom_user_hash
6767
def call(env)
6868
user_hash = get_user_hash(env)
6969
if user_hash
70-
CurrentContext.add({user: user_hash})
70+
CurrentContext.with({user: user_hash}) do
71+
@app.call(env)
72+
end
73+
else
74+
@app.call(env)
7175
end
72-
73-
@app.call(env)
7476
end
7577

7678
private

lib/logtail-rack/version.rb

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
module Logtail
22
module Integrations
33
module Rack
4-
VERSION = "0.1.6"
4+
VERSION = "0.2.0"
55
end
66
end
77
end

0 commit comments

Comments
 (0)