logtail-rails 0.2.9 → 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: 5c6ccb46b27ddea66626e2521d985fd1d94bbae9c736b6d2decdb60e21648bdf
4
- data.tar.gz: 755fc58643d694cff87fc4297dbc77660b74e25e4ac5d624adbc1ed8be9c7529
3
+ metadata.gz: 591e29df9a10485d143f414b59fc443ee9ddf793a15c866aaedfd606613140d9
4
+ data.tar.gz: 36d0d2e06481593c0eb1ec1b19c7db48631392e7b1c09d03fb186a0a5e9d85a5
5
5
  SHA512:
6
- metadata.gz: 445b43b604ee29baf7c428dc49372a66cb31294e70b4092415b89d669839889ff549e4d642daf07d5d1e1083b040f1f3f27a254c37f1846e18d1b13ef2c704aa
7
- data.tar.gz: 5e0ed7ae395830f9372f7213d48ad29604dafa4f8aa8d72a3cf60fd6d5fd7b11fc7836872f95c8849161915ecd9174a3efd33644dd12967e0d6828a45656d168
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.9"
74
+ gem "logtail-rails", "~> 0.2.11"
@@ -16,7 +16,7 @@ Then replace `<SOURCE_TOKEN>` and `<INGESTING_HOST>` in `config/application.rb`
16
16
  ```ruby
17
17
  config.logger = Logtail::Logger.create_default_logger(
18
18
  "<YOUR_ACTUAL_SOURCE_TOKEN>",
19
- telemetry_host: "in.logs.betterstack.com",
19
+ ingesting_host: "in.logs.betterstack.com",
20
20
  )
21
21
  ```
22
22
 
@@ -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
- telemetry_host: "<INGESTING_HOST>",
23
+ "gLfvoCKSYwgzDtpHRC3hqdmH",
24
+ ingesting_host: "s1382247.us-east-9.betterstackdata.com",
25
25
  )
26
26
  end
27
27
  end
@@ -6,6 +6,10 @@ gem 'sidekiq', '>= 7.3.0', require: false if RUBY_VERSION >= '2.7.0'
6
6
  gem 'logtail'
7
7
  gem 'logtail-rack'
8
8
 
9
+ if RUBY_VERSION >= "3.4.0"
10
+ gem 'mutex_m'
11
+ end
12
+
9
13
  if RUBY_PLATFORM == "java"
10
14
  gem 'mime-types', '2.6.2'
11
15
  end
@@ -6,6 +6,10 @@ gem 'sidekiq', '>= 7.3.0', require: false if RUBY_VERSION >= '2.7.0'
6
6
  gem 'logtail'
7
7
  gem 'logtail-rack'
8
8
 
9
+ if RUBY_VERSION >= "3.4.0"
10
+ gem 'mutex_m'
11
+ end
12
+
9
13
  if RUBY_PLATFORM == "java"
10
14
  gem 'mime-types', '2.6.2'
11
15
  end
@@ -6,6 +6,10 @@ gem 'sidekiq', '>= 7.3.0', require: false if RUBY_VERSION >= '2.7.0'
6
6
  gem 'logtail'
7
7
  gem 'logtail-rack'
8
8
 
9
+ if RUBY_VERSION >= "3.4.0"
10
+ gem 'mutex_m'
11
+ end
12
+
9
13
  if RUBY_PLATFORM == "java"
10
14
  gem 'mime-types', '2.6.2'
11
15
  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
@@ -56,10 +56,10 @@ module Logtail
56
56
  end
57
57
 
58
58
  def self.create_default_logger(source_token, options = {})
59
- # Handle backward-compatibility of argument names
60
- options[:logtail_host] ||= options[:telemetry_host] if options[:telemetry_host].present?
61
- options[:logtail_port] ||= options[:telemetry_port] if options[:telemetry_port].present?
62
- options[:logtail_scheme] ||= options[:telemetry_scheme] if options[:telemetry_scheme].present?
59
+ # Handle backward-compatibility of argument names from v0.2.9
60
+ options[:ingesting_host] ||= options[:telemetry_host] if options[:telemetry_host].present?
61
+ options[:ingesting_port] ||= options[:telemetry_port] if options[:telemetry_port].present?
62
+ options[:ingesting_scheme] ||= options[:telemetry_scheme] if options[:telemetry_scheme].present?
63
63
 
64
64
  if ENV['LOGTAIL_SKIP_LOGS'].blank? && !Rails.env.test?
65
65
  io_device = Logtail::LogDevices::HTTP.new(source_token, options)
@@ -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,5 +1,5 @@
1
1
  # Logtail and lograge are not compatible installed together. Using lograge
2
- # with the Logtail.com *service* is perfectly fine, but not with the Logtail *gem*.
2
+ # with the Better Stack Telemetry *service* is perfectly fine, but not with the Logtail *gem*.
3
3
  #
4
4
  # Logtail does ship with a {Logtail::Config#logrageify!} option that configures
5
5
  # Logtail to behave similarly to Lograge (silencing various logs). Check out
@@ -1,7 +1,7 @@
1
1
  module Logtail
2
2
  module Integrations
3
3
  module Rails
4
- VERSION = "0.2.9"
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
@@ -27,7 +27,7 @@ Gem::Specification.new do |spec|
27
27
  spec.executables = spec.files.grep(%r{^exe/}) { |f| File.basename(f) }
28
28
  spec.require_paths = ["lib"]
29
29
 
30
- spec.add_runtime_dependency "logtail", "~> 0.1"
30
+ spec.add_runtime_dependency "logtail", "~> 0.1", ">= 0.1.14"
31
31
  spec.add_runtime_dependency "logtail-rack", "~> 0.1"
32
32
 
33
33
  spec.add_runtime_dependency 'activerecord', '>= 5.0.0'
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.9
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-03 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
@@ -17,6 +17,9 @@ dependencies:
17
17
  - - "~>"
18
18
  - !ruby/object:Gem::Version
19
19
  version: '0.1'
20
+ - - ">="
21
+ - !ruby/object:Gem::Version
22
+ version: 0.1.14
20
23
  type: :runtime
21
24
  prerelease: false
22
25
  version_requirements: !ruby/object:Gem::Requirement
@@ -24,6 +27,9 @@ dependencies:
24
27
  - - "~>"
25
28
  - !ruby/object:Gem::Version
26
29
  version: '0.1'
30
+ - - ">="
31
+ - !ruby/object:Gem::Version
32
+ version: 0.1.14
27
33
  - !ruby/object:Gem::Dependency
28
34
  name: logtail-rack
29
35
  requirement: !ruby/object:Gem::Requirement
@@ -328,6 +334,7 @@ files:
328
334
  - lib/logtail-rails/config/action_view.rb
329
335
  - lib/logtail-rails/config/active_record.rb
330
336
  - lib/logtail-rails/error_event.rb
337
+ - lib/logtail-rails/event_log_subscriber.rb
331
338
  - lib/logtail-rails/log_entry.rb
332
339
  - lib/logtail-rails/logger.rb
333
340
  - lib/logtail-rails/overrides.rb