From b316ff8413a4d69b8a9443aa7430478e6b4c165f Mon Sep 17 00:00:00 2001 From: Mike Angell Date: Wed, 11 Sep 2019 04:20:34 +1000 Subject: [PATCH] Add usage tracking --- README.md | 6 ++++++ lib/liquid/standardfilters.rb | 1 + lib/liquid/usage.rb | 6 ++++++ 3 files changed, 13 insertions(+) create mode 100644 lib/liquid/usage.rb diff --git a/README.md b/README.md index 77e9ff43..75b1d5f6 100644 --- a/README.md +++ b/README.md @@ -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 determine if a feature or code path is used in production we have included opt-in usage tracking. To achieve this we provide an empty `Liquid::Usage.increment` method that can be implemented. This was designed to be paired with https://github.com/Shopify/statsd-instrument , however it's implementation is up to you. + +Once you have enabled usage tracking we recommend reporting any logged events through Github Issues that your system may be reporting. It is highly likely this event has been added to consider deprecating or improving code specific to this event, so please raise any concerns. diff --git a/lib/liquid/standardfilters.rb b/lib/liquid/standardfilters.rb index afcf479e..f0c98686 100644 --- a/lib/liquid/standardfilters.rb +++ b/lib/liquid/standardfilters.rb @@ -421,6 +421,7 @@ module Liquid def default(input, default_value = ''.freeze) if !input || input.respond_to?(:empty?) && input.empty? + Usage.increment("liquid.default_filter_received_false_value") if input == false # See https://github.com/Shopify/liquid/issues/1127 default_value else input diff --git a/lib/liquid/usage.rb b/lib/liquid/usage.rb new file mode 100644 index 00000000..4876ce93 --- /dev/null +++ b/lib/liquid/usage.rb @@ -0,0 +1,6 @@ +module Liquid + module Usage + def self.increment(name, sample_rate: 0.1, tags: {}) + end + end +end