airbrake: Set metadata to be sent if an exception occurs?

Hi

Is there a way to set metadata context and params like in Honeybadger.context?

That would be very helpful, because usually the place that Airbrake.notify(e) is a high level class, and sometimes the one that raises an exception is super further down, so it would be super cool being able to:

def execute
  call_a_all_the_way_down_to_c
rescue e
  Airbrake.notify(e)
end

def c
  # something
rescue e
  Airbrake.context(user_id: user_id)
end

About this issue

  • Original URL
  • State: closed
  • Created 7 years ago
  • Reactions: 1
  • Comments: 17 (14 by maintainers)

Commits related to this issue

Most upvoted comments

Since airbrake-ruby v2.9.0 you can set context with Airbrake.merge_context: https://github.com/airbrake/airbrake-ruby#airbrakemerge_context

My need is for something exactly like Honeybadger.context, so I can append useful information to the error in any layer, and in the main executor I only notify, as the main one does not have access to all meaningful information deep down in all other layers.

class A
  def call(...)
    B.new(...).call(...)
  rescue e
    # notify with all context added in B ... N
    Airbrake.notify(e)
  end
end

class B
  def call(...)
    N.new(...).call(...)
  rescue e
    Airbrake.context(instance_variable_of_b_1: n1, instance_variable_of_b_2: n2, some_other_information: n)
    raise e
  end
end

class N
  def call(...)
  rescue e
    Airbrake.context(instance_variable_of_n_1: n1, instance_variable_of_n_2: n2, some_other_information: n)
    raise e
  end
end

Does that make sense?

Alternatively, if you work with custom exceptions, you can set custom exception attributes.

Most of the exceptions aren’t my own, for example Stripe::Error.

@kyrylo it seems the example is missing the param (veggies):

  def load_veggies(veggies)
    Airbrake.merge_context(veggies: veggies)
  end

Sorry for the delay! I’ve been distracted by other tasks. Given the growing interest in this feature, I plan to work on it next week. I am going to close this issue in favour of https://github.com/airbrake/airbrake-ruby/issues/187 because that repo is the correct place (airbrake-ruby needs to be modified to implement the feature).