foam-ruby 0.1.0.alpha4 → 0.1.0.alpha6

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: 1d76d514553861aade3abed6a2c607d2d97906869ae85e441c066be755d025ab
4
- data.tar.gz: 5e79a5adaffe152567dffad68f0b5247b560415c2ebb59830b5293381f1e2ded
3
+ metadata.gz: '039cdc9710beb8c5ebc5caf48a4d26ebc906af5843a2effcaa6e23516de0a5e0'
4
+ data.tar.gz: 239ff4c8bfcaf6d56659bdb306cdabf93452c8db7713772bdfe4ef37080b326d
5
5
  SHA512:
6
- metadata.gz: 746dcac38e096f124a8c9b4f07048d58e71738fdea1dd1450fd6c4ea9b39503ebf0fa202f0e440e1edc9571a601bd0b17f6ff34898f2091d2b7b3a87bce1d13c
7
- data.tar.gz: 62bf146e6ac5f2b671e33e91ed797ed3684b7e686067cde33a8960ff436c184c2cfbe143ca719d8afac81d5d5df8e10eee5987966e19212a8dbc1482d6daa98b
6
+ metadata.gz: 73478d74ae9823f7c9c88f58da21f1eab4fe6338d67e25b847d83f024b86229217f6a41170f1799161670680b45cfa4e602ba2dea9c06fe53282159afab56bd7
7
+ data.tar.gz: 654295ea96663ef4399f01ccb6d98bc6fa17f2eac3f6cc81523e8a9f6f6de7ca0bec0f23743b9c241d1c961ebc38d3ef0c268ee42868c64843474ffc9630496c
data/README.md CHANGED
@@ -35,17 +35,6 @@ That's it. The gem will:
35
35
 
36
36
  ## Configuration
37
37
 
38
- ### Block syntax
39
-
40
- ```ruby
41
- Foam::Ruby.configure do |c|
42
- c.token = ENV["FOAM_API_TOKEN"]
43
- c.service_name = "my-rails-app"
44
- c.traces_enabled = true
45
- c.logs_enabled = true
46
- end
47
- ```
48
-
49
38
  ### Environment variables
50
39
 
51
40
  | Variable | Description | Default |
@@ -54,17 +43,6 @@ end
54
43
  | `OTEL_SERVICE_NAME` | Service name for telemetry | `rails-app` |
55
44
  | `FOAM_OTEL_ENDPOINT` | OTLP collector endpoint | `https://otel.api.foam.ai` |
56
45
 
57
- ### Disabling signals
58
-
59
- ```ruby
60
- Foam::Ruby.init(
61
- token: ENV["FOAM_API_TOKEN"],
62
- service_name: "my-rails-app",
63
- traces: false, # disable trace collection
64
- logs: true
65
- )
66
- ```
67
-
68
46
  ## How It Works
69
47
 
70
48
  ### Rails.logger → OTel Logs
@@ -95,20 +73,13 @@ rescue => e
95
73
  end
