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

add user id as Custom Attribute to New Relic agent #24978

Merged
merged 2 commits into from Sep 26, 2018
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
8 changes: 8 additions & 0 deletions dashboard/config/initializers/new_relic_user_attribute.rb
@@ -0,0 +1,8 @@
if defined?(::NewRelic::Agent.add_custom_attributes) &&
defined?(::Warden::Manager.after_set_user)
::Warden::Manager.after_set_user do |user, _auth, _opts|
if user.respond_to?(:id)
::NewRelic::Agent.add_custom_attributes({user_id: user.id})
end
end
end
8 changes: 8 additions & 0 deletions shared/test/spy_newrelic_agent.rb
Expand Up @@ -40,5 +40,13 @@ def self.get_events(regex)
regex.match event.first
end
end

def self.add_custom_attributes(params)
(@@attributes ||= {}).merge!(params)
end

def self.custom_attributes
@@attributes ||= {}
end
end
end