lognexis 1.0.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 +7 -0
- data/README.md +56 -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: 8f2e3f254da26e11a8b54379af8c7a3269848a8485cbec18ca2e5aef47e1649a
|
|
4
|
+
data.tar.gz: 5fa8355aa0d9673198a30e0fcd8fd9c114b35d0084ab9f741a22555ae886273b
|
|
5
|
+
SHA512:
|
|
6
|
+
metadata.gz: 5f00653a0388a3a534d2d88936ef1b5cd572b085b7c40c5b28fa052de52dc1107f418ee616c29c3dcbb9cf3301ab194cf7c26b11da0a9cc74828382e169511f0
|
|
7
|
+
data.tar.gz: c55770354cb93f1dff79c9970587a09930ace50348f66724a034f06c6a5203691dcafd6bf1d01065ecfc92136045fbc8d56a68cf6b8e1bca986116971379eac7
|
data/README.md
ADDED
|
@@ -0,0 +1,56 @@
|
|
|
1
|
+
# LogNexis Ruby SDK
|
|
2
|
+
|
|
3
|
+
Official Ruby tracking agent for LogNexis. Automatically capture API request logs, errors, and latencies without blocking your application. Supports any Rack-based framework (Rails, Sinatra, etc.).
|
|
4
|
+
|
|
5
|
+
## Installation
|
|
6
|
+
|
|
7
|
+
Add this line to your application's Gemfile:
|
|
8
|
+
|
|
9
|
+
```ruby
|
|
10
|
+
gem 'lognexis'
|
|
11
|
+
```
|
|
12
|
+
|
|
13
|
+
And then execute:
|
|
14
|
+
```bash
|
|
15
|
+
$ bundle install
|
|
16
|
+
```
|
|
17
|
+
|
|
18
|
+
## Quick Start (Ruby on Rails)
|
|
19
|
+
|
|
20
|
+
In your `config/application.rb` or inside an initializer like `config/initializers/lognexis.rb`:
|
|
21
|
+
|
|
22
|
+
```ruby
|
|
23
|
+
require 'lognexis'
|
|
24
|
+
|
|
25
|
+
Rails.application.config.middleware.use LogNexis::RackMiddleware, api_key: "YOUR_API_KEY"
|
|
26
|
+
```
|
|
27
|
+
|
|
28
|
+
## Quick Start (Sinatra / Rack)
|
|
29
|
+
|
|
30
|
+
In your `config.ru` or main app file:
|
|
31
|
+
|
|
32
|
+
```ruby
|
|
33
|
+
require 'sinatra'
|
|
34
|
+
require 'lognexis'
|
|
35
|
+
|
|
36
|
+
use LogNexis::RackMiddleware, api_key: "YOUR_API_KEY"
|
|
37
|
+
|
|
38
|
+
get '/' do
|
|
39
|
+
'Hello World'
|
|
40
|
+
end
|
|
41
|
+
```
|
|
42
|
+
|
|
43
|
+
## Manual Usage
|
|
44
|
+
|
|
45
|
+
```ruby
|
|
46
|
+
require 'lognexis'
|
|
47
|
+
|
|
48
|
+
client = LogNexis::Client.new("YOUR_API_KEY")
|
|
49
|
+
|
|
50
|
+
client.capture({
|
|
51
|
+
endpoint: "/custom-job",
|
|
52
|
+
method: "POST",
|
|
53
|
+
statusCode: 200,
|
|
54
|
+
latency: 45.5
|
|
55
|
+
})
|
|
56
|
+
```
|
|
@@ -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
|
|
3
|
+
version: !ruby/object:Gem::Version
|
|
4
|
+
version: 1.0.0
|
|
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://github.com/Gopal562004/ai-api-monitoring
|
|
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: []
|