opensource-developer
opensource-developer

Reputation: 3058

Send additional information with Raven.send_event

I have integrated Sentry in my Ruby On Rails application and I want to send a custom event when a specific case happens, I am able to send the events with

Raven.send_event({:message => 'Custom event'})

How do i send additional information related to the same. I need to send for example, user_id, email_id, login_name and other custom parameters.

Upvotes: 0

Views: 1208

Answers (3)

Cengizz
Cengizz

Reputation: 45

Addition to @opensource-developer answer: You can find more available extra parameters here => Sentry Usage Page

Upvotes: 1

opensource-developer
opensource-developer

Reputation: 3058

For anyone facing similar issue, i managed to do it via, under the key extra you can specify any extra keys which you want to send to sentry for further debugging

    Raven.capture_message "custom message",
      logger: 'logger',
      extra: {
        time_at: Time.now
      },
      tags: {
        env: Rails.env
      }

Upvotes: 0

Sumanth Madishetty
Sumanth Madishetty

Reputation: 3605

You can set user_context to raven using Raven.user_context method

You can write a method to set context in Application Controller and call the same in before action

For example

Raven.user_context(
# a unique ID which represents this user
id: current_user.id, # 1

# the actor's email address, if available
 email: current_user.email, # "[email protected]"

 # the actor's username, if available
  username: current_user.username, # "foo"

  # the actor's IP address, if available
  ip_address: request.ip # '127.0.0.1'
)

You can write in application controller as

class ApplicationController < ActionController::Base
before_action :set_raven_context, if: proc { Rails.env.production? } //If you want to set only in prod

def set_raven_context


Raven.user_context(
# a unique ID which represents this user
id: current_user.id, # 1

# the actor's email address, if available
 email: current_user.email, # "[email protected]"

 # the actor's username, if available
  username: current_user.username, # "foo"

  # the actor's IP address, if available
  ip_address: request.ip # '127.0.0.1'
)

#You can also set extra context using `Raven.extra_context`
Raven.extra_context app: url, environment: Rails.env, time: Time.now
end

end

Upvotes: 2

Related Questions