96
74
  ```
97
75
 
98
- ### Additional Instrumentations
76
+ ### Sentry Integration
99
77
 
100
- Pass extra OpenTelemetry instrumentations:
78
+ If Sentry is in your Gemfile, the gem automatically bridges `Sentry.capture_exception` to forward errors to Foam. No configuration needed.
101
79
 
102
- ```ruby
103
- Foam::Ruby.init(
104
- token: ENV["FOAM_API_TOKEN"],
105
- service_name: "my-rails-app",
106
- instrumentations: [
107
- "OpenTelemetry::Instrumentation::Sidekiq",
108
- "OpenTelemetry::Instrumentation::Redis",
109
- ]
110
- )
111
- ```
80
+ ### Production Only
81
+
82
+ The gem only initializes in production (`RAILS_ENV=production` or `RACK_ENV=production`). In development and test, all calls are silent no-ops — zero overhead, zero side effects.
112
83
 
113
84
  ## Rails Compatibility
114
85
 
@@ -5,17 +5,12 @@ module Foam
5
5
  class Configuration
6
6
  FOAM_OTEL_ENDPOINT = "https://otel.api.foam.ai"
7
7
 
8
- attr_accessor :token, :service_name, :endpoint,
9
- :traces_enabled, :logs_enabled,
10
- :additional_instrumentations
8
+ attr_accessor :token, :service_name, :endpoint
11
9
 
12
10
  def initialize
13
11
  @token = ENV["FOAM_API_TOKEN"]
14
12
  @service_name = ENV.fetch("OTEL_SERVICE_NAME", "rails-app")
15
13
  @endpoint = ENV.fetch("FOAM_OTEL_ENDPOINT", FOAM_OTEL_ENDPOINT)
16
- @traces_enabled = true
17
- @logs_enabled = true
18
- @additional_instrumentations = []
19
14
  end
20
15
 
21
16
  def otel_headers
@@ -12,8 +12,8 @@ module Foam
12
12
  module_function
13
13
 
14
14
  def configure!(config)
15
- configure_traces(config) if config.traces_enabled
16
- configure_logs(config) if config.logs_enabled
15
+ configure_traces(config)
16
+ configure_logs(config)
17
17
  end
18
18
 
19
19
  def configure_traces(config)
@@ -2,6 +2,6 @@
2
2
 
3
3
  module Foam
4
4
  module Ruby
5
- VERSION = "0.1.0.alpha4"
5
+ VERSION = "0.1.0.alpha6"
6
6
  end
7
7
  end
data/lib/foam/ruby.rb CHANGED
@@ -10,30 +10,14 @@ module Foam
10
10
  @initialized == true
11
11
  end
12
12
 
13
- def configuration
14
- @configuration ||= Configuration.new
15
- end
16
-
17
- def configure
18
- yield(configuration) if block_given?
19
- configuration
20
- end
13
+ def init(token: nil, service_name: nil)
14
+ return unless production?
21
15
 
22
- def init(token: nil, service_name: nil, endpoint: nil, **options)
23
- unless production?
24
- return
25
- end
26
-
27
- configure do |c|
28
- c.token = token if token
29
- c.service_name = service_name if service_name
30
- c.endpoint = endpoint if endpoint
31
- c.traces_enabled = options.fetch(:traces, true)
32
- c.logs_enabled = options.fetch(:logs, true)
33
- c.additional_instrumentations = options[:instrumentations] || []
34
- end
16
+ config = configuration
17
+ config.token = token if token
18
+ config.service_name = service_name if service_name
35
19
 
36
- unless configuration.valid?
20
+ unless config.valid?
37
21
  warn "[foam-ruby] Missing token — set FOAM_API_TOKEN or pass token: to Foam::Ruby.init"
38
22
  return
39
23
  end
@@ -41,10 +25,11 @@ module Foam
41
25
  require_relative "ruby/otel_setup"
42
26
  require_relative "ruby/log_subscriber"
43
27
 
44
- OtelSetup.configure!(configuration)
45
- schedule_logger_attach! if configuration.logs_enabled
28
+ OtelSetup.configure!(config)
29
+ schedule_logger_attach!
30
+ bridge_sentry!
46
31
  @initialized = true
47
- rescue StandardError => e
32
+ rescue Exception => e # rubocop:disable Lint/RescueException
48
33
  warn "[foam-ruby] init failed: #{e.message}"
49
34
  @initialized = false
50
35
  end
@@ -67,15 +52,23 @@ module Foam
67
52
 
68
53
  span.record_exception(error, attributes: attrs)
69
54
  span.status = OpenTelemetry::Trace::Status.error(error.message)
70
- rescue StandardError => e
71
- warn "[foam-ruby] capture_exception failed: #{e.message}"
55
+ rescue Exception # rubocop:disable Lint/RescueException
56
+ nil
72
57
  end
73
58
 
74
59
  private
75
60
 
61
+ def configuration
62
+ @configuration ||= Configuration.new
63
+ rescue Exception # rubocop:disable Lint/RescueException
64
+ Configuration.new
65
+ end
66
+
76
67
  def production?
77
68
  env = ENV["RAILS_ENV"] || ENV["RACK_ENV"] || "development"
78
69
  env.downcase == "production"
70
+ rescue Exception # rubocop:disable Lint/RescueException
71
+ false
79
72
  end
80
73
 
81
74
  def schedule_logger_attach!
@@ -86,15 +79,31 @@ module Foam
86
79
  else
87
80
  do_attach_otel_logger!
88
81
  end
89
- rescue StandardError => e
90
- warn "[foam-ruby] Failed to schedule OTel logger attach: #{e.message}"
82
+ rescue Exception # rubocop:disable Lint/RescueException
83
+ nil
84
+ end
85
+
86
+ def bridge_sentry!
87
+ return unless defined?(::Rails) && ::Rails.respond_to?(:application) && ::Rails.application
88
+
89
+ ::Rails.application.config.after_initialize do
90
+ next unless defined?(::Sentry)
91
+
92
+ ::Sentry.singleton_class.prepend(Module.new do
93
+ def capture_exception(exception, **options, &block)
94
+ Foam::Ruby.capture_exception(exception) if exception.is_a?(::Exception)
95
+ super
96
+ end
97
+ end)
98
+ end
99
+ rescue Exception # rubocop:disable Lint/RescueException
100
+ nil
91
101
  end
92
102
 
93
103
  def do_attach_otel_logger!
94
104
  return unless ::Rails.respond_to?(:logger) && ::Rails.logger
95
105
 
96
106
  unless OpenTelemetry.logger_provider.is_a?(OpenTelemetry::SDK::Logs::LoggerProvider)
97
- warn "[foam-ruby] OTel logger provider not configured — call Foam::Ruby.init before attaching logger"
98
107
  return
99
108
  end
100
109
 
@@ -105,8 +114,8 @@ module Foam
105
114
  elsif defined?(::ActiveSupport::Logger) && ::ActiveSupport::Logger.respond_to?(:broadcast)
106
115
  ::Rails.logger.extend(::ActiveSupport::Logger.broadcast(otel_logger))
107
116
  end
108
- rescue StandardError => e
109
- warn "[foam-ruby] Failed to attach OTel logger to Rails.logger: #{e.message}"
117
+ rescue Exception # rubocop:disable Lint/RescueException
118
+ nil
110
119
  end
111
120
  end
112
121
  end
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: foam-ruby
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.1.0.alpha4
4
+ version: 0.1.0.alpha6
5
5
  platform: ruby
6
6
  authors:
7
7
  - Foam