apm-agent-ruby icon indicating copy to clipboard operation
apm-agent-ruby copied to clipboard

Custom context for set_custom_context

Open danilvoe opened this issue 6 years ago • 4 comments

How can I send an error message without exception, but with additional information?

ElasticAPM.report - sends error data

ElasticAPM.report_message - just sends text

I would like to send a message in which there is no Exception but at the same time there is another meaningful load, the user's name, data about the model with which he worked, etc. those.

ElasticAPM.set_custom_context fails to set for ElasticAPM.report_message

danilvoe avatar Feb 08 '19 09:02 danilvoe

Here it is done in sentry https://docs.sentry.io/clients/ruby/context/

danilvoe avatar Feb 08 '19 09:02 danilvoe

I think this might be a bug. Let me investigate a bit – thanks for reporting.

mikker avatar Feb 08 '19 09:02 mikker

@mikker

I checked (ElasticAPM.report_message("dsds") ) the work separately ElasticAPM.report_message, when I call in the application, I get an error error json ### Problem validating JSON document against schema: I [#] S [#] does not validate with \ "error # " \ n https://pastebin.com/A8zHNMNr

Run through the console console is successful.

danilvoe avatar Feb 08 '19 11:02 danilvoe

I think we need a with_custom_context method for this. If we are outside transactions, we have no way to store the context nor define when the custom context from set_custom_context should be un-set.

Would that solve your use case?

ElasticAPM.with_custom_context my_thing: 'something' do
  begin
    explode
  rescue Exception => e
    ElasticAPM.report e # will have custom: { my_thing: 'something' }
  end
end

mikker avatar Feb 26 '19 11:02 mikker