metrics 0.12.0 → 0.12.2

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA256:
3
- metadata.gz: 68f3f47929348e39fb0b1989c529211aeca2e77a11d89cc74eb5156517413920
4
- data.tar.gz: 23d3a1efe32f6de6a69f63401ad777e5ccd42d9386bb02dfa8039c0bfa84e7b0
3
+ metadata.gz: da58c61e306a2816806803db0b41e967f593517c8f825a454d1480dafce50342
4
+ data.tar.gz: c535510ec158b5c0181b57a772c0d43c9800356f9180a4ae97c35037732e99af
5
5
  SHA512:
6
- metadata.gz: 266cbaef3d8f81ba42de551bf2119ec6f93004a68cc373046726aec26129a949e01b3548362d6f155bd9fbc48144d06483fcc83db62c9eab34bfe340c4681df7
7
- data.tar.gz: 50fe49335a1fadc4362d1dac69c084867eb47b358de9197d7f77276033a9c55176db64464bf422ef55da3e52ffef2263bd0baae741a0f0027e98182e8aa4d588
6
+ metadata.gz: 0ae866b7e9dfce05883974ed8ea2489536838d3a8cc9e5947ee188879e7e72c8793f23e9274b26a20749e114d653b6006ed8a10827f13f3dbb680052e5fd2231
7
+ data.tar.gz: cb70aa1a2a2672df5d80a8368265495b2652a612fc0128972a64c1eec917076881ff27daafb9c514b5f86fd46bcf400cb838597971ff00be6fe59b42562d199a
checksums.yaml.gz.sig CHANGED
Binary file
@@ -3,7 +3,6 @@
3
3
  # Released under the MIT License.
4
4
  # Copyright, 2023-2024, by Samuel Williams.
5
5
 
6
- require "console"
7
6
  require_relative "../metric"
8
7
 
9
8
  module Metrics
@@ -3,9 +3,10 @@
3
3
  # Released under the MIT License.
4
4
  # Copyright, 2021-2024, by Samuel Williams.
5
5
 
6
- require "console"
7
6
  require_relative "../metric"
8
7
 
8
+ require "console"
9
+
9
10
  module Metrics
10
11
  module Backend
11
12
  module Console
@@ -3,7 +3,6 @@
3
3
  # Released under the MIT License.
4
4
  # Copyright, 2021-2024, by Samuel Williams.
5
5
 
6
- require "console"
7
6
  require_relative "../metric"
8
7
 
9
8
  module Metrics
@@ -3,27 +3,11 @@
3
3
  # Released under the MIT License.
4
4
  # Copyright, 2021-2024, by Samuel Williams.
5
5
 
6
- require "console/event/failure"
6
+ require_relative "config"
7
7
 
8
8
  module Metrics
9
9
  module Backend
10
- # Require a specific trace backend.
11
- def self.require_backend(env = ENV)
12
- if backend = env["METRICS_BACKEND"]
13
- begin
14
- require(backend)
15
- rescue LoadError => error
16
- ::Console::Event::Failure.for(error).emit(self, "Unable to load metrics backend!", backend: backend, severity: :warn)
17
-
18
- return false
19
- end
20
-
21
- Metrics.extend(Backend::Interface)
22
-
23
- return true
24
- end
25
- end
26
10
  end
11
+
12
+ Config::DEFAULT.require_backend
27
13
  end
