logtail-rails 0.2.10 → 0.2.11

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: 6b503273fbd0b4fbe3c6ef7cfd1c07a4e0c1e3a91f8736fce93dce5d46df1d31
4
- data.tar.gz: bb996b21390b25b3be1445ec99c6674bc583d1278b32b515fdc42d2dc4beca9c
3
+ metadata.gz: 591e29df9a10485d143f414b59fc443ee9ddf793a15c866aaedfd606613140d9
4
+ data.tar.gz: 36d0d2e06481593c0eb1ec1b19c7db48631392e7b1c09d03fb186a0a5e9d85a5
5
5
  SHA512:
6
- metadata.gz: 3194e5a635d7615acd0ea104e9d39184fbaaded715804712be2738361e63c0e9b5dfab7fd02542d7172b7d02021fa7796429402fa8f1192c366ff55bab62cff7
7
- data.tar.gz: 7ca05f29eb60048f6a60da2afbdeca8a8b7082e8e036966bb22225b8c8675793cd8ec5912f8e55afd5bfb5ab890a35f74b82eebcb0af6fb3af133d38e5902414
6
+ metadata.gz: f30c68aaf72c06de9bacd6282c8eb82fd1d75d8a1153a106ffe826670182154b881cf6dfaca24307da3b7ed4ade2c9565c3a3dd25a530fb8ab82a2a05dfe1c81
7
+ data.tar.gz: 19a5c1cc60f9225870fecd768f2ebe13c3f9604dba7ce01141f8d39d79d68ce4b56042026b5c797c344cd8320f4765042d29918b67aa5d40d5be98f0f179b46f
@@ -1,19 +1,19 @@
1
1
  source "https://rubygems.org"
2
2
  git_source(:github) { |repo| "https://github.com/#{repo}.git" }
3
3
 
4
- ruby "3.2.2"
4
+ ruby "3.3.4"
5
5
 
6
6
  # Bundle edge Rails instead: gem "rails", github: "rails/rails", branch: "main"
7
- gem "rails", "~> 7.1.0"
7
+ gem "rails", "~> 8.1.0.rc1"
8
8
 
9
9
  # The original asset pipeline for Rails [https://github.com/rails/sprockets-rails]
10
10
  gem "sprockets-rails"
11
11
 
12
12
  # Use sqlite3 as the database for Active Record
13
- gem "sqlite3", "~> 1.4"
13
+ gem "sqlite3", "~> 2.1"
14
14
 
15
15
  # Use the Puma web server [https://github.com/puma/puma]
16
- gem "puma", "~> 6.0"
16
+ gem "puma", "~> 6.4"
17
17
 
18
18
  # Use JavaScript with ESM import maps [https://github.com/rails/importmap-rails]
19
19
  gem "importmap-rails"
@@ -71,4 +71,4 @@ group :test do
71
71
  gem "webdrivers"
72
72
  end
73
73
 
74
- gem "logtail-rails", "~> 0.2.10"
74
+ gem "logtail-rails", "~> 0.2.11"
@@ -36,5 +36,15 @@ class ExampleController < ApplicationController
36
36
  },
37
37
  id: 123456
38
38
  )
39
+
40
+ # Since Rails 8.1, you can also use the Rails.event to send events with structured data to Better Stack.
41
+ Rails.event.notify("My first event", user_id: 123, email: "user@example.com")
42
+
43
+ # You can add context to all events
44
+ Rails.event.set_context(request_id: "abc123", shop_id: 456)
45
+ # And tags specific events
46
+ Rails.event.tagged("api") do
47
+ Rails.event.notify("My tagged event with additional context", user_id: 123, email: "user@example.com")
48
+ end
39
49
  end
40
50
  end
@@ -9,7 +9,7 @@ Bundler.require(*Rails.groups)
9
9
  module ExampleProject
10
10
  class Application < Rails::Application
11
11
  # Initialize configuration defaults for originally generated Rails version.
12
- config.load_defaults 7.1
12
+ config.load_defaults 8.1
13
13
 
14
14
  # Configuration for the application, engines, and railties goes here.
15
15
  #
@@ -20,8 +20,8 @@ module ExampleProject
20
20
  # config.eager_load_paths << Rails.root.join("extras")
21
21
 
22
22
  config.logger = Logtail::Logger.create_default_logger(
23
- "<SOURCE_TOKEN>",
24
- ingesting_host: "<INGESTING_HOST>",
23
+ "gLfvoCKSYwgzDtpHRC3hqdmH",
24
+ ingesting_host: "s1382247.us-east-9.betterstackdata.com",
25
25
  )
