[Metrics] track! method doesn't work in metric definition
Looooong opened this issue · 4 comments
I tried a modified piece of code from the example
metric '[Milestone] Level 5' do
description 'Measure how many people reached level 5.'
User.after_save do |user|
track! if user.level_changed? && user.level == 5
end
end
When user reaches level 5, exception is thrown: undefined method 'track!' for #<User:0x007f201750b480>
@Looooong the track!
method isn't defined globally, it's only available on the Vanity
object, does Vanity.track!
work there?
@phillbaker Yes, it does work. I have to rewrite the code to Vanity.track!(:milestone_level_5)
.
It doesn't seem to be slick to me, however.
You should either update the document, or update the code to work as expected in the document.
I have just tested the code.
metric '[Milestone] Level 5' do
description 'Measure how many people reached level 5.'
User.after_save do |user|
Vanity.track! if user.level_changed? && user.level == 5
end
end
And it throws ArgumentError: wrong number if arguments (given 0, expected 1..2)
And worse, with this pattern, Rails doesn't show the exact line where this exception is thrown.
So, I will stick to Vanity.track!(:metric)