Skip to content

Commit

Permalink
Merge pull request Shopify#1149 from Shopify/liquid-usage
Browse files Browse the repository at this point in the history
Add usage tracking
  • Loading branch information
shopmike authored Sep 16, 2019
2 parents 1fcef21 + 8318be2 commit 9a42c8c
Show file tree
Hide file tree
Showing 4 changed files with 14 additions and 0 deletions.
6 changes: 6 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -106,3 +106,9 @@ template = Liquid::Template.parse("{{x}} {{y}}")
template.render!({ 'x' => 1}, { strict_variables: true })
#=> Liquid::UndefinedVariable: Liquid error: undefined variable y
```

### Usage tracking

To help track usages of a feature or code path in production, we have released opt-in usage tracking. To enable this, we provide an empty `Liquid:: Usage.increment` method which you can customize to your needs. The feature is well suited to https://github.com/Shopify/statsd-instrument. However, the choice of implementation is up to you.

Once you have enabled usage tracking, we recommend reporting any events through Github Issues that your system may be logging. It is highly likely this event has been added to consider deprecating or improving code specific to this event, so please raise any concerns.
1 change: 1 addition & 0 deletions lib/liquid.rb
Original file line number Diff line number Diff line change
Expand Up @@ -75,6 +75,7 @@ module Liquid
require 'liquid/tokenizer'
require 'liquid/parse_context'
require 'liquid/partial_cache'
require 'liquid/usage'

# Load all the tags of the standard library
#
Expand Down
1 change: 1 addition & 0 deletions lib/liquid/standardfilters.rb
Original file line number Diff line number Diff line change
Expand Up @@ -421,6 +421,7 @@ def at_most(input, n)

def default(input, default_value = ''.freeze)
if !input || input.respond_to?(:empty?) && input.empty?
Usage.increment("default_filter_received_false_value") if input == false # See https://github.com/Shopify/liquid/issues/1127
default_value
else
input
Expand Down
6 changes: 6 additions & 0 deletions lib/liquid/usage.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
module Liquid
module Usage
def self.increment(name)
end
end
end

0 comments on commit 9a42c8c

Please sign in to comment.