Skip to content

Commit

Permalink
Merge pull request #24978 from code-dot-org/newrelic_user_custom_attr…
Browse files Browse the repository at this point in the history
…ibute

add user id as Custom Attribute to New Relic agent
  • Loading branch information
wjordan committed Sep 26, 2018
2 parents 070cdc7 + 36960e5 commit 7fcc454
Show file tree
Hide file tree
Showing 2 changed files with 16 additions and 0 deletions.
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

0 comments on commit 7fcc454

Please sign in to comment.