metrics 0.12.0 → 0.12.1

Sign up to get free protection for your applications and to get access to all the features.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA256:
3
- metadata.gz: 68f3f47929348e39fb0b1989c529211aeca2e77a11d89cc74eb5156517413920
4
- data.tar.gz: 23d3a1efe32f6de6a69f63401ad777e5ccd42d9386bb02dfa8039c0bfa84e7b0
3
+ metadata.gz: 193277c7355699f745c13423414860110e110ce7cc0ea2c6244d4a6aef1bace2
4
+ data.tar.gz: e5363e2f9660f500f69472421e314451cbdf7ef0339a8af685a4d7bd0006012d
5
5
  SHA512:
6
- metadata.gz: 266cbaef3d8f81ba42de551bf2119ec6f93004a68cc373046726aec26129a949e01b3548362d6f155bd9fbc48144d06483fcc83db62c9eab34bfe340c4681df7
7
- data.tar.gz: 50fe49335a1fadc4362d1dac69c084867eb47b358de9197d7f77276033a9c55176db64464bf422ef55da3e52ffef2263bd0baae741a0f0027e98182e8aa4d588
6
+ metadata.gz: c659a423919600b8efe495dce0bd45d78da651dd66ff6caa1f3bb95e95322171dccd0bfd2e417380c815105c6a13f1933c0a8672cf6c85407a8e7a7bcef54790
7
+ data.tar.gz: e153ebb2d36bd2471053f14569fcece3a72bacc8cfa799b750963a74d0b3ced80579130acfd87e8a27491da5950e08c5deddb3612cb24bc3f64ffb861eb2dcf9
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, 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.extend(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.1"
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/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
Binary file
metadata CHANGED
@@ -1,7 +1,7 @@
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.1
5
5
  platform: ruby
6
6
  authors:
7
7
  - Samuel Williams
@@ -37,7 +37,7 @@ cert_chain:
37
37
  Q2K9NVun/S785AP05vKkXZEFYxqG6EW012U4oLcFl5MySFajYXRYbuUpH6AY+HP8
38
38
  voD0MPg1DssDLKwXyt1eKD/+Fq0bFWhwVM/1XiAXL7lyYUyOq24KHgQ2Csg=
39
39
  -----END CERTIFICATE-----
40
- date: 2024-10-12 00:00:00.000000000 Z
40
+ date: 2024-11-05 00:00:00.000000000 Z
41
41
  dependencies: []
42
42
  description:
43
43
  email:
@@ -51,12 +51,14 @@ files:
51
51
  - lib/metrics/backend/capture.rb
52
52
  - lib/metrics/backend/console.rb
53
53
  - lib/metrics/backend/test.rb
54
+ - lib/metrics/config.rb
54
55
  - lib/metrics/metric.rb
55
56
  - lib/metrics/provider.rb
56
57
  - lib/metrics/tags.rb
57
58
  - lib/metrics/version.rb
58
59
  - license.md
59
60
  - readme.md
61
+ - releases.md
60
62
  homepage: https://github.com/socketry/metrics
61
63
  licenses:
62
64
  - MIT
metadata.gz.sig CHANGED
Binary file