lantern-rails 0.2.1 → 0.2.2
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/lib/lantern/rails/railtie.rb +9 -3
- data/lib/lantern/rails/request_tracker.rb +11 -0
- data/lib/lantern/rails/version.rb +1 -1
- 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: a10d9bbf6c76960298040e88390464ba2d451640e1abfb62bd5e7f8b46dc3aa9
|
|
4
|
+
data.tar.gz: 8e86338e7c02d61ef522140726562c5941ab725daf823360d748ab9402da7b8c
|
|
5
5
|
SHA512:
|
|
6
|
-
metadata.gz:
|
|
7
|
-
data.tar.gz:
|
|
6
|
+
metadata.gz: 57cfc0136452511b7a42e5799489a09450e39f22828505506f7c1c6150101a901779c01e4adae57c4add0b47e4da22b6deb7bfd88004470358c5da7de93e10c0
|
|
7
|
+
data.tar.gz: 55de2b34703ca25621026c177c35a701b0bacb323bb0a5c96f0ba2b74ae64574141c496ff621104d14de382900649b25bfb79e453f4a98b1da9955f276033909
|
|
@@ -1,14 +1,20 @@
|
|
|
1
1
|
module Lantern
|
|
2
2
|
module Rails
|
|
3
3
|
class Railtie < ::Rails::Railtie
|
|
4
|
-
|
|
4
|
+
initializer "lantern.request_tracker" do |app|
|
|
5
|
+
# Insert middleware unconditionally — it checks config at runtime
|
|
6
|
+
# and no-ops if Lantern isn't configured. This avoids the frozen
|
|
7
|
+
# middleware stack issue in Rails 8.1 while ensuring the API key
|
|
8
|
+
# (set in app initializers) is available when requests arrive.
|
|
9
|
+
app.middleware.use Lantern::Rails::RequestTracker, Lantern::Rails.query_aggregator
|
|
10
|
+
end
|
|
11
|
+
|
|
12
|
+
config.after_initialize do
|
|
5
13
|
config = Lantern::Rails.configuration
|
|
6
14
|
next unless config.valid?
|
|
7
15
|
next unless config.enabled
|
|
8
16
|
next unless config.collect_in_environments.include?(::Rails.env.to_s)
|
|
9
17
|
|
|
10
|
-
app.middleware.use Lantern::Rails::RequestTracker, Lantern::Rails.query_aggregator
|
|
11
|
-
|
|
12
18
|
runner = Lantern::Rails::Runner.new(config)
|
|
13
19
|
|
|
14
20
|
at_exit { runner.stop }
|
|
@@ -10,6 +10,9 @@ module Lantern
|
|
|
10
10
|
end
|
|
11
11
|
|
|
12
12
|
def call(env)
|
|
13
|
+
# No-op if Lantern isn't configured or not enabled for this environment
|
|
14
|
+
return @app.call(env) unless enabled?
|
|
15
|
+
|
|
13
16
|
# Only track actual controller requests, skip assets/healthchecks
|
|
14
17
|
return @app.call(env) unless trackable_request?(env)
|
|
15
18
|
|
|
@@ -49,6 +52,14 @@ module Lantern
|
|
|
49
52
|
|
|
50
53
|
private
|
|
51
54
|
|
|
55
|
+
def enabled?
|
|
56
|
+
return @enabled if defined?(@enabled)
|
|
57
|
+
|
|
58
|
+
config = Lantern::Rails.configuration
|
|
59
|
+
@enabled = config.valid? && config.enabled &&
|
|
60
|
+
config.collect_in_environments.include?(::Rails.env.to_s)
|
|
61
|
+
end
|
|
62
|
+
|
|
52
63
|
def trackable_request?(env)
|
|
53
64
|
# Skip asset pipeline, action cable, health checks
|
|
54
65
|
path = env["PATH_INFO"].to_s
|