Skip to content

Attach context - #112

Open
joromir wants to merge 5 commits into
masterfrom
attach_context
Open

Attach context#112
joromir wants to merge 5 commits into
masterfrom
attach_context

Conversation

@joromir

@joromir joromir commented Jul 3, 2018

Copy link
Copy Markdown
Contributor
  • Improve passing context to logger
  • Refactor code in Loga::Configuration.

Fixes #77

@joromir joromir self-assigned this Jul 3, 2018
@joromir
joromir force-pushed the attach_context branch 6 times, most recently from 2588d30 to 33e3019 Compare July 5, 2018 10:52
@joromir

joromir commented Jul 6, 2018

Copy link
Copy Markdown
Contributor Author

👀

@bliof
bliof self-requested a review June 14, 2019 10:00
@bliof

bliof commented Jun 19, 2019

Copy link
Copy Markdown
Contributor

🤔 Unfortunately the current implementation won't do / needs expanding.

The main problem is that when we trace something e.g. sidekiq job or a rack request we want to pass some metadata to that trace e.g. Loga.context(user_type: 'Admin')

Overall we can refactor a bit more and extract the tracing so from e.g. Loga::Sidekiq::JobLogger#call and Loga::Rack::Logger#call when the trace starts we can create a context for that trace and with the Loga.context(user_type: 'Admin') we start filling that context.

# somewhere in Loga::Rack::Logger#call

Loga::Trace.trace do
   @app.call(env).tap { |status, _headers, _body| data['status'] = status.to_i }
end

# somewhere in the app

Loga.context(user_type: 'Admin')

# or even we can create nested traces/contexts

Loga.context(user_type: 'Admin') do
   Loga.logger.info "Call 1" # -> Call 1 user_type=Admin
   jobs.each do |job|
     Loga.context(job_id: job.id) do
        Loga.logger.info "Call 2" # -> Call 2 user_type=Admin job_id=123
     end
   end
   Loga.logger.info "Call 3" # -> Call 3 user_type=Admin
end

I'll continue the PR ☝️ direction. The dsl is still questionable ;)

@cassiomarques

Copy link
Copy Markdown
Contributor

Closing, stale and probably no longer needed.

@bliof

bliof commented Feb 21, 2020

Copy link
Copy Markdown
Contributor

Needed but not trivial to implements so.. we haven't spend the time :) -> Opening again

@bliof bliof reopened this Feb 21, 2020
@cassiomarques

Copy link
Copy Markdown
Contributor

ivial to implements so.. we haven't spend the time :) -> Opening again

Would the code here be reused or would the author probably start from scratch?

@bliof

bliof commented Feb 21, 2020

Copy link
Copy Markdown
Contributor

No idea. If/when I try I'll use the current PR. Assume this PR as an Issue with some code :)

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Improve passing context to logger

4 participants