ez_logs_agent 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/CHANGELOG.md +12 -0
- data/README.md +72 -59
- data/lib/ez_logs_agent/configuration_validator.rb +2 -2
- data/lib/ez_logs_agent/flush_scheduler.rb +21 -3
- data/lib/ez_logs_agent/logger.rb +8 -2
- data/lib/ez_logs_agent/railtie.rb +39 -0
- data/lib/ez_logs_agent/transport.rb +9 -7
- data/lib/ez_logs_agent/version.rb +1 -1
- data/lib/generators/ez_logs_agent/install/templates/ez_logs_agent.rb.tt +2 -0
- metadata +4 -4
checksums.yaml
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
---
|
|
2
2
|
SHA256:
|
|
3
|
-
metadata.gz:
|
|
4
|
-
data.tar.gz:
|
|
3
|
+
metadata.gz: 60873dfcf28408365019a70880b7a28aa868142df967df60c5b4c2c32c3f2608
|
|
4
|
+
data.tar.gz: 36daaebd2e181f7ca987b630a3c64102212ef3466598c1b41dae84abe183d89c
|
|
5
5
|
SHA512:
|
|
6
|
-
metadata.gz:
|
|
7
|
-
data.tar.gz:
|
|
6
|
+
metadata.gz: 2ae1777f5b2bdab3eaa688d6a543a5c796d32582f4fc269074eee4914403d06c36598497126707e64ba018340ca6f56d798310a358c187121b65414ccdb9a974
|
|
7
|
+
data.tar.gz: b39b3add6cb40cd7f061892302fe379879c25d3bc2d561c2a453ef59ebf96ab7e70e86e08a5ce25534ef3615c8c24b7119d0e8aa1068b8d4860cb2d4730592e7
|
data/CHANGELOG.md
CHANGED
|
@@ -2,6 +2,18 @@
|
|
|
2
2
|
|
|
3
3
|
All notable changes to this project will be documented in this file.
|
|
4
4
|
|
|
5
|
+
## [0.2.2] — 2026-11-17
|
|
6
|
+
|
|
7
|
+
### Added
|
|
8
|
+
- **Startup line.** Each process logs one line, whatever the agent's `log_level` (visible unless Rails' own log level is above `info`), so you can check the install: `[EzLogsAgent] capturing → app.ezlogs.io (key ezl_a1b2c3d4…)`. The key is shown as Settings → API Keys shows it (`ezl_` + first 8 characters); other token shapes get no hint. With config missing it logs `[EzLogsAgent] not capturing: project_token missing`. Silent in the test env. In development it is in `log/development.log`.
|
|
9
|
+
|
|
10
|
+
### Fixed
|
|
11
|
+
- **Events lost at process exit.** `FlushScheduler.stop` (run from `at_exit`) now sends what is still buffered: one attempt, no retries, 1 s HTTP timeouts and a 3 s hard cap. Before, the last up-to-3 s of events (the `send_interval` default) were dropped whenever a process exited: always for `rails runner` / rake tasks, and on every Puma/Sidekiq restart. It also runs when the flush thread had crashed. Shutdown may take up to ~3–5 s longer when events are pending and the server is slow or unreachable.
|
|
12
|
+
- **Forked children no longer resend the parent's events.** The buffer inherited across `fork` (Puma cluster workers, etc.) is cleared in the child; the parent still sends it.
|
|
13
|
+
|
|
14
|
+
### Changed
|
|
15
|
+
- **`project_token` is required.** A missing token is now a configuration error and the agent stays off. Before, it was a warning: the agent ran and every batch was rejected with 401. Set the token in `config/initializers/ez_logs_agent.rb`: it is checked once at boot, so a token set later in `after_initialize` or `to_prepare` is not seen.
|
|
16
|
+
|
|
5
17
|
## [0.2.1] — 2026-06-05
|
|
6
18
|
|
|
7
19
|
### Fixed
|
data/README.md
CHANGED
|
@@ -134,12 +134,13 @@ Test your configuration:
|
|
|
134
134
|
rails ez_logs_agent:test_connection
|
|
135
135
|
```
|
|
136
136
|
|
|
137
|
-
**Successful output
|
|
137
|
+
**Successful output** (excerpt):
|
|
138
138
|
```
|
|
139
139
|
✅ Configuration is valid
|
|
140
140
|
✅ Connection successful (HTTP 200)
|
|
141
|
-
|
|
142
|
-
|
|
141
|
+
Test event accepted by server
|
|
142
|
+
|
|
143
|
+
✅ All checks passed! EzLogs Agent is configured correctly.
|
|
143
144
|
```
|
|
144
145
|
|
|
145
146
|
If the test fails, you'll see exactly what's wrong and how to fix it.
|
|
@@ -154,15 +155,20 @@ rails server
|
|
|
154
155
|
# Restart your application using your deployment process
|
|
155
156
|
```
|
|
156
157
|
|
|
157
|
-
Check your Rails logs for the startup
|
|
158
|
+
Check your Rails logs for the startup line. It is printed once per process (web, Sidekiq, rake), whatever the agent's `log_level`, and is visible unless Rails' own log level is above `info`. In development it lands in `log/development.log` (`rails s` copies the log to the terminal only after boot). Silent in the test env.
|
|
159
|
+
|
|
160
|
+
```
|
|
161
|
+
[EzLogsAgent] capturing → app.ezlogs.io (key ezl_a1b2c3d4…)
|
|
162
|
+
```
|
|
163
|
+
|
|
164
|
+
The key is shown the way Settings → API Keys shows it (`ezl_` + first 8 characters), so you can tell which key the app uses. If something is missing, the line says what:
|
|
158
165
|
|
|
159
166
|
```
|
|
160
|
-
[EzLogsAgent]
|
|
161
|
-
[EzLogsAgent] ✓ HTTP capture enabled
|
|
162
|
-
[EzLogsAgent] ✓ Sidekiq capture enabled
|
|
163
|
-
[EzLogsAgent] ✓ Database capture enabled
|
|
167
|
+
[EzLogsAgent] not capturing: project_token missing
|
|
164
168
|
```
|
|
165
169
|
|
|
170
|
+
Set `project_token` in `config/initializers/ez_logs_agent.rb`. The agent checks it once at boot, so a token set later (in `after_initialize` or `to_prepare`) is not seen.
|
|
171
|
+
|
|
166
172
|
### 5. See Your Activity
|
|
167
173
|
|
|
168
174
|
Visit your EZLogs dashboard and interact with your application. Within seconds, you'll see activity appearing in real-time.
|
|
@@ -604,34 +610,37 @@ rails ez_logs_agent:test_connection
|
|
|
604
610
|
### Successful Output
|
|
605
611
|
|
|
606
612
|
```
|
|
607
|
-
|
|
613
|
+
🔍 EzLogs Agent Connection Test
|
|
614
|
+
|
|
615
|
+
Step 1: Validating configuration...
|
|
608
616
|
✅ Configuration is valid
|
|
617
|
+
|
|
618
|
+
Configuration Summary:
|
|
619
|
+
Server URL: https://app.ezlogs.io
|
|
620
|
+
Project Token: ***1a2b
|
|
621
|
+
Capture HTTP: true
|
|
622
|
+
Capture Jobs: true
|
|
623
|
+
Capture Database: true
|
|
624
|
+
|
|
625
|
+
Step 2: Testing connection to server...
|
|
609
626
|
✅ Connection successful (HTTP 200)
|
|
610
|
-
|
|
611
|
-
✅ All checks passed! EZLogs Agent is configured correctly.
|
|
627
|
+
Test event accepted by server
|
|
612
628
|
|
|
613
|
-
|
|
614
|
-
1. Restart your Rails application
|
|
615
|
-
2. Visit your EZLogs dashboard
|
|
616
|
-
3. Interact with your application to generate events
|
|
629
|
+
✅ All checks passed! EzLogs Agent is configured correctly.
|
|
617
630
|
```
|
|
618
631
|
|
|
619
632
|
### Failed Output
|
|
620
633
|
|
|
621
|
-
If the test fails, you'll see exactly what's wrong:
|
|
634
|
+
If the test fails, you'll see exactly what's wrong (excerpt, after the same Step 1 and summary):
|
|
622
635
|
|
|
623
636
|
```
|
|
624
|
-
|
|
625
|
-
❌
|
|
626
|
-
|
|
627
|
-
Possible causes:
|
|
628
|
-
- Invalid API key (project_token)
|
|
629
|
-
- API key has been revoked
|
|
630
|
-
- Check your project_token in config/initializers/ez_logs_agent.rb
|
|
631
|
-
|
|
632
|
-
Please fix the error and run this command again.
|
|
637
|
+
Step 2: Testing connection to server...
|
|
638
|
+
❌ Authentication failed (HTTP 401)
|
|
639
|
+
Check your project_token in config/initializers/ez_logs_agent.rb
|
|
633
640
|
```
|
|
634
641
|
|
|
642
|
+
Other failures print one of: `❌ Server endpoint not found (HTTP 404)`, `❌ Could not resolve host: …`, `❌ Connection refused: …`, `❌ Connection timeout: …`, or `❌ Configuration validation failed:` followed by the errors.
|
|
643
|
+
|
|
635
644
|
---
|
|
636
645
|
|
|
637
646
|
## Troubleshooting
|
|
@@ -657,19 +666,22 @@ rails ez_logs_agent:test_connection
|
|
|
657
666
|
rails ez_logs_agent:test_connection
|
|
658
667
|
```
|
|
659
668
|
|
|
660
|
-
2. **Check Rails logs** for agent
|
|
669
|
+
2. **Check Rails logs** for the startup line and for agent errors, e.g. a rejected key:
|
|
661
670
|
```
|
|
662
|
-
[EzLogsAgent]
|
|
663
|
-
[EzLogsAgent]
|
|
664
|
-
[EzLogsAgent] Sending batch of 3 events...
|
|
665
|
-
[EzLogsAgent] Batch sent successfully (HTTP 200)
|
|
671
|
+
[EzLogsAgent] capturing → app.ezlogs.io (key ezl_a1b2c3d4…)
|
|
672
|
+
[EzLogsAgent] [Transport] send failed (401)
|
|
666
673
|
```
|
|
667
674
|
|
|
668
675
|
3. **Enable debug logging** in `config/initializers/ez_logs_agent.rb`:
|
|
669
676
|
```ruby
|
|
670
677
|
config.log_level = :debug
|
|
671
678
|
```
|
|
672
|
-
Then restart Rails
|
|
679
|
+
Then restart Rails. A working agent logs, among others:
|
|
680
|
+
```
|
|
681
|
+
[EzLogsAgent] [Railtie] HTTP capture enabled
|
|
682
|
+
[EzLogsAgent] [Railtie] Agent initialized successfully
|
|
683
|
+
[EzLogsAgent] [Transport] send succeeded (200)
|
|
684
|
+
```
|
|
673
685
|
|
|
674
686
|
4. **Verify network connectivity:**
|
|
675
687
|
```bash
|
|
@@ -686,23 +698,23 @@ rails ez_logs_agent:test_connection
|
|
|
686
698
|
|
|
687
699
|
**Example output:**
|
|
688
700
|
```
|
|
689
|
-
[Railtie] Configuration validation failed:
|
|
690
|
-
|
|
691
|
-
[Railtie] Agent initialization skipped. Please fix configuration errors.
|
|
701
|
+
[EzLogsAgent] [Railtie] Configuration validation failed:
|
|
702
|
+
[EzLogsAgent] [Railtie] - server_url is required. Set it in config/initializers/ez_logs_agent.rb
|
|
703
|
+
[EzLogsAgent] [Railtie] Agent initialization skipped. Please fix configuration errors.
|
|
692
704
|
```
|
|
693
705
|
|
|
694
706
|
**Solution:** Fix the errors listed in the warning message and restart Rails.
|
|
695
707
|
|
|
696
708
|
Common validation errors:
|
|
697
|
-
- `server_url is required` → Set `config.server_url`
|
|
698
|
-
- `
|
|
699
|
-
- `
|
|
709
|
+
- `server_url is required. Set it in config/initializers/ez_logs_agent.rb` → Set `config.server_url`
|
|
710
|
+
- `server_url must be a valid URL (got: …)` → Fix the URL format
|
|
711
|
+
- `project_token is required. Set it in config/initializers/ez_logs_agent.rb` → Set `config.project_token`
|
|
700
712
|
|
|
701
713
|
---
|
|
702
714
|
|
|
703
715
|
### Authentication Errors (HTTP 401)
|
|
704
716
|
|
|
705
|
-
**Symptoms:** Connection test or agent logs show `HTTP 401
|
|
717
|
+
**Symptoms:** Connection test or agent logs show `HTTP 401`.
|
|
706
718
|
|
|
707
719
|
**Debug steps:**
|
|
708
720
|
|
|
@@ -747,7 +759,7 @@ Common validation errors:
|
|
|
747
759
|
|
|
748
760
|
3. **Look for Sidekiq registration in logs:**
|
|
749
761
|
```
|
|
750
|
-
[Railtie] Sidekiq server middleware registered
|
|
762
|
+
[EzLogsAgent] [Railtie] Sidekiq server middleware registered
|
|
751
763
|
```
|
|
752
764
|
**Note:** This message only appears in Sidekiq worker processes, not web processes.
|
|
753
765
|
|
|
@@ -789,7 +801,7 @@ Common validation errors:
|
|
|
789
801
|
|
|
790
802
|
3. **Look for database capture registration in logs:**
|
|
791
803
|
```
|
|
792
|
-
[Railtie] Database capture installed (per-row + bulk)
|
|
804
|
+
[EzLogsAgent] [Railtie] Database capture installed (per-row + bulk)
|
|
793
805
|
```
|
|
794
806
|
|
|
795
807
|
4. **Verify models aren't excluded:**
|
|
@@ -839,8 +851,7 @@ config.send_interval = 1
|
|
|
839
851
|
|
|
840
852
|
**If correlation is missing when it should be present:**
|
|
841
853
|
1. Enable debug logging: `config.log_level = :debug`
|
|
842
|
-
2.
|
|
843
|
-
3. Check that jobs are enqueued within the same request context
|
|
854
|
+
2. Check that jobs are enqueued within the same request context
|
|
844
855
|
|
|
845
856
|
---
|
|
846
857
|
|
|
@@ -877,30 +888,32 @@ config.send_interval = 1
|
|
|
877
888
|
|
|
878
889
|
### Understanding Agent Log Messages
|
|
879
890
|
|
|
880
|
-
**Normal operation
|
|
891
|
+
**Normal operation** (the startup line always shows; the other two only at `config.log_level = :debug`):
|
|
881
892
|
```
|
|
882
|
-
[EzLogsAgent]
|
|
883
|
-
[EzLogsAgent]
|
|
884
|
-
[EzLogsAgent]
|
|
893
|
+
[EzLogsAgent] capturing → app.ezlogs.io (key ezl_a1b2c3d4…)
|
|
894
|
+
[EzLogsAgent] [Railtie] Agent initialized successfully
|
|
895
|
+
[EzLogsAgent] [Transport] send succeeded (200)
|
|
885
896
|
```
|
|
886
897
|
|
|
887
|
-
**Warnings
|
|
898
|
+
**Warnings:**
|
|
888
899
|
```
|
|
889
|
-
[EzLogsAgent] Buffer full,
|
|
890
|
-
→ Your app
|
|
891
|
-
→ Increase buffer_size or send_interval
|
|
900
|
+
[EzLogsAgent] [Buffer] Buffer full (10000), dropped oldest event
|
|
901
|
+
→ Your app produces events faster than they are sent
|
|
902
|
+
→ Increase buffer_size or lower send_interval
|
|
892
903
|
```
|
|
893
904
|
|
|
894
905
|
**Errors (need attention):**
|
|
895
906
|
```
|
|
896
|
-
[EzLogsAgent]
|
|
897
|
-
→ Invalid API key, check config.project_token
|
|
907
|
+
[EzLogsAgent] [Transport] send failed (401)
|
|
908
|
+
→ Invalid or revoked API key, check config.project_token
|
|
909
|
+
|
|
910
|
+
[EzLogsAgent] [Transport] send failed: Net::OpenTimeout - execution expired
|
|
911
|
+
→ Network issue or the server is down; the batch is retried (retry_attempts)
|
|
898
912
|
|
|
899
|
-
[EzLogsAgent] Failed
|
|
900
|
-
→
|
|
901
|
-
→ Events will be retried automatically
|
|
913
|
+
[EzLogsAgent] [RetrySender] Failed after 4 attempts, dropping 12 events
|
|
914
|
+
→ All retries failed; those events are lost
|
|
902
915
|
|
|
903
|
-
[EzLogsAgent] Configuration validation failed
|
|
916
|
+
[EzLogsAgent] [Railtie] Configuration validation failed:
|
|
904
917
|
→ Fix configuration errors and restart Rails
|
|
905
918
|
```
|
|
906
919
|
|
|
@@ -910,7 +923,7 @@ config.send_interval = 1
|
|
|
910
923
|
|
|
911
924
|
If you're still stuck after trying the above:
|
|
912
925
|
|
|
913
|
-
1. **Check GitHub Issues:** [github.com/dezsirazvan/
|
|
926
|
+
1. **Check GitHub Issues:** [github.com/dezsirazvan/ez_logs_agent/issues](https://github.com/dezsirazvan/ez_logs_agent/issues)
|
|
914
927
|
2. **Open a new issue** with:
|
|
915
928
|
- Rails version and Ruby version
|
|
916
929
|
- Relevant logs (set `config.log_level = :debug`)
|
|
@@ -1028,13 +1041,13 @@ We welcome bug reports and pull requests!
|
|
|
1028
1041
|
|
|
1029
1042
|
- **786 tests**, all green
|
|
1030
1043
|
- **Wire-format parity-tested** against the Next.js agent's fixtures (every event shape byte-for-byte identical)
|
|
1031
|
-
- **Production-shipping** in multiple Rails apps including
|
|
1044
|
+
- **Production-shipping** in multiple Rails apps including our Bookhouse demo app (Rails 8 + Sidekiq + Devise, exercises every capture path)
|
|
1032
1045
|
|
|
1033
1046
|
---
|
|
1034
1047
|
|
|
1035
1048
|
## Support
|
|
1036
1049
|
|
|
1037
|
-
- **GitHub Issues:** [Report a bug](https://github.com/dezsirazvan/
|
|
1050
|
+
- **GitHub Issues:** [Report a bug](https://github.com/dezsirazvan/ez_logs_agent/issues)
|
|
1038
1051
|
- **Email:** support@ezlogs.io
|
|
1039
1052
|
|
|
1040
1053
|
---
|
|
@@ -42,9 +42,9 @@ module EzLogsAgent
|
|
|
42
42
|
errors << "server_url must be a valid URL (got: #{config.server_url})"
|
|
43
43
|
end
|
|
44
44
|
|
|
45
|
-
#
|
|
45
|
+
# Required: the server rejects every event sent without a token
|
|
46
46
|
if config.project_token.nil? || config.project_token.to_s.strip.empty?
|
|
47
|
-
|
|
47
|
+
errors << "project_token is required. Set it in config/initializers/ez_logs_agent.rb"
|
|
48
48
|
end
|
|
49
49
|
|
|
50
50
|
# Validate numeric fields
|
|
@@ -1,5 +1,7 @@
|
|
|
1
1
|
# frozen_string_literal: true
|
|
2
2
|
|
|
3
|
+
require "timeout"
|
|
4
|
+
|
|
3
5
|
module EzLogsAgent
|
|
4
6
|
# FlushScheduler orchestrates periodic flushing of buffered events to the server.
|
|
5
7
|
#
|
|
@@ -14,6 +16,10 @@ module EzLogsAgent
|
|
|
14
16
|
# - Does NOT manage Rails lifecycle (Railtie handles that)
|
|
15
17
|
# - Does NOT mutate or inspect events
|
|
16
18
|
class FlushScheduler
|
|
19
|
+
# Exit budget: wait this long for the loop thread, then cap the final send
|
|
20
|
+
STOP_JOIN_SECONDS = 2
|
|
21
|
+
FINAL_FLUSH_SECONDS = 3
|
|
22
|
+
|
|
17
23
|
class << self
|
|
18
24
|
# Start the background flush thread
|
|
19
25
|
# Idempotent: safe to call multiple times
|
|
@@ -28,14 +34,26 @@ module EzLogsAgent
|
|
|
28
34
|
Logger.error("[FlushScheduler] Failed to start: #{error.class} - #{error.message}")
|
|
29
35
|
end
|
|
30
36
|
|
|
31
|
-
# Stop the background flush thread
|
|
37
|
+
# Stop the background flush thread, then send what is still buffered
|
|
32
38
|
# Blocks until thread exits
|
|
33
39
|
# Idempotent: safe to call multiple times
|
|
34
40
|
def stop
|
|
35
|
-
return unless
|
|
41
|
+
return unless @thread
|
|
36
42
|
|
|
37
43
|
@stop_requested = true
|
|
38
|
-
|
|
44
|
+
begin
|
|
45
|
+
@thread.wakeup # cut the interval sleep short so exit isn't delayed
|
|
46
|
+
rescue ThreadError
|
|
47
|
+
nil # thread already dead (e.g. the loop crashed): still drain below
|
|
48
|
+
end
|
|
49
|
+
@thread.join(STOP_JOIN_SECONDS)
|
|
50
|
+
@thread = nil
|
|
51
|
+
|
|
52
|
+
# Events buffered since the last tick would otherwise be lost at
|
|
53
|
+
# exit (rails runner, rake, deploy restarts). One attempt, short
|
|
54
|
+
# HTTP timeouts, and a hard cap (DNS isn't covered by
|
|
55
|
+
# open_timeout), so a down server can't stall shutdown.
|
|
56
|
+
Timeout.timeout(FINAL_FLUSH_SECONDS) { Transport.send(Buffer.flush, timeout: 1) }
|
|
39
57
|
|
|
40
58
|
Logger.debug("[FlushScheduler] Stopped")
|
|
41
59
|
rescue => error
|
data/lib/ez_logs_agent/logger.rb
CHANGED
|
@@ -29,11 +29,17 @@ module EzLogsAgent
|
|
|
29
29
|
log(:error, message)
|
|
30
30
|
end
|
|
31
31
|
|
|
32
|
+
# Logs at :info regardless of the configured log_level. Reserved for
|
|
33
|
+
# the one startup line that tells users whether capture is on.
|
|
34
|
+
def notice(message)
|
|
35
|
+
log(:info, message, force: true)
|
|
36
|
+
end
|
|
37
|
+
|
|
32
38
|
private
|
|
33
39
|
|
|
34
|
-
def log(level, message)
|
|
40
|
+
def log(level, message, force: false)
|
|
35
41
|
# Early return if this log level should not be logged
|
|
36
|
-
return unless should_log?(level)
|
|
42
|
+
return unless force || should_log?(level)
|
|
37
43
|
|
|
38
44
|
prefixed_message = "[EzLogsAgent] #{message}"
|
|
39
45
|
|
|
@@ -32,6 +32,7 @@ module EzLogsAgent
|
|
|
32
32
|
|
|
33
33
|
# Reset registration state (for testing)
|
|
34
34
|
def reset_registration_state!
|
|
35
|
+
@startup_announced = false
|
|
35
36
|
@sidekiq_client_registered = false
|
|
36
37
|
@sidekiq_server_registered = false
|
|
37
38
|
@activejob_installed = false
|
|
@@ -78,6 +79,7 @@ module EzLogsAgent
|
|
|
78
79
|
config.after_initialize do
|
|
79
80
|
# Validate configuration before doing anything
|
|
80
81
|
validation_result = validate_configuration
|
|
82
|
+
announce_startup(validation_result)
|
|
81
83
|
next unless validation_result
|
|
82
84
|
|
|
83
85
|
# Register Sidekiq middleware
|
|
@@ -267,6 +269,8 @@ module EzLogsAgent
|
|
|
267
269
|
# ActiveSupport::ForkTracker (Rails 6.1+) is the most reliable way
|
|
268
270
|
if defined?(ActiveSupport::ForkTracker)
|
|
269
271
|
ActiveSupport::ForkTracker.after_fork do
|
|
272
|
+
# The parent still owns (and sends) what it buffered before the fork
|
|
273
|
+
EzLogsAgent::Buffer.clear
|
|
270
274
|
start_flush_scheduler
|
|
271
275
|
end
|
|
272
276
|
EzLogsAgent::Logger.debug("[Railtie] Registered ActiveSupport::ForkTracker hook for FlushScheduler")
|
|
@@ -349,6 +353,41 @@ module EzLogsAgent
|
|
|
349
353
|
EzLogsAgent::Logger.error("[Railtie] Failed to log configuration summary: #{e.class} - #{e.message}")
|
|
350
354
|
end
|
|
351
355
|
|
|
356
|
+
# One line per process at the default log level, so "is it on?" is
|
|
357
|
+
# answerable from the logs: where events go and which key, shown the
|
|
358
|
+
# way the dashboard's Settings → API Keys shows it (`ezl_` + first 8
|
|
359
|
+
# characters). Other token shapes get no hint. Silent in the test env.
|
|
360
|
+
#
|
|
361
|
+
# @param capturing [Boolean] result of validate_configuration
|
|
362
|
+
# @return [void]
|
|
363
|
+
def self.announce_startup(capturing)
|
|
364
|
+
return if @startup_announced
|
|
365
|
+
@startup_announced = true
|
|
366
|
+
return if Rails.env.test?
|
|
367
|
+
|
|
368
|
+
config = EzLogsAgent.configuration
|
|
369
|
+
if capturing
|
|
370
|
+
uri = URI.parse(config.server_url.to_s)
|
|
371
|
+
host = uri.port == uri.default_port ? uri.host : "#{uri.host}:#{uri.port}"
|
|
372
|
+
token = config.project_token.to_s
|
|
373
|
+
project = token.start_with?("ezl_") && token.length >= 24 ? " (key #{token[0, 12]}…)" : ""
|
|
374
|
+
EzLogsAgent::Logger.notice("capturing → #{host}#{project}")
|
|
375
|
+
else
|
|
376
|
+
missing = [
|
|
377
|
+
blank?(config.server_url) && "server_url",
|
|
378
|
+
blank?(config.project_token) && "project_token"
|
|
379
|
+
].select { |m| m }
|
|
380
|
+
reason = missing.any? ? "#{missing.join(' and ')} missing" : "invalid configuration (see errors above)"
|
|
381
|
+
EzLogsAgent::Logger.warn("not capturing: #{reason}")
|
|
382
|
+
end
|
|
383
|
+
rescue StandardError => e
|
|
384
|
+
EzLogsAgent::Logger.error("[Railtie] Failed to log startup line: #{e.class} - #{e.message}")
|
|
385
|
+
end
|
|
386
|
+
|
|
387
|
+
def self.blank?(value)
|
|
388
|
+
value.nil? || value.to_s.strip.empty?
|
|
389
|
+
end
|
|
390
|
+
|
|
352
391
|
# Load rake tasks
|
|
353
392
|
rake_tasks do
|
|
354
393
|
load "tasks/ez_logs_agent.rake"
|
|
@@ -26,11 +26,12 @@ module EzLogsAgent
|
|
|
26
26
|
# Send events to the server
|
|
27
27
|
#
|
|
28
28
|
# @param events [Array<Hash>] Array of event hashes
|
|
29
|
+
# @param timeout [Numeric, nil] open/read/write timeout override (seconds)
|
|
29
30
|
# @return [Symbol] :success if 2xx response, :failure otherwise
|
|
30
|
-
def send(events)
|
|
31
|
+
def send(events, timeout: nil)
|
|
31
32
|
return :success if events.nil? || events.empty?
|
|
32
33
|
|
|
33
|
-
response = post_events(events)
|
|
34
|
+
response = post_events(events, timeout)
|
|
34
35
|
classify_response(response)
|
|
35
36
|
rescue => error
|
|
36
37
|
Logger.error("[Transport] send failed: #{error.class} - #{error.message}")
|
|
@@ -39,9 +40,9 @@ module EzLogsAgent
|
|
|
39
40
|
|
|
40
41
|
private
|
|
41
42
|
|
|
42
|
-
def post_events(events)
|
|
43
|
+
def post_events(events, timeout)
|
|
43
44
|
uri = build_uri
|
|
44
|
-
http = build_http_client(uri)
|
|
45
|
+
http = build_http_client(uri, timeout)
|
|
45
46
|
request = build_request(uri, events)
|
|
46
47
|
|
|
47
48
|
http.request(request)
|
|
@@ -56,11 +57,12 @@ module EzLogsAgent
|
|
|
56
57
|
raise "Invalid server_url: #{error.message}"
|
|
57
58
|
end
|
|
58
59
|
|
|
59
|
-
def build_http_client(uri)
|
|
60
|
+
def build_http_client(uri, timeout = nil)
|
|
60
61
|
http = Net::HTTP.new(uri.host, uri.port)
|
|
61
62
|
http.use_ssl = (uri.scheme == "https")
|
|
62
|
-
http.open_timeout = 5
|
|
63
|
-
http.read_timeout = 10
|
|
63
|
+
http.open_timeout = timeout || 5
|
|
64
|
+
http.read_timeout = timeout || 10
|
|
65
|
+
http.write_timeout = timeout if timeout
|
|
64
66
|
http
|
|
65
67
|
end
|
|
66
68
|
|
|
@@ -16,6 +16,8 @@ EzLogsAgent.configure do |config|
|
|
|
16
16
|
config.server_url = ENV.fetch("EZLOGS_SERVER_URL", "https://app.ezlogs.io")
|
|
17
17
|
|
|
18
18
|
# API key for your tenant. Get one at https://app.ezlogs.io/settings/api-keys.
|
|
19
|
+
# On boot the log shows "[EzLogsAgent] capturing → <host> (key ezl_<first 8>…)",
|
|
20
|
+
# or "[EzLogsAgent] not capturing: project_token missing" when this is unset.
|
|
19
21
|
config.project_token = ENV["EZLOGS_API_KEY"]
|
|
20
22
|
|
|
21
23
|
# =============================================================================
|
metadata
CHANGED
|
@@ -1,13 +1,13 @@
|
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
|
2
2
|
name: ez_logs_agent
|
|
3
3
|
version: !ruby/object:Gem::Version
|
|
4
|
-
version: 0.2.
|
|
4
|
+
version: 0.2.2
|
|
5
5
|
platform: ruby
|
|
6
6
|
authors:
|
|
7
7
|
- dezsirazvan
|
|
8
8
|
bindir: bin
|
|
9
9
|
cert_chain: []
|
|
10
|
-
date: 2026-
|
|
10
|
+
date: 2026-11-17 00:00:00.000000000 Z
|
|
11
11
|
dependencies:
|
|
12
12
|
- !ruby/object:Gem::Dependency
|
|
13
13
|
name: request_store
|
|
@@ -99,14 +99,14 @@ dependencies:
|
|
|
99
99
|
requirements:
|
|
100
100
|
- - "~>"
|
|
101
101
|
- !ruby/object:Gem::Version
|
|
102
|
-
version: '
|
|
102
|
+
version: '2.9'
|
|
103
103
|
type: :development
|
|
104
104
|
prerelease: false
|
|
105
105
|
version_requirements: !ruby/object:Gem::Requirement
|
|
106
106
|
requirements:
|
|
107
107
|
- - "~>"
|
|
108
108
|
- !ruby/object:Gem::Version
|
|
109
|
-
version: '
|
|
109
|
+
version: '2.9'
|
|
110
110
|
description: Captures HTTP requests, background jobs, and database changes from Rails
|
|
111
111
|
applications. Events are automatically correlated and sent to EzLogs Server, where
|
|
112
112
|
they are transformed into human-readable activity stories.
|