salopulse 0.1.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 ADDED
@@ -0,0 +1,7 @@
1
+ ---
2
+ SHA256:
3
+ metadata.gz: 508b79a0d71e8bf74c4c743df633f4c78d54607acf341587bcb6a29eeeb7f0c8
4
+ data.tar.gz: 9b27e52989cebcdaa7f6b48f4b9b758422c362c1e91fc3f93e35e3c26e06030f
5
+ SHA512:
6
+ metadata.gz: 9c6dd7aabc843b88d157244c9479ef89786d4efcf20c4b0db7330b596b259a5c9ede75e9bf491ed0e29459d60580d516794303274b97a99f8ebdc89159214278
7
+ data.tar.gz: 760dc6b01a270fcf26ee5e90a8ad1c60fbb7951168baa1bb9caf654526d7ea6ab3e2d1b09c84bcf5368962707c60530a2bf5b1ec13620bf9ba070571112b73a7
data/LICENSE ADDED
@@ -0,0 +1,28 @@
1
+
2
+ ---
3
+
4
+ # 📄 **3. `LICENSE`
5
+
6
+ ```text
7
+ MIT License
8
+
9
+ Copyright (c) 2025 Salo Company
10
+ All rights reserved.
11
+
12
+ Permission is hereby granted, free of charge, to any person obtaining a copy
13
+ of this software and associated documentation files (the "Software"), to deal
14
+ in the Software without restriction, including without limitation the rights
15
+ to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
16
+ copies of the Software, and to permit persons to whom the Software is
17
+ furnished to do so, subject to the following conditions:
18
+
19
+ The above copyright notice and this permission notice shall be included in
20
+ all copies or substantial portions of the Software.
21
+
22
+ THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
23
+ IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
24
+ FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
25
+ AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
26
+ LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
27
+ OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
28
+ THE SOFTWARE.
data/README.md ADDED
@@ -0,0 +1,26 @@
1
+ # SaloPulse Ruby SDK
2
+
3
+ SaloPulse Ruby SDK, Ruby ve Ruby on Rails projeleri için geliştirilmiş hafif ve modern bir **monitoring & analytics entegrasyon kütüphanesidir**.
4
+
5
+ Bu SDK, uygulamanızdaki her HTTP isteğini otomatik olarak izler, performans ölçer ve verileri **SaloPulse Observability Platformu**na güvenli bir şekilde iletir.
6
+
7
+ ---
8
+
9
+ ## 🚀 Özellikler
10
+
11
+ - Otomatik request yakalama (middleware)
12
+ - Path, method, status, response time ölçümü
13
+ - IP & User-Agent toplama
14
+ - API key tabanlı güvenli kimliklendirme
15
+ - SaloPulse backend’e JSON gönderimi
16
+ - Non-blocking – uygulamanızı hiçbir zaman bozmaz
17
+ - Production-ready – enterprise sistemler için uygundur
18
+
19
+ ---
20
+
21
+ ## 📦 Kurulum
22
+
23
+ ### 1. Gem ekle
24
+
25
+ ```ruby
26
+ gem "salopulse"
@@ -0,0 +1,52 @@
1
+ # frozen_string_literal: true
2
+
3
+ require 'net/http'
4
+ require 'uri'
5
+ require 'json'
6
+
7
+ module SaloPulse
8
+ class Client
9
+ class << self
10
+ def send_event(payload)
11
+ config = SaloPulse.config
12
+
13
+ return unless config.valid?
14
+
15
+ uri = URI.parse(config.endpoint)
16
+
17
+ http = Net::HTTP.new(uri.host, uri.port)
18
+ http.use_ssl = uri.scheme == 'https'
19
+ http.read_timeout = config.timeout
20
+ http.open_timeout = config.timeout
21
+
22
+ request = Net::HTTP::Post.new(uri.request_uri)
23
+ request['Content-Type'] = 'application/json'
24
+ request['Accept'] = 'application/json'
25
+
26
+ body = payload.merge(
27
+ api_key: config.api_key,
28
+ environment: config.environment
29
+ )
30
+
31
+ request.body = JSON.generate(body)
32
+
33
+ http.request(request)
34
+ rescue StandardError => e
35
+ log_error(e)
36
+ nil
37
+ end
38
+
39
+ private
40
+
41
+ def log_error(error)
42
+ message = "[SaloPulse] Failed to send event: #{error.class}: #{error.message}"
43
+
44
+ if defined?(Rails)
45
+ Rails.logger.debug(message)
46
+ else
47
+ warn(message)
48
+ end
49
+ end
50
+ end
51
+ end
52
+ end
@@ -0,0 +1,19 @@
1
+ # frozen_string_literal: true
2
+
3
+ module SaloPulse
4
+ class Configuration
5
+ attr_accessor :api_key, :environment, :endpoint, :timeout, :enabled
6
+
7
+ def initialize
8
+ @api_key = ENV['SALO_PULSE_API_KEY']
9
+ @environment = ENV['RAILS_ENV'] || ENV['RACK_ENV'] || 'development'
10
+ @endpoint = ENV['SALO_PULSE_ENDPOINT'] || 'https://api.salopulse.com/v1/ingest'
11
+ @timeout = 1.0
12
+ @enabled = true
13
+ end
14
+
15
+ def valid?
16
+ @enabled && @api_key && !@api_key.strip.empty?
17
+ end
18
+ end
19
+ end
@@ -0,0 +1,69 @@
1
+ # frozen_string_literal: true
2
+
3
+ require 'rack'
4
+ require 'time'
5
+
6
+ module SaloPulse
7
+ class Middleware
8
+ def initialize(app)
9
+ @app = app
10
+ end
11
+
12
+ def call(env)
13
+ start_monotonic = monotonic_time
14
+
15
+ status, headers, body = @app.call(env)
16
+
17
+ duration_ms = ((monotonic_time - start_monotonic) * 1000.0).round(2)
18
+
19
+ begin
20
+ event = build_event(env, status, duration_ms)
21
+ SaloPulse::Client.send_event(event) if event
22
+ rescue StandardError => e
23
+ log_middleware_error(e)
24
+ end
25
+
26
+ [status, headers, body]
27
+ end
28
+
29
+ private
30
+
31
+ def monotonic_time
32
+ Process.clock_gettime(Process::CLOCK_MONOTONIC)
33
+ end
34
+
35
+ def build_event(env, status, duration_ms)
36
+ req = Rack::Request.new(env)
37
+
38
+ {
39
+ path: req.path,
40
+ method: req.request_method,
41
+ status: status,
42
+ duration_ms: duration_ms,
43
+ ip: extract_ip(env, req),
44
+ user_agent: env['HTTP_USER_AGENT'],
45
+ occurred_at: Time.now.utc.iso8601
46
+ }
47
+ end
48
+
49
+ def extract_ip(env, req)
50
+ if env['action_dispatch.remote_ip']
51
+ env['action_dispatch.remote_ip'].to_s
52
+ elsif req.respond_to?(:ip)
53
+ req.ip
54
+ else
55
+ env['REMOTE_ADDR']
56
+ end
57
+ end
58
+
59
+ def log_middleware_error(error)
60
+ message = "[SaloPulse] Middleware error: #{error.class}: #{error.message}"
61
+
62
+ if defined?(Rails)
63
+ Rails.logger.debug(message)
64
+ else
65
+ warn(message)
66
+ end
67
+ end
68
+ end
69
+ end
data/lib/salopulse.rb ADDED
@@ -0,0 +1,18 @@
1
+ # frozen_string_literal: true
2
+
3
+ require "salopulse/version"
4
+ require "salopulse/configuration"
5
+ require "salopulse/client"
6
+ require "salopulse/middleware"
7
+
8
+ module SaloPulse
9
+ class << self
10
+ def configure
11
+ yield config
12
+ end
13
+
14
+ def config
15
+ @config ||= Configuration.new
16
+ end
17
+ end
18
+ end
metadata ADDED
@@ -0,0 +1,77 @@
1
+ --- !ruby/object:Gem::Specification
2
+ name: salopulse
3
+ version: !ruby/object:Gem::Version
4
+ version: 0.1.0
5
+ platform: ruby
6
+ authors:
7
+ - Salih İmran Büker
8
+ bindir: bin
9
+ cert_chain: []
10
+ date: 1980-01-02 00:00:00.000000000 Z
11
+ dependencies:
12
+ - !ruby/object:Gem::Dependency
13
+ name: json
14
+ requirement: !ruby/object:Gem::Requirement
15
+ requirements:
16
+ - - ">="
17
+ - !ruby/object:Gem::Version
18
+ version: '0'
19
+ type: :runtime
20
+ prerelease: false
21
+ version_requirements: !ruby/object:Gem::Requirement
22
+ requirements:
23
+ - - ">="
24
+ - !ruby/object:Gem::Version
25
+ version: '0'
26
+ - !ruby/object:Gem::Dependency
27
+ name: net-http
28
+ requirement: !ruby/object:Gem::Requirement
29
+ requirements:
30
+ - - ">="
31
+ - !ruby/object:Gem::Version
32
+ version: '0'
33
+ type: :runtime
34
+ prerelease: false
35
+ version_requirements: !ruby/object:Gem::Requirement
36
+ requirements:
37
+ - - ">="
38
+ - !ruby/object:Gem::Version
39
+ version: '0'
40
+ description: SaloPulse Ruby SDK provides automatic request tracking, performance measurement,
41
+ and real-time analytics integration for Rails apps. It captures HTTP traffic and
42
+ sends metrics to the SaloPulse Observability Platform.
43
+ email:
44
+ - info@salopulse.com
45
+ executables: []
46
+ extensions: []
47
+ extra_rdoc_files: []
48
+ files:
49
+ - LICENSE
50
+ - README.md
51
+ - lib/salopulse.rb
52
+ - lib/salopulse/client.rb
53
+ - lib/salopulse/configuration.rb
54
+ - lib/salopulse/middleware.rb
55
+ homepage: https://github.com/mersies/salopulse-sdk-ruby
56
+ licenses:
57
+ - MIT
58
+ metadata: {}
59
+ rdoc_options: []
60
+ require_paths:
61
+ - lib
62
+ required_ruby_version: !ruby/object:Gem::Requirement
63
+ requirements:
64
+ - - ">="
65
+ - !ruby/object:Gem::Version
66
+ version: '2.7'
67
+ required_rubygems_version: !ruby/object:Gem::Requirement
68
+ requirements:
69
+ - - ">="
70
+ - !ruby/object:Gem::Version
71
+ version: '0'
72
+ requirements: []
73
+ rubygems_version: 3.7.2
74
+ specification_version: 4
75
+ summary: SaloPulse Ruby SDK – Lightweight monitoring and request analytics for Rails
76
+ applications.
77
+ test_files: []