# Treblle
+[![Build Status](https://github.com/Treblle/treblle-ruby/workflows/Tests/badge.svg)](https://github.com/Treblle/treblle-ruby/actions) [![Gem Version](https://badge.fury.io/rb/treblle.svg)](https://badge.fury.io/rb/treblle)
Integrations
•
diff --git a/lib/treblle/errors/configuration_errors.rb b/lib/treblle/errors/configuration_errors.rb
index 73d3cec..9489a97 100644
--- a/lib/treblle/errors/configuration_errors.rb
+++ b/lib/treblle/errors/configuration_errors.rb
@@ -2,19 +2,19 @@ module Treblle
module Errors
class ConfigurationError < StandardError
def initialize(msg = "Configuration error")
- super(msg)
+ super
end
end
class MissingApiKeyError < ConfigurationError
def initialize(msg = "API key is missing")
- super(msg)
+ super
end
end
class MissingProjectIdError < ConfigurationError
def initialize(msg = "Project ID is missing")
- super(msg)
+ super
end
end
end
diff --git a/lib/treblle/generate_payload.rb b/lib/treblle/generate_payload.rb
index 64f5c1e..1abb354 100644
--- a/lib/treblle/generate_payload.rb
+++ b/lib/treblle/generate_payload.rb
@@ -8,10 +8,11 @@ class GeneratePayload
SDK_LANG = 'ruby'
TIME_FORMAT = '%Y-%m-%d %H:%M:%S'
- def initialize(request:, response:, started_at:, configuration: Treblle.configuration)
+ def initialize(request:, response:, started_at:, load_time:, configuration: Treblle.configuration)
@request = request
@response = response
@started_at = started_at
+ @load_time = load_time
@configuration = configuration
end
@@ -21,18 +22,14 @@ def call
private
- attr_reader :request, :response, :started_at, :configuration
+ attr_reader :request, :response, :started_at, :load_time, :configuration
def sanitize(body)
Utils::HashSanitizer.sanitize(body, configuration.sensitive_attrs)
end
def timestamp
- started_at.strftime(TIME_FORMAT)
- end
-
- def load_time
- Time.now - started_at
+ started_at.utc.strftime(TIME_FORMAT)
end
def payload
diff --git a/lib/treblle/middleware.rb b/lib/treblle/middleware.rb
index 28174ac..3cd6add 100644
--- a/lib/treblle/middleware.rb
+++ b/lib/treblle/middleware.rb
@@ -29,18 +29,25 @@ def call(env)
attr_reader :configuration
def call_with_treblle_monitoring(env)
- started_at = Time.now
+ started_at = Time.now.utc
response = @app.call(env)
- handle_monitoring(env, response, started_at)
+
+ load_time = Time.now.utc - started_at
+ handle_monitoring(env, response, started_at, load_time)
response
end
- def handle_monitoring(env, rack_response, started_at)
+ def handle_monitoring(env, rack_response, started_at, load_time)
request = RequestBuilder.new(env).build
response = ResponseBuilder.new(rack_response).build
- payload = GeneratePayload.new(request: request, response: response, started_at: started_at).call
+ payload = GeneratePayload.new(
+ request: request,
+ response: response,
+ started_at: started_at,
+ load_time: load_time
+ ).call
Dispatcher.new(payload: payload).call
rescue StandardError => e
diff --git a/lib/treblle/utils/hash_sanitizer.rb b/lib/treblle/utils/hash_sanitizer.rb
index 93c5f35..49a7206 100644
--- a/lib/treblle/utils/hash_sanitizer.rb
+++ b/lib/treblle/utils/hash_sanitizer.rb
@@ -32,7 +32,7 @@ def sanitize_array(array, sensitive_attrs)
end
def sanitize_value(key, value, sensitive_attrs)
- sensitive_attrs.include?(key.to_s) ? '*' * value.to_s.length : value
+ sensitive_attrs.include?(key.to_s) ? "*****" : value
end
end
end
diff --git a/spec/lib/utils/hash_sanitizer_spec.rb b/spec/lib/utils/hash_sanitizer_spec.rb
index bc100ab..7594cc7 100644
--- a/spec/lib/utils/hash_sanitizer_spec.rb
+++ b/spec/lib/utils/hash_sanitizer_spec.rb
@@ -33,7 +33,7 @@
context 'when given a hash with sensitive attributes' do
let(:input_hash) { { name: 'John', password: 'secretpassword', credit_card: '1234567890123456' } }
- let(:expected_subject) { { name: 'John', password: '**************', credit_card: '****************' } }
+ let(:expected_subject) { { name: 'John', password: '*****', credit_card: '*****' } }
it 'replaces sensitive attribute values with asterisks' do
expect(subject).to eq(expected_subject)
@@ -42,7 +42,7 @@
context 'when given a hash with nested hashes' do
let(:input_hash) { { user: { name: 'John', password: 'secretpassword' } } }
- let(:expected_subject) { { user: { name: 'John', password: '**************' } } }
+ let(:expected_subject) { { user: { name: 'John', password: '*****' } } }
it 'replaces sensitive attribute values with asterisks' do
expect(subject).to eq(expected_subject)
@@ -54,7 +54,7 @@
{ users: [{ name: 'John', password: 'secretpassword' }, { name: 'Jane', password: 'anotherpassword' }] }
end
let(:expected_subject) do
- { users: [{ name: 'John', password: '**************' }, { name: 'Jane', password: '***************' }] }
+ { users: [{ name: 'John', password: '*****' }, { name: 'Jane', password: '*****' }] }
end
it 'replaces sensitive attribute values with asterisks' do