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

Context should accept procs as values #963

Closed
fabn opened this issue Jun 12, 2020 · 1 comment
Closed

Context should accept procs as values #963

fabn opened this issue Jun 12, 2020 · 1 comment
Projects

Comments

@fabn
Copy link

fabn commented Jun 12, 2020

I used other error tracking libraries and what I'm missing in sentry is the ability to provide context using a proc.

If I provide context in a before action as in the provided example

before_action -> do
  Raven.user_context = user_context
  Raven.tags_context = context_tags
end

when filter is run some values may not yet be available. If we're able to provide a proc (evaluated with current controller) we can add more useful data to context and get it when available.

Also I see that you're using thread locals (correctly) but you don't suggest to clear context after usage, this can leak context to other requests served by same thread. I'm using like this to avoid this issue.

  around_action :set_diagnostic_context

  # Used to record values in sentry
  def set_diagnostic_context(&action)
    Raven.user_context = user_context
    Raven.tags_context = context_tags
    action.call
  ensure
    Raven::Context.clear!
  end

is that correct?

@st0012 st0012 added this to Needs triage in 3.x Aug 6, 2020
@st0012 st0012 moved this from Needs triage to Feature Request in 3.x Aug 6, 2020
@st0012 st0012 added this to the 3.1.0 milestone Aug 14, 2020
@st0012 st0012 moved this from Feature Request to Medium priority in 3.x Aug 27, 2020
@st0012
Copy link
Collaborator

st0012 commented Sep 4, 2020

If you want to insert some information that's only available after the before_action callback, you can use Raven.tags.merge!(key: val) to add it to the context.

It could be a bit less convenient than passing a proc value. But since it's achievable, I don't want to support proc value at the moment as the benefit won't worth the added complexity.

Also I see that you're using thread locals (correctly) but you don't suggest to clear context after usage, this can leak context to other requests served by same thread. I'm using like this to avoid this issue.

We do clean up the context in rack middleware, so you don't need to do it manually

https://github.com/getsentry/raven-ruby/blob/cd628e00ab7231e3d18d771ffd232db9c7b387c0/lib/raven/integrations/rack.rb#L60-L67

@st0012 st0012 closed this as completed Sep 4, 2020
3.x automation moved this from Medium priority to Closed Sep 4, 2020
@st0012 st0012 removed this from the 3.1.0 milestone Sep 4, 2020
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
3.x
  
Closed
Development

No branches or pull requests

2 participants