From b316ff8413a4d69b8a9443aa7430478e6b4c165f Mon Sep 17 00:00:00 2001 From: Mike Angell Date: Wed, 11 Sep 2019 04:20:34 +1000 Subject: [PATCH 1/3] 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 77e9ff4..75b1d5f 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 afcf479..f0c9868 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 0000000..4876ce9 --- /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 From b6547f322eb9d3b83908bc463dc3dd79e37cb3e4 Mon Sep 17 00:00:00 2001 From: Mike Angell Date: Wed, 11 Sep 2019 04:56:25 +1000 Subject: [PATCH 2/3] Simplify usage --- lib/liquid.rb | 1 + lib/liquid/standardfilters.rb | 2 +- lib/liquid/usage.rb | 2 +- 3 files changed, 3 insertions(+), 2 deletions(-) diff --git a/lib/liquid.rb b/lib/liquid.rb index 0e198bb..b98d4d9 100644 --- a/lib/liquid.rb +++ b/lib/liquid.rb @@ -75,6 +75,7 @@ require 'liquid/utils' require 'liquid/tokenizer' require 'liquid/parse_context' require 'liquid/partial_cache' +require 'liquid/usage' # Load all the tags of the standard library # diff --git a/lib/liquid/standardfilters.rb b/lib/liquid/standardfilters.rb index f0c9868..cf72dba 100644 --- a/lib/liquid/standardfilters.rb +++ b/lib/liquid/standardfilters.rb @@ -421,7 +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 + Usage.increment("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 index 4876ce9..e3267eb 100644 --- a/lib/liquid/usage.rb +++ b/lib/liquid/usage.rb @@ -1,6 +1,6 @@ module Liquid module Usage - def self.increment(name, sample_rate: 0.1, tags: {}) + def self.increment(name) end end end From 8318be2edc0c4a2aaf1a47085a7aa65950eb6c81 Mon Sep 17 00:00:00 2001 From: Mike Angell Date: Wed, 11 Sep 2019 05:20:05 +1000 Subject: [PATCH 3/3] Update readme --- README.md | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/README.md b/README.md index 75b1d5f..6802a71 100644 --- a/README.md +++ b/README.md @@ -109,6 +109,6 @@ template.render!({ 'x' => 1}, { strict_variables: true }) ### 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. +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 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. +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. \ No newline at end of file