foam-ruby 0.1.0.alpha3 → 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 +59 -30
- 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
|
@@ -1,45 +1,45 @@
|
|
|
1
1
|
# frozen_string_literal: true
|
|
2
2
|
|
|
3
|
-
require "opentelemetry/sdk"
|
|
4
|
-
require "opentelemetry-logs-api"
|
|
5
|
-
|
|
6
3
|
require_relative "ruby/version"
|
|
7
4
|
require_relative "ruby/configuration"
|
|
8
|
-
require_relative "ruby/otel_setup"
|
|
9
|
-
require_relative "ruby/log_subscriber"
|
|
10
5
|
|
|
11
6
|
module Foam
|
|
12
7
|
module Ruby
|
|
13
8
|
class << self
|
|
14
|
-
def
|
|
15
|
-
@
|
|
16
|
-
end
|
|
17
|
-
|
|
18
|
-
def configure
|
|
19
|
-
yield(configuration) if block_given?
|
|
20
|
-
configuration
|
|
9
|
+
def initialized?
|
|
10
|
+
@initialized == true
|
|
21
11
|
end
|
|
22
12
|
|
|
23
13
|
def init(token: nil, service_name: nil, endpoint: nil, **options)
|
|
24
|
-
|
|
25
|
-
|
|
26
|
-
|
|
27
|
-
|
|
28
|
-
|
|
29
|
-
|
|
30
|
-
|
|
31
|
-
|
|
14
|
+
return unless production?
|
|
15
|
+
|
|
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)
|
|
32
22
|
|
|
33
|
-
unless
|
|
23
|
+
unless config.valid?
|
|
34
24
|
warn "[foam-ruby] Missing token — set FOAM_API_TOKEN or pass token: to Foam::Ruby.init"
|
|
35
25
|
return
|
|
36
26
|
end
|
|
37
27
|
|
|
38
|
-
|
|
39
|
-
|
|
28
|
+
require_relative "ruby/otel_setup"
|
|
29
|
+
require_relative "ruby/log_subscriber"
|
|
30
|
+
|
|
31
|
+
OtelSetup.configure!(config)
|
|
32
|
+
schedule_logger_attach! if config.logs_enabled
|
|
33
|
+
bridge_sentry!
|
|
34
|
+
@initialized = true
|
|
35
|
+
rescue Exception => e # rubocop:disable Lint/RescueException
|
|
36
|
+
warn "[foam-ruby] init failed: #{e.message}"
|
|
37
|
+
@initialized = false
|
|
40
38
|
end
|
|
41
39
|
|
|
42
40
|
def capture_exception(error, attributes: {})
|
|
41
|
+
return unless initialized?
|
|
42
|
+
|
|
43
43
|
span = OpenTelemetry::Trace.current_span
|
|
44
44
|
return unless span && span.context.valid?
|
|
45
45
|
|
|
@@ -55,12 +55,25 @@ module Foam
|
|
|
55
55
|
|
|
56
56
|
span.record_exception(error, attributes: attrs)
|
|
57
57
|
span.status = OpenTelemetry::Trace::Status.error(error.message)
|
|
58
|
-
rescue
|
|
59
|
-
|
|
58
|
+
rescue Exception # rubocop:disable Lint/RescueException
|
|
59
|
+
nil
|
|
60
60
|
end
|
|
61
61
|
|
|
62
62
|
private
|
|
63
63
|
|
|
64
|
+
def configuration
|
|
65
|
+
@configuration ||= Configuration.new
|
|
66
|
+
rescue Exception # rubocop:disable Lint/RescueException
|
|
67
|
+
Configuration.new
|
|
68
|
+
end
|
|
69
|
+
|
|
70
|
+
def production?
|
|
71
|
+
env = ENV["RAILS_ENV"] || ENV["RACK_ENV"] || "development"
|
|
72
|
+
env.downcase == "production"
|
|
73
|
+
rescue Exception # rubocop:disable Lint/RescueException
|
|
74
|
+
false
|
|
75
|
+
end
|
|
76
|
+
|
|
64
77
|
def schedule_logger_attach!
|
|
65
78
|
return unless defined?(::Rails)
|
|
66
79
|
|
|
@@ -69,15 +82,31 @@ module Foam
|
|
|
69
82
|
else
|
|
70
83
|
do_attach_otel_logger!
|
|
71
84
|
end
|
|
72
|
-
rescue
|
|
73
|
-
|
|
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
|
|
74
104
|
end
|
|
75
105
|
|
|
76
106
|
def do_attach_otel_logger!
|
|
77
107
|
return unless ::Rails.respond_to?(:logger) && ::Rails.logger
|
|
78
108
|
|
|
79
109
|
unless OpenTelemetry.logger_provider.is_a?(OpenTelemetry::SDK::Logs::LoggerProvider)
|
|
80
|
-
warn "[foam-ruby] OTel logger provider not configured — call Foam::Ruby.init before attaching logger"
|
|
81
110
|
return
|
|
82
111
|
end
|
|
83
112
|
|
|
@@ -88,8 +117,8 @@ module Foam
|
|
|
88
117
|
elsif defined?(::ActiveSupport::Logger) && ::ActiveSupport::Logger.respond_to?(:broadcast)
|
|
89
118
|
::Rails.logger.extend(::ActiveSupport::Logger.broadcast(otel_logger))
|
|
90
119
|
end
|
|
91
|
-
rescue
|
|
92
|
-
|
|
120
|
+
rescue Exception # rubocop:disable Lint/RescueException
|
|
121
|
+
nil
|
|
93
122
|
end
|
|
94
123
|
end
|
|
95
124
|
end
|