28
-
29
- Metrics::Backend.require_backend
@@ -0,0 +1,54 @@
1
+ # frozen_string_literal: true
2
+
3
+ # Released under the MIT License.
4
+ # Copyright, 2024-2025, by Samuel Williams.
5
+
6
+ module Metrics
7
+ # Represents a configuration for the metrics library.
8
+ class Config
9
+ DEFAULT_PATH = ENV.fetch("METRICS_CONFIG_DEFAULT_PATH", "config/metrics.rb")
10
+
11
+ # Load the configuration from the given path.
12
+ # @parameter path [String] The path to the configuration file.
13
+ # @returns [Config] The loaded configuration.
14
+ def self.load(path)
15
+ config = self.new
16
+
17
+ if File.exist?(path)
18
+ config.instance_eval(File.read(path), path)
19
+ end
20
+
21
+ return config
22
+ end
23
+
24
+ # Load the default configuration.
25
+ # @returns [Config] The default configuration.
26
+ def self.default
27
+ @default ||= self.load(DEFAULT_PATH)
28
+ end
29
+
30
+ # Prepare the backend, e.g. by loading additional libraries or instrumentation.
31
+ def prepare
32
+ end
33
+
34
+ # Require a specific metrics backend implementation.
35
+ def require_backend(env = ENV)
36
+ if backend = env["METRICS_BACKEND"]
37
+ begin
38
+ if require(backend)
39
+ Metrics.singleton_class.prepend(Backend::Interface)
40
+
41
+ return true
42
+ end
43
+ rescue LoadError => error
44
+ warn "Unable to load metrics backend: #{backend.inspect}!"
45
+ end
46
+ end
47
+
48
+ return false
49
+ end
50
+
51
+ # Load the default configuration.
52
+ DEFAULT = self.default
53
+ end
54
+ end
@@ -35,6 +35,8 @@ module Metrics
35
35
 
36
36
  return provider
37
37
  end
38
+
39
+ Config::DEFAULT.prepare
38
40
  else
39
41
  def self.Provider(klass, &block)
40
42
  # Metrics disabled.
@@ -4,5 +4,5 @@
4
4
  # Copyright, 2021-2024, by Samuel Williams.
5
5
 
6
6
  module Metrics
7
- VERSION = "0.12.0"
7
+ VERSION = "0.12.2"
8
8
  end
data/lib/metrics.rb CHANGED
@@ -6,3 +6,7 @@
6
6
  require_relative "metrics/version"
7
7
  require_relative "metrics/provider"
8
8
  require_relative "metrics/tags"
9
+
10
+ # @namespace
11
+ module Metrics
12
+ end
data/license.md CHANGED
@@ -1,6 +1,6 @@
1
1
  # MIT License
2
2
 
3
- Copyright, 2021-2024, by Samuel Williams.
3
+ Copyright, 2021-2025, by Samuel Williams.
4
4
 
5
5
  Permission is hereby granted, free of charge, to any person obtaining a copy
6
6
  of this software and associated documentation files (the "Software"), to deal