26
26
  end
27
27
  end
@@ -0,0 +1,58 @@
1
+ module Logtail
2
+ module Integrations
3
+ module Rails
4
+ # A subscriber for Rails 8.1's Structured Event Reporting system.
5
+ # This subscriber receives events emitted by Rails.event.notify() and logs
6
+ # them with all their data to Rails.logger, which sends them to Better Stack.
7
+ class EventLogSubscriber
8
+ # Rails logger instance
9
+ attr_reader :logger
10
+
11
+ # Log level to use for logging events
12
+ mattr_accessor :log_level, default: :info
13
+
14
+ # Allows to disable the subscriber
15
+ mattr_accessor :enabled, default: true
16
+
17
+ # Initialize the subscriber with a logger instance
18
+ def initialize(logger)
19
+ @logger = logger
20
+ end
21
+
22
+ # Rails 8.1 event emission method - called when events are emitted
23
+ def emit(event)
24
+ return unless self.class.enabled
25
+
26
+ # Log the event with all its data to Rails.logger
27
+ # Create a structured log entry with the event data
28
+ tags = event[:tags]
29
+ tags_array = tags.is_a?(Hash) ? tags.keys : (tags.is_a?(Array) ? tags : [])
30
+
31
+ log_data = {
32
+ event_name: event[:name],
33
+ payload: event[:payload] || {},
34
+ context: event[:context] || {},
35
+ tags: tags_array,
36
+ source_location: event[:source_location] || {}
37
+ }
38
+
39
+ message = build_log_message(event)
40
+ logger.info("hello")
41
+ logger.send(self.class.log_level, message, log_data)
42
+ end
43
+
44
+ private
45
+
46
+ def build_log_message(event)
47
+ payload = event[:payload] || {}
48
+ payload_str = payload.map { |key, value| "#{key}=#{value}" }.join(" ")
49
+
50
+ source_location = event[:source_location] || {}
51
+ source_str = "at #{source_location[:filepath]}:#{source_location[:lineno]}" if source_location[:filepath] && source_location[:lineno]
52
+
53
+ "[#{event[:name]}] #{payload_str} #{source_str}".strip
54
+ end
55
+ end
56
+ end
57
+ end
58
+ end
@@ -78,6 +78,9 @@ module Logtail
78
78
  end
79
79
  end
80
80
 
81
+ # For Rails 8.1 and above, subscribe to the event system
82
+ Rails.event.subscribe(Logtail::Integrations::Rails::EventLogSubscriber.new(logger)) if Rails.respond_to?(:event)
83
+
81
84
  logger
82
85
  end
83
86
  end
@@ -1,7 +1,7 @@
1
1
  module Logtail
2
2
  module Integrations
3
3
  module Rails
4
- VERSION = "0.2.10"
4
+ VERSION = "0.2.11"
5
5
  end
6
6
  end
7
7
  end
data/lib/logtail-rails.rb CHANGED
@@ -7,6 +7,7 @@ require "active_record"
7
7
  require "rack"
8
8
 
9
9
  require "logtail-rails/active_support_log_subscriber"
10
+ require "logtail-rails/event_log_subscriber"
10
11
  require "logtail-rails/config"
11
12
  require "logtail-rails/railtie"
12
13
 
@@ -55,6 +56,7 @@ module Logtail
55
56
  ActionController.enabled = value
56
57
  ActionView.enabled = value
57
58
  ActiveRecord.enabled = value
59
+ EventLogSubscriber.enabled = value
58
60
  end
59
61
 
60
62
  # All enabled middlewares. The order is relevant. Middlewares that set
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: logtail-rails
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.2.10
4
+ version: 0.2.11
5
5
  platform: ruby
6
6
  authors:
7
7
  - Better Stack
8
8
  autorequire:
9
9
  bindir: exe
10
10
  cert_chain: []
11
- date: 2025-02-11 00:00:00.000000000 Z
11
+ date: 2025-10-16 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: logtail
@@ -334,6 +334,7 @@ files:
334
334
  - lib/logtail-rails/config/action_view.rb
335
335
  - lib/logtail-rails/config/active_record.rb
336
336
  - lib/logtail-rails/error_event.rb
337
+ - lib/logtail-rails/event_log_subscriber.rb
337
338
  - lib/logtail-rails/log_entry.rb
338
339
  - lib/logtail-rails/logger.rb
339
340
  - lib/logtail-rails/overrides.rb