diff --git a/CHANGELOG.md b/CHANGELOG.md index 7672fa1..54dfcf0 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -5,6 +5,12 @@ All notable changes to this project will be documented in this file. The format is based on [Keep a Changelog](http://keepachangelog.com/en/1.0.0/) and this project adheres to [Semantic Versioning](http://semver.org/spec/v2.0.0.html). +## not released + +### Fixed + + - Default tags were not sent to adapters for metrics declared before `default_tag` declaration. [@Envek] + ## 0.5.0 - 2020-01-29 ### Added diff --git a/lib/yabeda.rb b/lib/yabeda.rb index da8c827..3fbb10f 100644 --- a/lib/yabeda.rb +++ b/lib/yabeda.rb @@ -60,6 +60,7 @@ def configured? # Perform configuration: registration of metrics and collector blocks # @return [void] + # rubocop: disable Metrics/MethodLength, Metrics/AbcSize def configure! raise(AlreadyConfiguredError, @configured_by) if already_configured? @@ -69,8 +70,17 @@ def configure! group nil end + # Register metrics in adapters after evaluating all configuration blocks + # to ensure that all global settings (like default tags) will be applied. + adapters.each_value do |adapter| + metrics.each_value do |metric| + adapter.register!(metric) + end + end + @configured_by = caller_locations(1, 1)[0].to_s end + # rubocop: enable Metrics/MethodLength, Metrics/AbcSize # Forget all the configuration. # For testing purposes as it doesn't rollback changes in adapters. diff --git a/lib/yabeda/dsl/class_methods.rb b/lib/yabeda/dsl/class_methods.rb index 37545b2..4c4c00e 100644 --- a/lib/yabeda/dsl/class_methods.rb +++ b/lib/yabeda/dsl/class_methods.rb @@ -68,7 +68,6 @@ def register_metric(metric) name = [metric.group, metric.name].compact.join("_") ::Yabeda.define_singleton_method(name) { metric } ::Yabeda.metrics[name] = metric - ::Yabeda.adapters.each_value { |adapter| adapter.register!(metric) } register_group_for(metric) if metric.group metric end