lantern-rails 0.2.1 → 0.3.0
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 +8 -34
- data/lib/generators/lantern/install_generator.rb +23 -0
- data/lib/generators/lantern/templates/lantern.rb.tt +11 -0
- data/lib/lantern/rails/railtie.rb +26 -5
- data/lib/lantern/rails/request_tracker.rb +11 -0
- data/lib/lantern/rails/version.rb +1 -1
- metadata +3 -1
checksums.yaml
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
---
|
|
2
2
|
SHA256:
|
|
3
|
-
metadata.gz:
|
|
4
|
-
data.tar.gz:
|
|
3
|
+
metadata.gz: 9e80b02c09f20e01a8a0b0f4f502708feba44f3d8bffaa9cf0bbded0ee2bf079
|
|
4
|
+
data.tar.gz: 4dba6effb791874dbd11fe35d125b6637668b75792f3fd3c0efe9bf1069e9fcc
|
|
5
5
|
SHA512:
|
|
6
|
-
metadata.gz:
|
|
7
|
-
data.tar.gz:
|
|
6
|
+
metadata.gz: 0feab9b70da80d79b7455d28703ce83cc252520ca75988976751efea292d4bd201b8ecd25e133f4050f9a7be32f96a1b54b2fade5539eed629b16299fbe15f2d
|
|
7
|
+
data.tar.gz: 20c7cc314a052d6bc9d12de1b4175bc5b83b8f0670cb06ba4c20505f577bb6837d3c61c43c86f14ef10f7e4e68cf4b3acd4eda3548ec5e41b692780beb125f0c
|
data/README.md
CHANGED
|
@@ -16,50 +16,24 @@ Then run:
|
|
|
16
16
|
bundle install
|
|
17
17
|
```
|
|
18
18
|
|
|
19
|
-
##
|
|
19
|
+
## Quick start
|
|
20
20
|
|
|
21
|
-
1.
|
|
22
|
-
2.
|
|
23
|
-
3. Create an initializer
|
|
24
|
-
|
|
25
|
-
### Store your API key
|
|
26
|
-
|
|
27
|
-
**Option A: Environment variable**
|
|
21
|
+
1. Sign up for a free API key at [uselantern.dev](https://uselantern.dev)
|
|
22
|
+
2. Run the installer:
|
|
28
23
|
|
|
29
24
|
```
|
|
30
|
-
|
|
25
|
+
rails generate lantern:install
|
|
31
26
|
```
|
|
32
27
|
|
|
33
|
-
|
|
28
|
+
3. Add your API key to the generated initializer (`config/initializers/lantern.rb`) via environment variable or Rails credentials:
|
|
34
29
|
|
|
35
30
|
```
|
|
36
|
-
|
|
37
|
-
```
|
|
38
|
-
|
|
39
|
-
Flat:
|
|
40
|
-
```yaml
|
|
41
|
-
lantern_api_key: lnt_your_key_here
|
|
42
|
-
```
|
|
43
|
-
|
|
44
|
-
Or nested:
|
|
45
|
-
```yaml
|
|
46
|
-
lantern:
|
|
47
|
-
api_key: lnt_your_key_here
|
|
31
|
+
LANTERN_API_KEY=lnt_your_key_here
|
|
48
32
|
```
|
|
49
33
|
|
|
50
|
-
|
|
51
|
-
|
|
52
|
-
```ruby
|
|
53
|
-
# config/initializers/lantern.rb
|
|
54
|
-
Lantern::Rails.configure do |config|
|
|
55
|
-
# Match how you stored the key above:
|
|
56
|
-
config.api_key = ENV["LANTERN_API_KEY"]
|
|
57
|
-
# Or: config.api_key = Rails.application.credentials.lantern_api_key
|
|
58
|
-
# Or: config.api_key = Rails.application.credentials.dig(:lantern, :api_key)
|
|
59
|
-
end
|
|
60
|
-
```
|
|
34
|
+
4. Deploy — Lantern starts collecting automatically.
|
|
61
35
|
|
|
62
|
-
That's it.
|
|
36
|
+
That's it. Open [uselantern.dev](https://uselantern.dev) to see your dashboard.
|
|
63
37
|
|
|
64
38
|
## Configuration
|
|
65
39
|
|
|
@@ -0,0 +1,23 @@
|
|
|
1
|
+
module Lantern
|
|
2
|
+
class InstallGenerator < ::Rails::Generators::Base
|
|
3
|
+
source_root File.expand_path("templates", __dir__)
|
|
4
|
+
|
|
5
|
+
desc "Creates a Lantern initializer with your API key."
|
|
6
|
+
|
|
7
|
+
def copy_initializer
|
|
8
|
+
template "lantern.rb.tt", "config/initializers/lantern.rb"
|
|
9
|
+
end
|
|
10
|
+
|
|
11
|
+
def print_next_steps
|
|
12
|
+
say ""
|
|
13
|
+
say "Lantern installed!", :green
|
|
14
|
+
say ""
|
|
15
|
+
say "Next steps:"
|
|
16
|
+
say " 1. Add your API key to config/initializers/lantern.rb"
|
|
17
|
+
say " Get your free key at: https://uselantern.dev"
|
|
18
|
+
say " 2. Deploy your app — Lantern starts collecting automatically"
|
|
19
|
+
say " 3. Open https://uselantern.dev to see your dashboard"
|
|
20
|
+
say ""
|
|
21
|
+
end
|
|
22
|
+
end
|
|
23
|
+
end
|
|
@@ -0,0 +1,11 @@
|
|
|
1
|
+
Lantern::Rails.configure do |config|
|
|
2
|
+
# Your API key from https://uselantern.dev
|
|
3
|
+
# Sign up for free, add a database, and copy the key here.
|
|
4
|
+
config.api_key = Rails.application.credentials.dig(:lantern, :api_key) || ENV["LANTERN_API_KEY"]
|
|
5
|
+
|
|
6
|
+
# Collection interval in seconds (default: 300 = 5 minutes)
|
|
7
|
+
# config.interval = 300
|
|
8
|
+
|
|
9
|
+
# Environments to collect in (default: production and staging)
|
|
10
|
+
# config.collect_in_environments = %w[production staging]
|
|
11
|
+
end
|
|
@@ -1,13 +1,34 @@
|
|
|
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
|
-
next unless config.valid?
|
|
7
|
-
next unless config.enabled
|
|
8
|
-
next unless config.collect_in_environments.include?(::Rails.env.to_s)
|
|
9
14
|
|
|
10
|
-
|
|
15
|
+
unless config.valid?
|
|
16
|
+
::Rails.logger.info(
|
|
17
|
+
"[Lantern] No API key configured. Get your free key at https://uselantern.dev " \
|
|
18
|
+
"then run: rails generate lantern:install"
|
|
19
|
+
)
|
|
20
|
+
next
|
|
21
|
+
end
|
|
22
|
+
|
|
23
|
+
unless config.enabled
|
|
24
|
+
::Rails.logger.info("[Lantern] Disabled via configuration.")
|
|
25
|
+
next
|
|
26
|
+
end
|
|
27
|
+
|
|
28
|
+
unless config.collect_in_environments.include?(::Rails.env.to_s)
|
|
29
|
+
::Rails.logger.info("[Lantern] Skipping collection in #{::Rails.env} environment.")
|
|
30
|
+
next
|
|
31
|
+
end
|
|
11
32
|
|
|
12
33
|
runner = Lantern::Rails::Runner.new(config)
|
|
13
34
|
|
|
@@ -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
|
metadata
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
|
2
2
|
name: lantern-rails
|
|
3
3
|
version: !ruby/object:Gem::Version
|
|
4
|
-
version: 0.
|
|
4
|
+
version: 0.3.0
|
|
5
5
|
platform: ruby
|
|
6
6
|
authors:
|
|
7
7
|
- Eric Mumbower
|
|
@@ -29,6 +29,8 @@ extra_rdoc_files: []
|
|
|
29
29
|
files:
|
|
30
30
|
- LICENSE
|
|
31
31
|
- README.md
|
|
32
|
+
- lib/generators/lantern/install_generator.rb
|
|
33
|
+
- lib/generators/lantern/templates/lantern.rb.tt
|
|
32
34
|
- lib/lantern-rails.rb
|
|
33
35
|
- lib/lantern/rails/collector.rb
|
|
34
36
|
- lib/lantern/rails/configuration.rb
|