foam-ruby 0.1.0.alpha4 → 0.1.0.alpha5
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 +4 -4
- data/README.md +5 -23
- data/lib/foam/ruby/configuration.rb +1 -3
- data/lib/foam/ruby/version.rb +1 -1
- data/lib/foam/ruby.rb +43 -31
- metadata +1 -1
checksums.yaml
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
---
|
|
2
2
|
SHA256:
|
|
3
|
-
metadata.gz:
|
|
4
|
-
data.tar.gz:
|
|
3
|
+
metadata.gz: 57eba0f562797a93af9440bf8cc80c2e80009200837d5ac647e01c832a85e07e
|
|
4
|
+
data.tar.gz: 9c68ec68a95f652a90840cb21c285746ca317724c92b10ba272e25708210104e
|
|
5
5
|
SHA512:
|
|
6
|
-
metadata.gz:
|
|
7
|
-
data.tar.gz:
|
|
6
|
+
metadata.gz: 2f8f50ce67167cdb2e48382c6166abd767b22aa86b6ff01cc3762fa5fa8305cea5ce766b06877c6a257878b6e52c64cb063fc521e2f7b3a3cf41645e9fd306e7
|
|
7
|
+
data.tar.gz: 8ab6d387a971d5111e3ee7b864715eb15872ab976e5ab7f06a215b0d3e6c943e401050a883f725f35bfb46d4c8e6db1760eb40d2236da586d78cf76b267b8e9e
|
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 |
|
|
@@ -95,20 +84,13 @@ rescue => e
|
|
|
95
84
|
end
|
|
96
85
|
```
|
|
97
86
|
|
|
98
|
-
###
|
|
87
|
+
### Sentry Integration
|
|
99
88
|
|
|
100
|
-
|
|
89
|
+
If Sentry is in your Gemfile, the gem automatically bridges `Sentry.capture_exception` to forward errors to Foam. No configuration needed.
|
|
101
90
|
|
|
102
|
-
|
|
103
|
-
|
|
104
|
-
|
|
105
|
-
service_name: "my-rails-app",
|
|
106
|
-
instrumentations: [
|
|
107
|
-
"OpenTelemetry::Instrumentation::Sidekiq",
|
|
108
|
-
"OpenTelemetry::Instrumentation::Redis",
|
|
109
|
-
]
|
|
110
|
-
)
|
|
111
|
-
```
|
|
91
|
+
### Production Only
|
|
92
|
+
|
|
93
|
+
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
94
|
|
|
113
95
|
## Rails Compatibility
|
|
114
96
|
|
|
@@ -6,8 +6,7 @@ module Foam
|
|
|
6
6
|
FOAM_OTEL_ENDPOINT = "https://otel.api.foam.ai"
|
|
7
7
|
|
|
8
8
|
attr_accessor :token, :service_name, :endpoint,
|
|
9
|
-
:traces_enabled, :logs_enabled
|
|
10
|
-
:additional_instrumentations
|
|
9
|
+
:traces_enabled, :logs_enabled
|
|
11
10
|
|
|
12
11
|
def initialize
|
|
13
12
|
@token = ENV["FOAM_API_TOKEN"]
|
|
@@ -15,7 +14,6 @@ module Foam
|
|
|
15
14
|
@endpoint = ENV.fetch("FOAM_OTEL_ENDPOINT", FOAM_OTEL_ENDPOINT)
|
|
16
15
|
@traces_enabled = true
|
|
17
16
|
@logs_enabled = true
|
|
18
|
-
@additional_instrumentations = []
|
|
19
17
|
end
|
|
20
18
|
|
|
21
19
|
def otel_headers
|
data/lib/foam/ruby/version.rb
CHANGED
data/lib/foam/ruby.rb
CHANGED
|
@@ -10,30 +10,17 @@ 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
|
|
21
|
-
|
|
22
13
|
def init(token: nil, service_name: nil, endpoint: nil, **options)
|
|
23
|
-
unless production?
|
|
24
|
-
return
|
|
25
|
-
end
|
|
14
|
+
return unless production?
|
|
26
15
|
|
|
27
|
-
|
|
28
|
-
|
|
29
|
-
|
|
30
|
-
|
|
31
|
-
|
|
32
|
-
|
|
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
|
|
19
|
+
config.endpoint = endpoint if endpoint
|
|
20
|
+
config.traces_enabled = options.fetch(:traces, true)
|
|
21
|
+
config.logs_enabled = options.fetch(:logs, true)
|
|
35
22
|
|
|
36
|
-
unless
|
|
23
|
+
unless config.valid?
|
|
37
24
|
warn "[foam-ruby] Missing token — set FOAM_API_TOKEN or pass token: to Foam::Ruby.init"
|
|
38
25
|
return
|
|
39
26
|
end
|
|
@@ -41,10 +28,11 @@ module Foam
|
|
|
41
28
|
require_relative "ruby/otel_setup"
|
|
42
29
|
require_relative "ruby/log_subscriber"
|
|
43
30
|
|
|
44
|
-
OtelSetup.configure!(
|
|
45
|
-
schedule_logger_attach! if
|
|
31
|
+
OtelSetup.configure!(config)
|
|
32
|
+
schedule_logger_attach! if config.logs_enabled
|
|
33
|
+
bridge_sentry!
|
|
46
34
|
@initialized = true
|
|
47
|
-
rescue
|
|
35
|
+
rescue Exception => e # rubocop:disable Lint/RescueException
|
|
48
36
|
warn "[foam-ruby] init failed: #{e.message}"
|
|
49
37
|
@initialized = false
|
|
50
38
|
end
|
|
@@ -67,15 +55,23 @@ module Foam
|
|
|
67
55
|
|
|
68
56
|
span.record_exception(error, attributes: attrs)
|
|
69
57
|
span.status = OpenTelemetry::Trace::Status.error(error.message)
|
|
70
|
-
rescue
|
|
71
|
-
|
|
58
|
+
rescue Exception # rubocop:disable Lint/RescueException
|
|
59
|
+
nil
|
|
72
60
|
end
|
|
73
61
|
|
|
74
62
|
private
|
|
75
63
|
|
|
64
|
+
def configuration
|
|
65
|
+
@configuration ||= Configuration.new
|
|
66
|
+
rescue Exception # rubocop:disable Lint/RescueException
|
|
67
|
+
Configuration.new
|
|
68
|
+
end
|
|
69
|
+
|
|
76
70
|
def production?
|
|
77
71
|
env = ENV["RAILS_ENV"] || ENV["RACK_ENV"] || "development"
|
|
78
72
|
env.downcase == "production"
|
|
73
|
+
rescue Exception # rubocop:disable Lint/RescueException
|
|
74
|
+
false
|
|
79
75
|
end
|
|
80
76
|
|
|
81
77
|
def schedule_logger_attach!
|
|
@@ -86,15 +82,31 @@ module Foam
|
|
|
86
82
|
else
|
|
87
83
|
do_attach_otel_logger!
|
|
88
84
|
end
|
|
89
|
-
rescue
|
|
90
|
-
|
|
85
|
+
rescue Exception # rubocop:disable Lint/RescueException
|
|
86
|
+
nil
|
|
87
|
+
end
|
|
88
|
+
|
|
89
|
+
def bridge_sentry!
|
|
90
|
+
return unless defined?(::Rails) && ::Rails.respond_to?(:application) && ::Rails.application
|
|
91
|
+
|
|
92
|
+
::Rails.application.config.after_initialize do
|
|
93
|
+
next unless defined?(::Sentry)
|
|
94
|
+
|
|
95
|
+
::Sentry.singleton_class.prepend(Module.new do
|
|
96
|
+
def capture_exception(exception, **options, &block)
|
|
97
|
+
Foam::Ruby.capture_exception(exception) if exception.is_a?(::Exception)
|
|
98
|
+
super
|
|
99
|
+
end
|
|
100
|
+
end)
|
|
101
|
+
end
|
|
102
|
+
rescue Exception # rubocop:disable Lint/RescueException
|
|
103
|
+
nil
|
|
91
104
|
end
|
|
92
105
|
|
|
93
106
|
def do_attach_otel_logger!
|
|
94
107
|
return unless ::Rails.respond_to?(:logger) && ::Rails.logger
|
|
95
108
|
|
|
96
109
|
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
110
|
return
|
|
99
111
|
end
|
|
100
112
|
|
|
@@ -105,8 +117,8 @@ module Foam
|
|
|
105
117
|
elsif defined?(::ActiveSupport::Logger) && ::ActiveSupport::Logger.respond_to?(:broadcast)
|
|
106
118
|
::Rails.logger.extend(::ActiveSupport::Logger.broadcast(otel_logger))
|
|
107
119
|
end
|
|
108
|
-
rescue
|
|
109
|
-
|
|
120
|
+
rescue Exception # rubocop:disable Lint/RescueException
|
|
121
|
+
nil
|
|
110
122
|
end
|
|
111
123
|
end
|
|
112
124
|
end
|