data/readme.md CHANGED
@@ -19,6 +19,14 @@ Please see the [project documentation](https://socketry.github.io/metrics/) for
19
19
 
20
20
  - [Testing](https://socketry.github.io/metrics/guides/testing/index) - This guide explains how to write assertions in your test suite to validate `metrics` are being emitted correctly.
21
21
 
22
+ ## Releases
23
+
24
+ Please see the [project releases](https://socketry.github.io/metrics/releases/index) for all releases.
25
+
26
+ ### v0.12.1
27
+
28
+ - [Introduce `Metrics::Config` to Expose `prepare` Hook](https://socketry.github.io/metrics/releases/index#introduce-metrics::config-to-expose-prepare-hook)
29
+
22
30
  ## Contributing
23
31
 
24
32
  We welcome contributions to this project.
data/releases.md ADDED
@@ -0,0 +1,18 @@
1
+ # Releases
2
+
3
+ ## v0.12.1
4
+
5
+ ### Introduce `Metrics::Config` to Expose `prepare` Hook
6
+
7
+ The `metrics` gem uses aspect-oriented programming to wrap existing methods to emit metrics. However, while there are some reasonable defaults for emitting metrics, it can be useful to customize the behavior and level of detail. To that end, the `metrics` gem now optionally loads a `config/metrics.rb` which includes a `prepare` hook that can be used to load additional providers.
8
+
9
+ ``` ruby
10
+ # config/metrics.rb
11
+
12
+ def prepare
13
+ require 'metrics/provider/async'
14
+ require 'metrics/provider/async/http'
15
+ end
16
+ ```
17
+
18
+ The `prepare` method is called immediately after the metrics backend is loaded. You can require any provider you want in this file, or even add your own custom providers.
data.tar.gz.sig CHANGED
@@ -1,3 +1,4 @@
1
- &�J��qzmIŐ�,+�>���vP�@ǩ"����cN�˜0���(��$�e=?��ru<��(X��%�il�W�&"����6CY�����P�`;�BkE
2
- ��ݗN��eR0Pl�U��y��QX$�@��]���F��
3
- `�{?<O}��� :l
1
+ �\ᐾ2 �|W����zB��������jT|N�5Eb�J�<��䤅��.���mt�S��w;��_*o/�lS��s)r����/�P,�����ɐ?��J��T dCW��]0��7g`�9&�\66��Ufp0c���H�Re���Y뜁�<
2
+ �9��1Sf=��#d��7�`�؍֐{�Y�{�|�M� �<$
3
+ ��C_e�6��28|���*�;�`��=�6�2�qSE�ʍ6{����x-��/6�)����� �܀A>��[2ʸI���-ds|1|�!�5���;*��<bm_��g��^�[ ��'l��GmozT���_��|�|uA�Ԝ������hE9������r�D^��;�e��l A<�
4
+ �cm�l]=dJ%
metadata CHANGED
@@ -1,11 +1,10 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: metrics
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.12.0
4
+ version: 0.12.2
5
5
  platform: ruby
6
6
  authors:
7
7
  - Samuel Williams
8
- autorequire:
9
8
  bindir: bin
10
9
  cert_chain:
11
10
  - |
@@ -37,10 +36,8 @@ cert_chain:
37
36
  Q2K9NVun/S785AP05vKkXZEFYxqG6EW012U4oLcFl5MySFajYXRYbuUpH6AY+HP8
38
37
  voD0MPg1DssDLKwXyt1eKD/+Fq0bFWhwVM/1XiAXL7lyYUyOq24KHgQ2Csg=
39
38
  -----END CERTIFICATE-----
40
- date: 2024-10-12 00:00:00.000000000 Z
39
+ date: 2025-03-07 00:00:00.000000000 Z
41
40
  dependencies: []
42
- description:
43
- email:
44
41
  executables: []
45
42
  extensions: []
46
43
  extra_rdoc_files: []
@@ -51,19 +48,20 @@ files:
51
48
  - lib/metrics/backend/capture.rb
52
49
  - lib/metrics/backend/console.rb
53
50
  - lib/metrics/backend/test.rb
51
+ - lib/metrics/config.rb
54
52
  - lib/metrics/metric.rb
55
53
  - lib/metrics/provider.rb
56
54
  - lib/metrics/tags.rb
57
55
  - lib/metrics/version.rb
58
56
  - license.md
59
57
  - readme.md
58
+ - releases.md
60
59
  homepage: https://github.com/socketry/metrics
61
60
  licenses:
62
61
  - MIT
63
62
  metadata:
64
63
  documentation_uri: https://socketry.github.io/metrics/
65
64
  source_code_uri: https://github.com/socketry/metrics.git
66
- post_install_message:
67
65
  rdoc_options: []
68
66
  require_paths:
69
67
  - lib
@@ -78,8 +76,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
78
76
  - !ruby/object:Gem::Version
79
77
  version: '0'
80
78
  requirements: []
81
- rubygems_version: 3.5.11
82
- signing_key:
79
+ rubygems_version: 3.6.2
83
80
  specification_version: 4
84
81
  summary: Application metrics and instrumentation.
85
82
  test_files: []
metadata.gz.sig CHANGED
@@ -1,5 +1,2 @@
1
- O@�5��q'
2
- #�8�`���帟�u��K�TtT2�"��
3
- /�_�wý^S;�P���Xf[@Gմ�œC35�~��Ulⅈ����I�^�¾�Õ�7�Y�v5�̱�8S~�6h݂T�IA���)+O��
4
- ��
5
- ����86��16�/�M�����.�I-E|\�pT���^5�8K����4B��q���;ߣӯq^���
1
+ Y�H�޹����&�����?a�ܹ�<�抷���?� ��Y��z_���z^6��;�:H}����,��8�|Njn���k��%M�
2
+ ��)�j$7���*��"�ի�S�畹 ����ۂ�PMD��w�Ϭ0N�g�7s*���I�� �1������