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 +4 -4
- data/README.md +5 -34
- data/lib/foam/ruby/configuration.rb +1 -6
- data/lib/foam/ruby/otel_setup.rb +2 -2
- data/lib/foam/ruby/version.rb +1 -1
- data/lib/foam/ruby.rb +41 -32
- 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: '039cdc9710beb8c5ebc5caf48a4d26ebc906af5843a2effcaa6e23516de0a5e0'
|
|
4
|
+
data.tar.gz: 239ff4c8bfcaf6d56659bdb306cdabf93452c8db7713772bdfe4ef37080b326d
|
|
5
5
|
SHA512:
|
|
6
|
-
metadata.gz:
|
|
7
|
-
data.tar.gz:
|
|
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
|
-
###
|
|
76
|
+
### Sentry Integration
|
|
99
77
|
|
|
100
|
-
|
|
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
|
-
|
|
103
|
-
|
|
104
|
-
|
|
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
|
data/lib/foam/ruby/otel_setup.rb
CHANGED
|
@@ -12,8 +12,8 @@ module Foam
|
|
|
12
12
|
module_function
|
|
13
13
|
|
|
14
14
|
def configure!(config)
|
|
15
|
-
configure_traces(config)
|
|
16
|
-
configure_logs(config)
|
|
15
|
+
configure_traces(config)
|
|
16
|
+
configure_logs(config)
|
|
17
17
|
end
|
|
18
18
|
|
|
19
19
|
def configure_traces(config)
|
data/lib/foam/ruby/version.rb
CHANGED
data/lib/foam/ruby.rb
CHANGED
|
@@ -10,30 +10,14 @@ module Foam
|
|
|
10
10
|
@initialized == true
|
|
11
11
|
end
|
|
12
12
|
|
|
13
|
-
def
|
|
14
|
-
|
|
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
|
-
|
|
23
|
-
|
|
24
|
-
|
|
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
|
|
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!(
|
|
45
|
-
schedule_logger_attach!
|
|
28
|
+
OtelSetup.configure!(config)
|
|
29
|
+
schedule_logger_attach!
|
|
30
|
+
bridge_sentry!
|
|
46
31
|
@initialized = true
|
|
47
|
-
rescue
|
|
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
|
|
71
|
-
|
|
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
|
|
90
|
-
|
|
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
|
|
109
|
-
|
|
117
|
+
rescue Exception # rubocop:disable Lint/RescueException
|
|
118
|
+
nil
|
|
110
119
|
end
|
|
111
120
|
end
|
|
112
121
|
end
|