lognexis-ruby 1.0.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 +7 -0
- data/README.md +72 -0
- data/lib/lognexis/client.rb +32 -0
- data/lib/lognexis/rack_middleware.rb +43 -0
- data/lib/lognexis.rb +5 -0
- metadata +62 -0
checksums.yaml
ADDED
|
@@ -0,0 +1,7 @@
|
|
|
1
|
+
---
|
|
2
|
+
SHA256:
|
|
3
|
+
metadata.gz: a32cef2c39a5eaa03a633e6b3a84823de252f2fa1112591c37e27e21f146d00b
|
|
4
|
+
data.tar.gz: 9499d204c073c30dee3f8b2ed0242312cfaccfae91e30fae71178851839966b0
|
|
5
|
+
SHA512:
|
|
6
|
+
metadata.gz: ba908e63f8cc94f6514f5f2b4a49bf56205180ccbe2d1eeb55b64af39f5bd3756c54bab7d0955894c1d3d8c307d26272fd70edc5b21c047438b42a0c6ad33792
|
|
7
|
+
data.tar.gz: 14ea6a2452940881633a6f2ac8c4e3823d69e63075dfe90df19755082b1ff6daa13f1b8c8baa33e2eee28e93534c843d1ccb82bef35cdfc0bc7e857efeb46960
|
data/README.md
ADDED
|
@@ -0,0 +1,72 @@
|
|
|
1
|
+
# LogNexis Ruby SDK
|
|
2
|
+
|
|
3
|
+
The official Ruby tracking SDK for **LogNexis** — the lightweight, real-time API monitoring, analytics, and observability platform.
|
|
4
|
+
|
|
5
|
+
**Website:** [https://lognexis.online](https://lognexis.online)
|
|
6
|
+
**Documentation:** [https://lognexis.online/docs](https://lognexis.online/docs)
|
|
7
|
+
|
|
8
|
+
## What it does
|
|
9
|
+
Automatically capture API request logs, HTTP errors, latency metrics, and real-world performance without blocking your application threads. It works universally across any Rack-based framework.
|
|
10
|
+
|
|
11
|
+
## Installation
|
|
12
|
+
|
|
13
|
+
Add this line to your application's Gemfile:
|
|
14
|
+
|
|
15
|
+
```ruby
|
|
16
|
+
gem 'lognexis-ruby', '>= 1.0'
|
|
17
|
+
```
|
|
18
|
+
|
|
19
|
+
And then execute:
|
|
20
|
+
```bash
|
|
21
|
+
$ bundle install
|
|
22
|
+
```
|
|
23
|
+
|
|
24
|
+
Or install it yourself via:
|
|
25
|
+
```bash
|
|
26
|
+
$ gem install lognexis-ruby
|
|
27
|
+
```
|
|
28
|
+
|
|
29
|
+
## Quick Start (Ruby on Rails)
|
|
30
|
+
|
|
31
|
+
In your `config/application.rb` or inside a new initializer like `config/initializers/lognexis.rb`:
|
|
32
|
+
|
|
33
|
+
```ruby
|
|
34
|
+
require 'lognexis'
|
|
35
|
+
|
|
36
|
+
Rails.application.config.middleware.use LogNexis::RackMiddleware, api_key: "YOUR_LOGNEXIS_API_KEY"
|
|
37
|
+
```
|
|
38
|
+
|
|
39
|
+
## Quick Start (Sinatra / Rack)
|
|
40
|
+
|
|
41
|
+
In your `config.ru` or main app file:
|
|
42
|
+
|
|
43
|
+
```ruby
|
|
44
|
+
require 'sinatra'
|
|
45
|
+
require 'lognexis'
|
|
46
|
+
|
|
47
|
+
use LogNexis::RackMiddleware, api_key: "YOUR_LOGNEXIS_API_KEY"
|
|
48
|
+
|
|
49
|
+
get '/' do
|
|
50
|
+
'Hello World'
|
|
51
|
+
end
|
|
52
|
+
```
|
|
53
|
+
|
|
54
|
+
## Manual Usage (Background Jobs / Services)
|
|
55
|
+
|
|
56
|
+
If you aren't using a web server or want to log background jobs:
|
|
57
|
+
|
|
58
|
+
```ruby
|
|
59
|
+
require 'lognexis'
|
|
60
|
+
|
|
61
|
+
client = LogNexis::Client.new("YOUR_LOGNEXIS_API_KEY")
|
|
62
|
+
|
|
63
|
+
client.capture({
|
|
64
|
+
endpoint: "/custom-job/user-sync",
|
|
65
|
+
method: "POST",
|
|
66
|
+
statusCode: 200,
|
|
67
|
+
latency: 145.5
|
|
68
|
+
})
|
|
69
|
+
```
|
|
70
|
+
|
|
71
|
+
## How it works
|
|
72
|
+
This SDK uses Ruby's built-in `Net::HTTP` inside of a non-blocking `Thread.new` block. It operates in a completely "fire-and-forget" manner, meaning that even if the LogNexis servers were to go down, your application will NEVER crash and your API response times will NEVER be slowed down by this SDK.
|
|
@@ -0,0 +1,32 @@
|
|
|
1
|
+
require 'net/http'
|
|
2
|
+
require 'uri'
|
|
3
|
+
require 'json'
|
|
4
|
+
require 'thread'
|
|
5
|
+
|
|
6
|
+
module LogNexis
|
|
7
|
+
class Client
|
|
8
|
+
DEFAULT_BASE_URL = "https://lognexis-node.onrender.com".freeze
|
|
9
|
+
|
|
10
|
+
def initialize(api_key, base_url = DEFAULT_BASE_URL)
|
|
11
|
+
@api_key = api_key
|
|
12
|
+
@base_url = base_url.sub(/\/$/, '')
|
|
13
|
+
@endpoint = URI("#{@base_url}/api/logs/#{@api_key}")
|
|
14
|
+
end
|
|
15
|
+
|
|
16
|
+
def capture(log_data)
|
|
17
|
+
# Fire and forget in a background thread to prevent blocking
|
|
18
|
+
Thread.new do
|
|
19
|
+
begin
|
|
20
|
+
request = Net::HTTP::Post.new(@endpoint, 'Content-Type' => 'application/json')
|
|
21
|
+
request.body = log_data.to_json
|
|
22
|
+
|
|
23
|
+
Net::HTTP.start(@endpoint.hostname, @endpoint.port, use_ssl: @endpoint.scheme == 'https', open_timeout: 5, read_timeout: 5) do |http|
|
|
24
|
+
http.request(request)
|
|
25
|
+
end
|
|
26
|
+
rescue => e
|
|
27
|
+
# Silently fail, do not crash the user's application
|
|
28
|
+
end
|
|
29
|
+
end
|
|
30
|
+
end
|
|
31
|
+
end
|
|
32
|
+
end
|
|
@@ -0,0 +1,43 @@
|
|
|
1
|
+
require 'time'
|
|
2
|
+
require 'rack/request'
|
|
3
|
+
|
|
4
|
+
module LogNexis
|
|
5
|
+
class RackMiddleware
|
|
6
|
+
def initialize(app, api_key:, base_url: Client::DEFAULT_BASE_URL)
|
|
7
|
+
@app = app
|
|
8
|
+
@client = Client.new(api_key, base_url)
|
|
9
|
+
end
|
|
10
|
+
|
|
11
|
+
def call(env)
|
|
12
|
+
start_time = Process.clock_gettime(Process::CLOCK_MONOTONIC)
|
|
13
|
+
|
|
14
|
+
status, headers, response = @app.call(env)
|
|
15
|
+
|
|
16
|
+
latency = (Process.clock_gettime(Process::CLOCK_MONOTONIC) - start_time) * 1000.0
|
|
17
|
+
|
|
18
|
+
request = Rack::Request.new(env)
|
|
19
|
+
|
|
20
|
+
ip_address = env['HTTP_X_FORWARDED_FOR'] || env['REMOTE_ADDR'] || ''
|
|
21
|
+
ip_address = ip_address.split(',').first.strip if ip_address.include?(',')
|
|
22
|
+
|
|
23
|
+
req_headers = env.select { |k,v| k.start_with?('HTTP_') }
|
|
24
|
+
.map { |k,v| [k.sub(/^HTTP_/, '').split('_').map(&:capitalize).join('-'), v] }
|
|
25
|
+
.to_h
|
|
26
|
+
|
|
27
|
+
log_data = {
|
|
28
|
+
endpoint: request.path_info,
|
|
29
|
+
method: request.request_method,
|
|
30
|
+
statusCode: status.to_i,
|
|
31
|
+
latency: latency,
|
|
32
|
+
timestamp: Time.now.utc.strftime('%Y-%m-%dT%H:%M:%S.%L') + 'Z',
|
|
33
|
+
ipAddress: ip_address,
|
|
34
|
+
userAgent: request.user_agent || '',
|
|
35
|
+
requestHeaders: req_headers
|
|
36
|
+
}
|
|
37
|
+
|
|
38
|
+
@client.capture(log_data)
|
|
39
|
+
|
|
40
|
+
[status, headers, response]
|
|
41
|
+
end
|
|
42
|
+
end
|
|
43
|
+
end
|
data/lib/lognexis.rb
ADDED
metadata
ADDED
|
@@ -0,0 +1,62 @@
|
|
|
1
|
+
--- !ruby/object:Gem::Specification
|
|
2
|
+
name: lognexis-ruby
|
|
3
|
+
version: !ruby/object:Gem::Version
|
|
4
|
+
version: 1.0.2
|
|
5
|
+
platform: ruby
|
|
6
|
+
authors:
|
|
7
|
+
- Gopal562004
|
|
8
|
+
autorequire:
|
|
9
|
+
bindir: bin
|
|
10
|
+
cert_chain: []
|
|
11
|
+
date: 2026-07-13 00:00:00.000000000 Z
|
|
12
|
+
dependencies:
|
|
13
|
+
- !ruby/object:Gem::Dependency
|
|
14
|
+
name: rack
|
|
15
|
+
requirement: !ruby/object:Gem::Requirement
|
|
16
|
+
requirements:
|
|
17
|
+
- - ">="
|
|
18
|
+
- !ruby/object:Gem::Version
|
|
19
|
+
version: '2.0'
|
|
20
|
+
type: :runtime
|
|
21
|
+
prerelease: false
|
|
22
|
+
version_requirements: !ruby/object:Gem::Requirement
|
|
23
|
+
requirements:
|
|
24
|
+
- - ">="
|
|
25
|
+
- !ruby/object:Gem::Version
|
|
26
|
+
version: '2.0'
|
|
27
|
+
description: Lightweight middleware for Rails, Sinatra, and Rack applications to automatically
|
|
28
|
+
capture API request logs, errors, and latencies.
|
|
29
|
+
email:
|
|
30
|
+
- support@lognexis.online
|
|
31
|
+
executables: []
|
|
32
|
+
extensions: []
|
|
33
|
+
extra_rdoc_files: []
|
|
34
|
+
files:
|
|
35
|
+
- README.md
|
|
36
|
+
- lib/lognexis.rb
|
|
37
|
+
- lib/lognexis/client.rb
|
|
38
|
+
- lib/lognexis/rack_middleware.rb
|
|
39
|
+
homepage: https://lognexis.online
|
|
40
|
+
licenses:
|
|
41
|
+
- MIT
|
|
42
|
+
metadata: {}
|
|
43
|
+
post_install_message:
|
|
44
|
+
rdoc_options: []
|
|
45
|
+
require_paths:
|
|
46
|
+
- lib
|
|
47
|
+
required_ruby_version: !ruby/object:Gem::Requirement
|
|
48
|
+
requirements:
|
|
49
|
+
- - ">="
|
|
50
|
+
- !ruby/object:Gem::Version
|
|
51
|
+
version: '0'
|
|
52
|
+
required_rubygems_version: !ruby/object:Gem::Requirement
|
|
53
|
+
requirements:
|
|
54
|
+
- - ">="
|
|
55
|
+
- !ruby/object:Gem::Version
|
|
56
|
+
version: '0'
|
|
57
|
+
requirements: []
|
|
58
|
+
rubygems_version: 3.4.19
|
|
59
|
+
signing_key:
|
|
60
|
+
specification_version: 4
|
|
61
|
+
summary: Official LogNexis API Monitoring SDK
|
|
62
|
+
test_files: []
|