boringmetrics-rails 0.1.0

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 ADDED
@@ -0,0 +1,7 @@
1
+ ---
2
+ SHA256:
3
+ metadata.gz: 0f20c8aaaab17cf76207209400332fdb37cf4f4ca03d2f22e70ce9d316b79164
4
+ data.tar.gz: 67456101066e331580c7e5db7cdc10d8677f08873e1ea87febe6e66bd6a1fb89
5
+ SHA512:
6
+ metadata.gz: 687ee811ae61ebeedf646f8973095f8ed4423e4ecd08a9e596fb55cb62ac5338382132264942e6e66e9420e572bf28d22704e1287c63b0bbfed49b1dbe44e4ec
7
+ data.tar.gz: 8b5b8f6d10eaebc7f9b51fd6186ddb217bdfeb7054970b5d9d1a01d38e97c0a0cd10f5c07373318815398122028a858b9f3eed64e865ae9a0f28f9d88490ea74
data/LICENSE ADDED
@@ -0,0 +1,19 @@
1
+ Copyright (c) 2025 Boring Metrics
2
+
3
+ Permission is hereby granted, free of charge, to any person obtaining a copy
4
+ of this software and associated documentation files (the "Software"), to deal
5
+ in the Software without restriction, including without limitation the rights
6
+ to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
7
+ copies of the Software, and to permit persons to whom the Software is
8
+ furnished to do so, subject to the following conditions:
9
+
10
+ The above copyright notice and this permission notice shall be included in all
11
+ copies or substantial portions of the Software.
12
+
13
+ THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
14
+ EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
15
+ MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT.
16
+ IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM,
17
+ DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR
18
+ OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE
19
+ OR OTHER DEALINGS IN THE SOFTWARE.
data/README.md ADDED
@@ -0,0 +1,102 @@
1
+ # Boring Metrics Ruby SDK
2
+
3
+ This is a Ruby SDK for the Boring Metrics API. It provides a simple and efficient way to interact with the API from your Ruby applications.
4
+
5
+ ## Supported Platforms
6
+
7
+ The SDK is available for the following platforms:
8
+
9
+ - [`boringmetrics`](https://github.com/boringmetrics/ruby-sdk/tree/main/packages/boringmetrics): SDK for Ruby
10
+ - [`boringmetrics-rails`](https://github.com/boringmetrics/ruby-sdk/tree/main/packages/boringmetrics-rails): SDK for Ruby on Rails
11
+
12
+ ## Installation
13
+
14
+ Add this line to your application's Gemfile:
15
+
16
+ ```ruby
17
+ # For plain Ruby applications
18
+ gem 'boringmetrics'
19
+
20
+ # For Rails applications
21
+ gem 'boringmetrics-rails'
22
+ ```
23
+
24
+ And then execute:
25
+
26
+ ```bash
27
+ $ bundle install
28
+ ```
29
+
30
+ Or install it yourself as:
31
+
32
+ ```bash
33
+ $ gem install boringmetrics
34
+ $ gem install boringmetrics-rails
35
+ ```
36
+
37
+ ## Usage
38
+
39
+ ### Ruby
40
+
41
+ ```ruby
42
+ # Initialize the SDK
43
+ BoringMetrics.initialize("YOUR_API_TOKEN")
44
+
45
+ # Send a log
46
+ BoringMetrics.logs.send(
47
+ type: "log",
48
+ level: "info",
49
+ message: "User signed in",
50
+ data: { user_id: "123" },
51
+ )
52
+
53
+ # Send multiple logs
54
+ BoringMetrics.logs.send_batch([
55
+ { type: "log", level: "warn", message: "Something looks weird" },
56
+ { type: "log", level: "error", message: "Something broke!", data: { error: "Connection timeout" } }
57
+ ])
58
+
59
+ # Set a live metric value
60
+ BoringMetrics.lives.update(
61
+ live_id: "metric-123",
62
+ value: 42,
63
+ operation: "set",
64
+ )
65
+
66
+ # Increment a live metric value
67
+ BoringMetrics.lives.update(
68
+ live_id: "metric-123",
69
+ value: 5,
70
+ operation: "increment",
71
+ )
72
+ ```
73
+
74
+ ### Rails
75
+
76
+ In a Rails application, you can initialize the SDK in an initializer:
77
+
78
+ ```ruby
79
+ # config/initializers/boringmetrics.rb
80
+ BoringMetrics::Rails.initialize("YOUR_API_TOKEN", {
81
+ logs_max_batch_size: 50,
82
+ logs_send_interval: 10
83
+ })
84
+ ```
85
+
86
+ The Rails integration automatically captures exceptions and logs them to BoringMetrics.
87
+
88
+ ## Contributing
89
+
90
+ Bug reports and pull requests are welcome on GitHub at https://github.com/boringmetrics/ruby-sdk.
91
+
92
+ ## Contributors
93
+
94
+ Thanks to everyone who contributed to the Boring Metrics Ruby SDK!
95
+
96
+ <a href="https://github.com/boringmetrics/ruby-sdk/graphs/contributors">
97
+ <img src="https://contributors-img.web.app/image?repo=boringmetrics/ruby-sdk" />
98
+ </a>
99
+
100
+ ## License
101
+
102
+ The gem is available as open source under the terms of the [MIT License](https://opensource.org/licenses/MIT).
@@ -0,0 +1,50 @@
1
+ # frozen_string_literal: true
2
+
3
+ module BoringMetrics
4
+ module Rails
5
+ # Rack middleware for BoringMetrics
6
+ class Middleware
7
+ def initialize(app)
8
+ @app = app
9
+ end
10
+
11
+ def call(env)
12
+ start_time = Time.now
13
+
14
+ # Process the request
15
+ begin
16
+ status, headers, response = @app.call(env)
17
+ [status, headers, response]
18
+ rescue StandardError => e
19
+ # Log the exception if BoringMetrics is initialized
20
+ if defined?(BoringMetrics.client) && BoringMetrics.client
21
+ BoringMetrics.logs.send(
22
+ type: "log",
23
+ level: "error",
24
+ message: e.message,
25
+ data: {
26
+ exception: e.class.name,
27
+ backtrace: e.backtrace&.first(10),
28
+ path: env["PATH_INFO"],
29
+ method: env["REQUEST_METHOD"]
30
+ }
31
+ )
32
+ end
33
+ raise e
34
+ ensure
35
+ # Log request metrics if BoringMetrics is initialized
36
+ if defined?(BoringMetrics.client) && BoringMetrics.client
37
+ duration = ((Time.now - start_time) * 1000).round(2) # in milliseconds
38
+
39
+ # Update live metric for request duration
40
+ BoringMetrics.lives.update(
41
+ live_id: "request_duration",
42
+ value: duration,
43
+ operation: "set"
44
+ )
45
+ end
46
+ end
47
+ end
48
+ end
49
+ end
50
+ end
@@ -0,0 +1,37 @@
1
+ # frozen_string_literal: true
2
+
3
+ require "rails"
4
+ require_relative "middleware"
5
+
6
+ module BoringMetrics
7
+ module Rails
8
+ # Rails integration for BoringMetrics
9
+ class Railtie < ::Rails::Railtie
10
+ initializer "boringmetrics.middleware" do |app|
11
+ app.middleware.use Middleware
12
+ end
13
+
14
+ # Log Rails errors to BoringMetrics
15
+ config.after_initialize do
16
+ ActiveSupport::Notifications.subscribe("process_action.action_controller") do |*args|
17
+ event = ActiveSupport::Notifications::Event.new(*args)
18
+ exception = event.payload[:exception_object]
19
+
20
+ if exception && defined?(BoringMetrics.client) && BoringMetrics.client
21
+ BoringMetrics.logs.send(
22
+ type: "log",
23
+ level: "error",
24
+ message: exception.message,
25
+ data: {
26
+ exception: exception.class.name,
27
+ backtrace: exception.backtrace&.first(10),
28
+ controller: event.payload[:controller],
29
+ action: event.payload[:action]
30
+ }
31
+ )
32
+ end
33
+ end
34
+ end
35
+ end
36
+ end
37
+ end
@@ -0,0 +1,7 @@
1
+ # frozen_string_literal: true
2
+
3
+ module BoringMetrics
4
+ module Rails
5
+ VERSION = "0.1.0"
6
+ end
7
+ end
@@ -0,0 +1,21 @@
1
+ # frozen_string_literal: true
2
+
3
+ require "boringmetrics"
4
+ require_relative "boringmetrics-rails/version"
5
+ require_relative "boringmetrics-rails/railtie"
6
+
7
+ module BoringMetrics
8
+ # Rails integration for BoringMetrics
9
+ module Rails
10
+ class << self
11
+ # Initialize the SDK with Rails integration
12
+ #
13
+ # @param token [String] Your BoringMetrics API token
14
+ # @param config [Hash] Optional configuration options
15
+ # @return [BoringMetrics::Client] The initialized client
16
+ def initialize(token, **config)
17
+ BoringMetrics.initialize(token, **config)
18
+ end
19
+ end
20
+ end
21
+ end
metadata ADDED
@@ -0,0 +1,120 @@
1
+ --- !ruby/object:Gem::Specification
2
+ name: boringmetrics-rails
3
+ version: !ruby/object:Gem::Version
4
+ version: 0.1.0
5
+ platform: ruby
6
+ authors:
7
+ - Aymeric Chauvin
8
+ bindir: bin
9
+ cert_chain: []
10
+ date: 2025-05-15 00:00:00.000000000 Z
11
+ dependencies:
12
+ - !ruby/object:Gem::Dependency
13
+ name: boringmetrics
14
+ requirement: !ruby/object:Gem::Requirement
15
+ requirements:
16
+ - - '='
17
+ - !ruby/object:Gem::Version
18
+ version: 0.1.0
19
+ type: :runtime
20
+ prerelease: false
21
+ version_requirements: !ruby/object:Gem::Requirement
22
+ requirements:
23
+ - - '='
24
+ - !ruby/object:Gem::Version
25
+ version: 0.1.0
26
+ - !ruby/object:Gem::Dependency
27
+ name: railties
28
+ requirement: !ruby/object:Gem::Requirement
29
+ requirements:
30
+ - - ">="
31
+ - !ruby/object:Gem::Version
32
+ version: '5.0'
33
+ type: :runtime
34
+ prerelease: false
35
+ version_requirements: !ruby/object:Gem::Requirement
36
+ requirements:
37
+ - - ">="
38
+ - !ruby/object:Gem::Version
39
+ version: '5.0'
40
+ - !ruby/object:Gem::Dependency
41
+ name: bundler
42
+ requirement: !ruby/object:Gem::Requirement
43
+ requirements:
44
+ - - "~>"
45
+ - !ruby/object:Gem::Version
46
+ version: '2.0'
47
+ type: :development
48
+ prerelease: false
49
+ version_requirements: !ruby/object:Gem::Requirement
50
+ requirements:
51
+ - - "~>"
52
+ - !ruby/object:Gem::Version
53
+ version: '2.0'
54
+ - !ruby/object:Gem::Dependency
55
+ name: rake
56
+ requirement: !ruby/object:Gem::Requirement
57
+ requirements:
58
+ - - "~>"
59
+ - !ruby/object:Gem::Version
60
+ version: '13.0'
61
+ type: :development
62
+ prerelease: false
63
+ version_requirements: !ruby/object:Gem::Requirement
64
+ requirements:
65
+ - - "~>"
66
+ - !ruby/object:Gem::Version
67
+ version: '13.0'
68
+ - !ruby/object:Gem::Dependency
69
+ name: rubocop
70
+ requirement: !ruby/object:Gem::Requirement
71
+ requirements:
72
+ - - "~>"
73
+ - !ruby/object:Gem::Version
74
+ version: '1.21'
75
+ type: :development
76
+ prerelease: false
77
+ version_requirements: !ruby/object:Gem::Requirement
78
+ requirements:
79
+ - - "~>"
80
+ - !ruby/object:Gem::Version
81
+ version: '1.21'
82
+ description: Rails integration for the Boring Metrics Ruby SDK. It provides Rails-specific
83
+ functionality for the Boring Metrics API.
84
+ email:
85
+ - contact@halftheopposite.dev
86
+ executables: []
87
+ extensions: []
88
+ extra_rdoc_files: []
89
+ files:
90
+ - LICENSE
91
+ - README.md
92
+ - lib/boringmetrics-rails.rb
93
+ - lib/boringmetrics-rails/middleware.rb
94
+ - lib/boringmetrics-rails/railtie.rb
95
+ - lib/boringmetrics-rails/version.rb
96
+ homepage: https://github.com/boringmetrics/ruby-sdk
97
+ licenses:
98
+ - MIT
99
+ metadata:
100
+ homepage_uri: https://github.com/boringmetrics/ruby-sdk
101
+ source_code_uri: https://github.com/boringmetrics/ruby-sdk
102
+ changelog_uri: https://github.com/boringmetrics/ruby-sdk/blob/main/CHANGELOG.md
103
+ rdoc_options: []
104
+ require_paths:
105
+ - lib
106
+ required_ruby_version: !ruby/object:Gem::Requirement
107
+ requirements:
108
+ - - ">="
109
+ - !ruby/object:Gem::Version
110
+ version: 2.6.0
111
+ required_rubygems_version: !ruby/object:Gem::Requirement
112
+ requirements:
113
+ - - ">="
114
+ - !ruby/object:Gem::Version
115
+ version: '0'
116
+ requirements: []
117
+ rubygems_version: 3.6.2
118
+ specification_version: 4
119
+ summary: Rails integration for Boring Metrics
120
+ test_files: []