sqreen 1.19.2 → 1.21.0.beta2
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/CHANGELOG.md +21 -0
- data/lib/sqreen/agent_message.rb +20 -0
- data/lib/sqreen/aggregated_metric.rb +25 -0
- data/lib/sqreen/attack_detected.html +1 -2
- data/lib/sqreen/ca.crt +24 -0
- data/lib/sqreen/configuration.rb +10 -4
- data/lib/sqreen/deliveries/batch.rb +12 -2
- data/lib/sqreen/deliveries/simple.rb +4 -0
- data/lib/sqreen/ecosystem.rb +96 -0
- data/lib/sqreen/ecosystem/dispatch_table.rb +43 -0
- data/lib/sqreen/ecosystem/exception_reporting.rb +26 -0
- data/lib/sqreen/ecosystem/http/net_http.rb +50 -0
- data/lib/sqreen/ecosystem/http/rack_request.rb +39 -0
- data/lib/sqreen/ecosystem/loggable.rb +13 -0
- data/lib/sqreen/ecosystem/module_api.rb +30 -0
- data/lib/sqreen/ecosystem/module_api/event_listener.rb +18 -0
- data/lib/sqreen/ecosystem/module_api/instrumentation.rb +23 -0
- data/lib/sqreen/ecosystem/module_api/message_producer.rb +51 -0
- data/lib/sqreen/ecosystem/module_api/signal_producer.rb +24 -0
- data/lib/sqreen/ecosystem/module_api/tracing.rb +45 -0
- data/lib/sqreen/ecosystem/module_api/tracing/client_data.rb +31 -0
- data/lib/sqreen/ecosystem/module_api/tracing/server_data.rb +27 -0
- data/lib/sqreen/ecosystem/module_api/tracing_id_generation.rb +16 -0
- data/lib/sqreen/ecosystem/module_api/transaction_storage.rb +71 -0
- data/lib/sqreen/ecosystem/module_registry.rb +44 -0
- data/lib/sqreen/ecosystem/redis/redis_connection.rb +43 -0
- data/lib/sqreen/ecosystem/tracing/modules/client.rb +31 -0
- data/lib/sqreen/ecosystem/tracing/modules/server.rb +30 -0
- data/lib/sqreen/ecosystem/tracing/sampler.rb +160 -0
- data/lib/sqreen/ecosystem/tracing/sampling_configuration.rb +150 -0
- data/lib/sqreen/ecosystem/tracing/signals/tracing_client.rb +53 -0
- data/lib/sqreen/ecosystem/tracing/signals/tracing_server.rb +53 -0
- data/lib/sqreen/ecosystem/tracing_broker.rb +101 -0
- data/lib/sqreen/ecosystem/tracing_id_setup.rb +34 -0
- data/lib/sqreen/ecosystem/transaction_storage.rb +64 -0
- data/lib/sqreen/ecosystem/util/call_writers_from_init.rb +13 -0
- data/lib/sqreen/ecosystem_integration.rb +81 -0
- data/lib/sqreen/ecosystem_integration/around_callbacks.rb +89 -0
- data/lib/sqreen/ecosystem_integration/instrumentation_service.rb +38 -0
- data/lib/sqreen/ecosystem_integration/request_lifecycle_tracking.rb +58 -0
- data/lib/sqreen/ecosystem_integration/signal_consumption.rb +35 -0
- data/lib/sqreen/endpoint_testing.rb +184 -0
- data/lib/sqreen/event.rb +7 -5
- data/lib/sqreen/events/attack.rb +23 -18
- data/lib/sqreen/events/remote_exception.rb +0 -22
- data/lib/sqreen/events/request_record.rb +15 -70
- data/lib/sqreen/frameworks/generic.rb +15 -1
- data/lib/sqreen/frameworks/request_recorder.rb +13 -2
- data/lib/sqreen/graft/call.rb +9 -0
- data/lib/sqreen/kit/signals/specialized/aggregated_metric.rb +72 -0
- data/lib/sqreen/kit/signals/specialized/attack.rb +57 -0
- data/lib/sqreen/kit/signals/specialized/binning_metric.rb +76 -0
- data/lib/sqreen/kit/signals/specialized/http_trace.rb +26 -0
- data/lib/sqreen/kit/signals/specialized/sdk_track_call.rb +50 -0
- data/lib/sqreen/kit/signals/specialized/sqreen_exception.rb +57 -0
- data/lib/sqreen/legacy/old_event_submission_strategy.rb +227 -0
- data/lib/sqreen/legacy/waf_redactions.rb +49 -0
- data/lib/sqreen/log/loggable.rb +1 -1
- data/lib/sqreen/metrics/base.rb +3 -0
- data/lib/sqreen/metrics_store.rb +22 -12
- data/lib/sqreen/performance_notifications/binned_metrics.rb +8 -2
- data/lib/sqreen/remote_command.rb +3 -0
- data/lib/sqreen/rules.rb +4 -2
- data/lib/sqreen/rules/rule_cb.rb +2 -0
- data/lib/sqreen/rules/waf_cb.rb +13 -10
- data/lib/sqreen/runner.rb +94 -13
- data/lib/sqreen/sensitive_data_redactor.rb +19 -31
- data/lib/sqreen/session.rb +53 -43
- data/lib/sqreen/signals/conversions.rb +288 -0
- data/lib/sqreen/signals/http_trace_redaction.rb +111 -0
- data/lib/sqreen/signals/signals_submission_strategy.rb +78 -0
- data/lib/sqreen/version.rb +1 -1
- metadata +83 -10
- data/lib/sqreen/backport.rb +0 -9
- data/lib/sqreen/backport/clock_gettime.rb +0 -74
- data/lib/sqreen/backport/original_name.rb +0 -88
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA256:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: e5b3d6fc37fd5d2431e622d302fd3f58d35dd64a3fc7abca741a84b213688025
|
4
|
+
data.tar.gz: a3443a3f1c95841af9deb7eb5f4a5ab8c47aabf6c6f42eeb902d828edd3ad91d
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 487d63ea8f4bc8c5d3da55dced0c8d458c6a6c7f218689027925d8f6ca2808fc4eda478e57ca67764edb8a049fb8fae60b552974ffa39dfaa0dcd15d31f34071
|
7
|
+
data.tar.gz: 23cf04763b76e95d421a36593c2b96d91aad0f40bc206fe8608606fad803a464d03518ac92b40e4c1bb667dbd163ba79c6380f605b1133270f65d66fb8314173
|
data/CHANGELOG.md
CHANGED
@@ -1,3 +1,24 @@
|
|
1
|
+
## 1.21.0.beta2
|
2
|
+
|
3
|
+
* Improve transport and tracing internals
|
4
|
+
|
5
|
+
## 1.21.0.beta1
|
6
|
+
|
7
|
+
* Add transport and tracing internals
|
8
|
+
|
9
|
+
## 1.20.1
|
10
|
+
|
11
|
+
* Add fallback mechanisms when connecting to new Sqreen backend API domains
|
12
|
+
|
13
|
+
## 1.20.0
|
14
|
+
|
15
|
+
* Enable new instrumentation engine by default
|
16
|
+
* Add signal-based backend communication
|
17
|
+
|
18
|
+
## 1.19.3
|
19
|
+
|
20
|
+
* Improve WAF PII protection
|
21
|
+
|
1
22
|
## 1.19.2
|
2
23
|
|
3
24
|
* Handle unexpected rule callback return values more gracefully
|
@@ -0,0 +1,20 @@
|
|
1
|
+
require 'digest'
|
2
|
+
|
3
|
+
module Sqreen
|
4
|
+
class AgentMessage
|
5
|
+
def initialize(kind, message, id = nil)
|
6
|
+
id ||= message + "\x00" + kind
|
7
|
+
@hash_hex = Digest::SHA1.hexdigest(id)
|
8
|
+
@kind = kind
|
9
|
+
@message = message
|
10
|
+
end
|
11
|
+
|
12
|
+
def to_h
|
13
|
+
{
|
14
|
+
id: @hash_hex,
|
15
|
+
kind: @kind,
|
16
|
+
message: @message,
|
17
|
+
}
|
18
|
+
end
|
19
|
+
end
|
20
|
+
end
|
@@ -0,0 +1,25 @@
|
|
1
|
+
require 'sqreen/rules/rule_cb'
|
2
|
+
require 'sqreen/metrics/base'
|
3
|
+
|
4
|
+
module Sqreen
|
5
|
+
class AggregatedMetric
|
6
|
+
def initialize(values = {})
|
7
|
+
values.each do |k, v|
|
8
|
+
public_send "#{k}=", v
|
9
|
+
end
|
10
|
+
end
|
11
|
+
|
12
|
+
# @return [Sqreen::Rules::RuleCB]
|
13
|
+
attr_accessor :rule # optional
|
14
|
+
|
15
|
+
# @return [Sqreen::Metric::Base]
|
16
|
+
attr_accessor :metric
|
17
|
+
|
18
|
+
attr_accessor :start, :finish
|
19
|
+
attr_accessor :data
|
20
|
+
|
21
|
+
def name
|
22
|
+
metric.name
|
23
|
+
end
|
24
|
+
end
|
25
|
+
end
|
@@ -1,2 +1 @@
|
|
1
|
-
|
2
|
-
|
1
|
+
<!-- Sorry, you’ve been blocked --><!DOCTYPE html><html lang="en"><head><meta charset="UTF-8"><meta name="viewport" content="width=device-width,initial-scale=1"><title>You've been blocked</title><style>a,body,div,h1,html,span{margin:0;padding:0;border:0;font-size:100%;font:inherit;vertical-align:baseline}body{background:-webkit-radial-gradient(26% 19%,circle,#fff,#f4f7f9);background:radial-gradient(circle at 26% 19%,#fff,#f4f7f9);display:-webkit-box;display:-ms-flexbox;display:flex;-webkit-box-pack:center;-ms-flex-pack:center;justify-content:center;-webkit-box-align:center;-ms-flex-align:center;align-items:center;-ms-flex-line-pack:center;align-content:center;width:100%;min-height:100vh;line-height:1;flex-direction:column}h1,p,svg{display:block}svg{margin:0 auto 4vh}main{text-align:center;flex:1;display:-webkit-box;display:-ms-flexbox;display:flex;-webkit-box-pack:center;-ms-flex-pack:center;justify-content:center;-webkit-box-align:center;-ms-flex-align:center;align-items:center;-ms-flex-line-pack:center;align-content:center;flex-direction:column}h1{font-family:sans-serif;font-weight:600;font-size:34px;color:#1e0936;line-height:1.2}p{font-size:18px;line-height:normal;color:#646464;font-family:sans-serif;font-weight:400}a{color:#4842b7}footer{width:100%;text-align:center}footer p{font-size:16px}</style></head><body><main><svg width="170px" height="193px" viewBox="0 0 170 193" version="1.1" xmlns="http://www.w3.org/2000/svg" xmlns:xlink="http://www.w3.org/1999/xlink" aria-hidden="true"><g id="exports" stroke="none" stroke-width="1" fill="none" fill-rule="evenodd"><g id="Artboard" transform="translate(-186.000000, -189.000000)"><g id="logo-cmyk-indigo" transform="translate(186.000000, 189.000000)"><g id="nest-cmyk-indigo"><ellipse id="sqreen" fill="#B0ACFF" cx="85" cy="96.5" rx="45.7692308" ry="45.7966102"></ellipse><path d="M78.4615385,175.749389 L78.4615385,102.2092 L13.1398162,64.4731256 L13.1398162,129.181112 L36.352167,115.771438 C37.9764468,119.873152 40.1038639,123.720553 42.6582364,127.237412 L18.5723996,141.151695 L78.4615385,175.749389 Z M91.5384615,175.749389 L151.4276,141.151695 L127.341764,127.237412 C129.896136,123.720553 132.023553,119.873152 133.647833,115.771438 L156.860184,129.181112 L156.860184,64.4731256 L91.5384615,102.2092 L91.5384615,175.749389 Z M18.0061522,52.1754237 L85,90.8774777 L151.993848,52.1754237 L91.5384615,17.2506105 L91.5384615,44.565949 C89.3964992,44.2986903 87.2143177,44.1610169 85,44.1610169 C82.7856823,44.1610169 80.6035008,44.2986903 78.4615385,44.565949 L78.4615385,17.2506105 L18.0061522,52.1754237 Z M90.8846156,1.76392358 L164.052491,44.0326866 C167.693904,46.1363149 169.937107,50.0239804 169.937107,54.231237 L169.937107,138.768763 C169.937107,142.97602 167.693904,146.863685 164.052491,148.967313 L90.8846156,191.236076 C87.2432028,193.339705 82.7567972,193.339705 79.1153844,191.236076 L5.94750871,148.967313 C2.30609589,146.863685 0.0628930904,142.97602 0.0628930904,138.768763 L0.0628930904,54.231237 C0.0628930904,50.0239804 2.30609589,46.1363149 5.94750871,44.0326866 L79.1153844,1.76392358 C82.7567972,-0.339704735 87.2432028,-0.339704735 90.8846156,1.76392358 Z" id="app" fill="#4842B7"></path></g></g></g></g></svg><h1>Sorry, you've been blocked</h1><p>Contact the website owner</p></main><footer><p>Security provided by <a href="https://www.sqreen.com/?utm_medium=block_page" target="_blank">Sqreen</a></p></footer></body></html>
|
data/lib/sqreen/ca.crt
CHANGED
@@ -70,3 +70,27 @@ WE9gyn6CagsCqiUXObXbf+eEZSqVir2G3l6BFoMtEMze/aiCKm0oHw0LxOXnGiYZ
|
|
70
70
|
4fQRbxC1lfznQgUy286dUV4otp6F01vvpX1FQHKOtw5rDgb7MzVIcbidJ4vEZV8N
|
71
71
|
hnacRHr2lVz2XTIIM6RUthg/aFzyQkqFOFSDX9HoLPKsEdao7WNq
|
72
72
|
-----END CERTIFICATE-----
|
73
|
+
-----BEGIN CERTIFICATE-----
|
74
|
+
MIID7zCCAtegAwIBAgIBADANBgkqhkiG9w0BAQsFADCBmDELMAkGA1UEBhMCVVMx
|
75
|
+
EDAOBgNVBAgTB0FyaXpvbmExEzARBgNVBAcTClNjb3R0c2RhbGUxJTAjBgNVBAoT
|
76
|
+
HFN0YXJmaWVsZCBUZWNobm9sb2dpZXMsIEluYy4xOzA5BgNVBAMTMlN0YXJmaWVs
|
77
|
+
ZCBTZXJ2aWNlcyBSb290IENlcnRpZmljYXRlIEF1dGhvcml0eSAtIEcyMB4XDTA5
|
78
|
+
MDkwMTAwMDAwMFoXDTM3MTIzMTIzNTk1OVowgZgxCzAJBgNVBAYTAlVTMRAwDgYD
|
79
|
+
VQQIEwdBcml6b25hMRMwEQYDVQQHEwpTY290dHNkYWxlMSUwIwYDVQQKExxTdGFy
|
80
|
+
ZmllbGQgVGVjaG5vbG9naWVzLCBJbmMuMTswOQYDVQQDEzJTdGFyZmllbGQgU2Vy
|
81
|
+
dmljZXMgUm9vdCBDZXJ0aWZpY2F0ZSBBdXRob3JpdHkgLSBHMjCCASIwDQYJKoZI
|
82
|
+
hvcNAQEBBQADggEPADCCAQoCggEBANUMOsQq+U7i9b4Zl1+OiFOxHz/Lz58gE20p
|
83
|
+
OsgPfTz3a3Y4Y9k2YKibXlwAgLIvWX/2h/klQ4bnaRtSmpDhcePYLQ1Ob/bISdm2
|
84
|
+
8xpWriu2dBTrz/sm4xq6HZYuajtYlIlHVv8loJNwU4PahHQUw2eeBGg6345AWh1K
|
85
|
+
Ts9DkTvnVtYAcMtS7nt9rjrnvDH5RfbCYM8TWQIrgMw0R9+53pBlbQLPLJGmpufe
|
86
|
+
hRhJfGZOozptqbXuNC66DQO4M99H67FrjSXZm86B0UVGMpZwh94CDklDhbZsc7tk
|
87
|
+
6mFBrMnUVN+HL8cisibMn1lUaJ/8viovxFUcdUBgF4UCVTmLfwUCAwEAAaNCMEAw
|
88
|
+
DwYDVR0TAQH/BAUwAwEB/zAOBgNVHQ8BAf8EBAMCAQYwHQYDVR0OBBYEFJxfAN+q
|
89
|
+
AdcwKziIorhtSpzyEZGDMA0GCSqGSIb3DQEBCwUAA4IBAQBLNqaEd2ndOxmfZyMI
|
90
|
+
bw5hyf2E3F/YNoHN2BtBLZ9g3ccaaNnRbobhiCPPE95Dz+I0swSdHynVv/heyNXB
|
91
|
+
ve6SbzJ08pGCL72CQnqtKrcgfU28elUSwhXqvfdqlS5sdJ/PHLTyxQGjhdByPq1z
|
92
|
+
qwubdQxtRbeOlKyWN7Wg0I8VRw7j6IPdj/3vQQF3zCepYoUz8jcI73HPdwbeyBkd
|
93
|
+
iEDPfUYd/x7H4c7/I9vG+o1VTqkC50cRRj70/b17KSa7qWFiNyi2LSr2EIZkyXCn
|
94
|
+
0q23KXB56jzaYyWf/Wi3MOxw+3WKt21gZ7IeyLnp2KhvAotnDU0mV3HaIPzBSlCN
|
95
|
+
sSi6
|
96
|
+
-----END CERTIFICATE-----
|
data/lib/sqreen/configuration.rb
CHANGED
@@ -39,11 +39,15 @@ module Sqreen
|
|
39
39
|
{ :env => :SQREEN_LIBSQREEN, :name => :libsqreen,
|
40
40
|
:default => true, :convert => :to_bool },
|
41
41
|
{ :env => :SQREEN_WEAVE, :name => :weave,
|
42
|
-
:default =>
|
42
|
+
:default => true, :convert => :to_bool },
|
43
43
|
{ :env => :SQREEN_WEAVE_STRATEGY, :name => :weave_strategy,
|
44
|
-
:default => :
|
45
|
-
{ :env => :SQREEN_URL,
|
46
|
-
:default =>
|
44
|
+
:default => :prepend, :convert => :to_sym },
|
45
|
+
{ :env => :SQREEN_URL, :name => :url,
|
46
|
+
:default => nil },
|
47
|
+
{ :env => :SQREEN_INGESTION_URL, :name => :ingestion_url,
|
48
|
+
:default => nil },
|
49
|
+
{ :env => :SQREEN_PROXY_URL, :name => :proxy_url,
|
50
|
+
:default => nil },
|
47
51
|
{ :env => :SQREEN_TOKEN, :name => :token,
|
48
52
|
:default => nil },
|
49
53
|
{ :env => :SQREEN_APP_NAME, :name => :app_name,
|
@@ -74,6 +78,8 @@ module Sqreen
|
|
74
78
|
:default => nil },
|
75
79
|
{ :env => :SQREEN_STRIP_SENSITIVE_REGEX, :name => :strip_sensitive_regex,
|
76
80
|
:default => nil },
|
81
|
+
{ :env => :SQREEN_NO_SNIFF_DOMAINS, :name => :no_sniff_domains,
|
82
|
+
:default => false },
|
77
83
|
|
78
84
|
].freeze
|
79
85
|
|
@@ -8,10 +8,13 @@
|
|
8
8
|
# TODO: Sqreen::RequestRecord => sqreen/events
|
9
9
|
# TODO: Sqreen.time
|
10
10
|
|
11
|
+
require 'sqreen/aggregated_metric'
|
11
12
|
require 'sqreen/events/attack'
|
12
13
|
require 'sqreen/events/remote_exception'
|
13
14
|
require 'sqreen/mono_time'
|
14
15
|
require 'sqreen/deliveries/simple'
|
16
|
+
require 'sqreen/kit/signals/signal'
|
17
|
+
require 'sqreen/kit/signals/trace'
|
15
18
|
|
16
19
|
module Sqreen
|
17
20
|
module Deliveries
|
@@ -57,7 +60,7 @@ module Sqreen
|
|
57
60
|
def post_batch_needed?(event)
|
58
61
|
now = Sqreen.time
|
59
62
|
# do not use any? {} due to side effects inside block
|
60
|
-
event_keys(event).map do |key|
|
63
|
+
event_keys(event).uniq.map do |key|
|
61
64
|
was = @first_seen[key]
|
62
65
|
@first_seen[key] ||= now
|
63
66
|
was.nil? || current_batch.size > max_batch || now > (was + max_staleness)
|
@@ -85,15 +88,22 @@ module Sqreen
|
|
85
88
|
res += event.observed.fetch(:sdk, []).select { |e|
|
86
89
|
e[0] == :track
|
87
90
|
}.map { |e| "sdk-track".freeze }
|
91
|
+
res += event.observed.fetch(:signals, []).map { "signal".freeze }
|
88
92
|
return res
|
89
93
|
end
|
90
94
|
|
91
95
|
def event_key(event)
|
92
96
|
case event
|
93
97
|
when Sqreen::Attack
|
94
|
-
"att-#{event.
|
98
|
+
"att-#{event.rule_name}"
|
95
99
|
when Sqreen::RemoteException
|
96
100
|
"rex-#{event.klass}"
|
101
|
+
when Sqreen::AggregatedMetric
|
102
|
+
"agg-metric"
|
103
|
+
when Sqreen::Kit::Signals::Signal
|
104
|
+
"signal"
|
105
|
+
when Sqreen::Kit::Signals::Trace
|
106
|
+
"signal"
|
97
107
|
end
|
98
108
|
end
|
99
109
|
end
|
@@ -7,6 +7,7 @@
|
|
7
7
|
# TODO: Sqreen::RemoteException => sqreen/events
|
8
8
|
# TODO: Sqreen::RequestRecord => sqreen/events
|
9
9
|
|
10
|
+
require 'sqreen/log/loggable'
|
10
11
|
require 'sqreen/events/attack'
|
11
12
|
require 'sqreen/events/remote_exception'
|
12
13
|
require 'sqreen/events/request_record'
|
@@ -15,6 +16,7 @@ module Sqreen
|
|
15
16
|
module Deliveries
|
16
17
|
# Simple delivery method that directly call session on event
|
17
18
|
class Simple
|
19
|
+
include Log::Loggable
|
18
20
|
attr_accessor :session
|
19
21
|
|
20
22
|
def initialize(session)
|
@@ -29,6 +31,8 @@ module Sqreen
|
|
29
31
|
session.post_sqreen_exception(event)
|
30
32
|
when Sqreen::RequestRecord
|
31
33
|
session.post_request_record(event)
|
34
|
+
when Sqreen::AggregatedMetric
|
35
|
+
logger.warn 'Delivery of metrics using signals is not supported with simple delivery'
|
32
36
|
else
|
33
37
|
session.post_event(event)
|
34
38
|
end
|
@@ -0,0 +1,96 @@
|
|
1
|
+
require 'securerandom'
|
2
|
+
require 'sqreen/ecosystem/module_registry'
|
3
|
+
require 'sqreen/ecosystem/tracing/sampling_configuration'
|
4
|
+
require 'sqreen/ecosystem/transaction_storage'
|
5
|
+
require 'sqreen/ecosystem/tracing_broker'
|
6
|
+
require 'sqreen/ecosystem/tracing_id_setup'
|
7
|
+
require 'sqreen/ecosystem/module_api/message_producer'
|
8
|
+
require 'sqreen/ecosystem/module_api/tracing_id_generation'
|
9
|
+
require 'sqreen/ecosystem/module_api/tracing'
|
10
|
+
|
11
|
+
module Sqreen
|
12
|
+
# The API for the ecosystem client (together with the dispatch table)
|
13
|
+
module Ecosystem
|
14
|
+
class << self
|
15
|
+
def init(opts = {})
|
16
|
+
@registry = ModuleRegistry.new
|
17
|
+
register_modules(opts[:modules])
|
18
|
+
@registry.init_all
|
19
|
+
|
20
|
+
# setup tracing generation
|
21
|
+
tracing_id_mods = @registry.module_subset(ModuleApi::TracingIdGeneration)
|
22
|
+
@tracing_id_setup = TracingIdSetup.new(tracing_id_mods)
|
23
|
+
@tracing_id_setup.setup_modules
|
24
|
+
|
25
|
+
# configure tracing broker with the consumers (tracing modules)
|
26
|
+
tracing_modules = @registry.module_subset(ModuleApi::Tracing)
|
27
|
+
@tracing_broker = TracingBroker.new(tracing_modules)
|
28
|
+
|
29
|
+
# inject tracing broker in message producers
|
30
|
+
@registry.each_module(ModuleApi::MessageProducer) do |mod|
|
31
|
+
mod.tracing_broker = @tracing_broker
|
32
|
+
end
|
33
|
+
rescue ::Exception # rubocop:disable Lint/RescueException
|
34
|
+
# TODO: modules must be disabled at this point
|
35
|
+
raise
|
36
|
+
end
|
37
|
+
|
38
|
+
def reset
|
39
|
+
instance_variables.each do |ia|
|
40
|
+
instance_variable_set(ia, nil)
|
41
|
+
end
|
42
|
+
end
|
43
|
+
|
44
|
+
# To be called by the Ecosystem client when a new transaction
|
45
|
+
# (generally: request) is started
|
46
|
+
# In the future, it's intended that request end/start detection be handled
|
47
|
+
# by the Ecosystem itself, so control will flow in the other direction,
|
48
|
+
# from the ecosystem to its client
|
49
|
+
def start_transaction
|
50
|
+
TransactionStorage.create_thread_local
|
51
|
+
end
|
52
|
+
|
53
|
+
def end_transaction
|
54
|
+
TransactionStorage.destroy_thread_local
|
55
|
+
end
|
56
|
+
|
57
|
+
# @param [String] tracing_id_prefix
|
58
|
+
# @param [Array<Hash{String=>Object}>] sampling_config
|
59
|
+
def configure_sampling(tracing_id_prefix, sampling_config)
|
60
|
+
@tracing_id_setup.tracing_id_prefix = tracing_id_prefix
|
61
|
+
built_samp_cfg = Tracing::SamplingConfiguration.new(sampling_config)
|
62
|
+
@tracing_broker.sampling_configuration = built_samp_cfg
|
63
|
+
end
|
64
|
+
|
65
|
+
private
|
66
|
+
|
67
|
+
def register_modules(modules)
|
68
|
+
return register_all_modules unless modules
|
69
|
+
|
70
|
+
modules.each { |mod| register mod }
|
71
|
+
end
|
72
|
+
|
73
|
+
def register_all_modules
|
74
|
+
# replace with something more magical?
|
75
|
+
require_relative 'ecosystem/http/rack_request'
|
76
|
+
register Http::RackRequest.new
|
77
|
+
|
78
|
+
require_relative 'ecosystem/http/net_http'
|
79
|
+
register Http::NetHttp.new
|
80
|
+
|
81
|
+
require_relative 'ecosystem/redis/redis_connection'
|
82
|
+
register Redis::RedisConnection.new
|
83
|
+
|
84
|
+
require_relative 'ecosystem/tracing/modules/client'
|
85
|
+
register Tracing::Modules::Client.new
|
86
|
+
|
87
|
+
require_relative 'ecosystem/tracing/modules/server'
|
88
|
+
register Tracing::Modules::Server.new
|
89
|
+
end
|
90
|
+
|
91
|
+
def register(mod)
|
92
|
+
@registry.register mod
|
93
|
+
end
|
94
|
+
end
|
95
|
+
end
|
96
|
+
end
|
@@ -0,0 +1,43 @@
|
|
1
|
+
require 'logger'
|
2
|
+
|
3
|
+
module Sqreen
|
4
|
+
module Ecosystem
|
5
|
+
# Configured by the ecosystem client
|
6
|
+
module DispatchTable
|
7
|
+
class << self
|
8
|
+
# data consumption
|
9
|
+
# argument: +Sqreen::Kit::Signals::Signal+
|
10
|
+
# see +Sqreen::EcosystemIntegration::SignalConsumption#consume_signal+
|
11
|
+
attr_accessor :consume_signal
|
12
|
+
|
13
|
+
# argument: block taking a Rack::Request
|
14
|
+
# see +Sqreen::EcosystemIntegration::RequestLifecycleTracking#add_start_observer+
|
15
|
+
attr_accessor :add_request_start_listener
|
16
|
+
|
17
|
+
attr_accessor :fetch_logger
|
18
|
+
|
19
|
+
# argument: callback taking:
|
20
|
+
# * the method to instrument
|
21
|
+
# * A Hash{Symbol=>Proc} with the advice. The proc takes the
|
22
|
+
# arguments and the ball, so these details of the instrumentation
|
23
|
+
# implementation leak through the abstraction
|
24
|
+
# see +Sqreen::EcosystemIntegration::InstrumentationService+
|
25
|
+
attr_accessor :instrument
|
26
|
+
|
27
|
+
def reset
|
28
|
+
instance_variables.each do |ia|
|
29
|
+
instance_variable_set(ia, nil)
|
30
|
+
end
|
31
|
+
|
32
|
+
# set default logger
|
33
|
+
logger = ::Logger.new(STDERR)
|
34
|
+
logger.level = ::Logger::WARN
|
35
|
+
logger.progname = 'sqreen-ecosystem'
|
36
|
+
self.fetch_logger = proc { logger }
|
37
|
+
end
|
38
|
+
end
|
39
|
+
|
40
|
+
reset
|
41
|
+
end
|
42
|
+
end
|
43
|
+
end
|
@@ -0,0 +1,26 @@
|
|
1
|
+
require 'sqreen/ecosystem/dispatch_table'
|
2
|
+
require 'sqreen/ecosystem/loggable'
|
3
|
+
require 'sqreen/kit/signals/specialized/sqreen_exception'
|
4
|
+
|
5
|
+
module Sqreen
|
6
|
+
module Ecosystem
|
7
|
+
module ExceptionReporting
|
8
|
+
include Loggable
|
9
|
+
|
10
|
+
private
|
11
|
+
|
12
|
+
# @param [String] message
|
13
|
+
# @param [Exception] e
|
14
|
+
def report_exception(message, e)
|
15
|
+
logger.warn { "#{message}: #{e.message}" }
|
16
|
+
logger.debug { e.backtrace.map { |x| " #{x}" }.join("\n") }
|
17
|
+
|
18
|
+
signal = Sqreen::Kit::Signals::Specialized::SqreenException.new(
|
19
|
+
ruby_exception: e
|
20
|
+
)
|
21
|
+
|
22
|
+
DispatchTable.consume_signal signal
|
23
|
+
end
|
24
|
+
end
|
25
|
+
end
|
26
|
+
end
|
@@ -0,0 +1,50 @@
|
|
1
|
+
require 'sqreen/ecosystem/module_api'
|
2
|
+
require 'sqreen/ecosystem/module_api/instrumentation'
|
3
|
+
require 'sqreen/ecosystem/module_api/message_producer'
|
4
|
+
require 'sqreen/ecosystem/module_api/tracing_id_generation'
|
5
|
+
require 'sqreen/ecosystem/module_api/tracing/client_data'
|
6
|
+
|
7
|
+
module Sqreen
|
8
|
+
module Ecosystem
|
9
|
+
module Http
|
10
|
+
class NetHttp
|
11
|
+
class HttpConnectionData
|
12
|
+
include ModuleApi::Tracing::ClientData
|
13
|
+
end
|
14
|
+
|
15
|
+
include ModuleApi::Instrumentation
|
16
|
+
include ModuleApi::MessageProducer
|
17
|
+
include ModuleApi::TracingIdGeneration
|
18
|
+
|
19
|
+
def setup
|
20
|
+
advice = wrap_for_interest(HttpConnectionData, &method(:before_advice))
|
21
|
+
instrument 'Net::HTTP#request', before: advice
|
22
|
+
end
|
23
|
+
|
24
|
+
private
|
25
|
+
|
26
|
+
# instr. def request(req, body = nil, &block) # :yield: +response+
|
27
|
+
# req is of type +Net::HTTPGenericRequest+
|
28
|
+
def before_advice(call, _ball)
|
29
|
+
tracing_id = create_tracing_id
|
30
|
+
|
31
|
+
# build & submit signal
|
32
|
+
host = call.instance.address
|
33
|
+
port = call.instance.port
|
34
|
+
|
35
|
+
# add tracing header
|
36
|
+
req = call.args[0]
|
37
|
+
req[ModuleApi::TRACE_ID_HEADER] = tracing_id
|
38
|
+
|
39
|
+
host += ':' + port.to_s if port != 80 && port != 443
|
40
|
+
|
41
|
+
HttpConnectionData.new(
|
42
|
+
transport: 'http',
|
43
|
+
host: host,
|
44
|
+
tracing_identifier: tracing_id
|
45
|
+
)
|
46
|
+
end
|
47
|
+
end
|
48
|
+
end
|
49
|
+
end
|
50
|
+
end
|
@@ -0,0 +1,39 @@
|
|
1
|
+
require 'sqreen/ecosystem/module_api'
|
2
|
+
require 'sqreen/ecosystem/module_api/event_listener'
|
3
|
+
require 'sqreen/ecosystem/module_api/message_producer'
|
4
|
+
require 'sqreen/ecosystem/module_api/tracing/server_data'
|
5
|
+
|
6
|
+
module Sqreen
|
7
|
+
module Ecosystem
|
8
|
+
module Http
|
9
|
+
class RackRequest
|
10
|
+
class HttpServerData
|
11
|
+
include ModuleApi::Tracing::ServerData
|
12
|
+
end
|
13
|
+
|
14
|
+
include ModuleApi::EventListener
|
15
|
+
include ModuleApi::MessageProducer
|
16
|
+
|
17
|
+
def setup
|
18
|
+
advice = wrap_for_interest(
|
19
|
+
ModuleApi::Tracing::ServerData,
|
20
|
+
&method(:handle_request)
|
21
|
+
)
|
22
|
+
on_request_start(&advice)
|
23
|
+
end
|
24
|
+
|
25
|
+
private
|
26
|
+
|
27
|
+
def handle_request(rack_request)
|
28
|
+
trace_id = rack_request.env[ModuleApi::TRACE_ID_ENV_KEY]
|
29
|
+
|
30
|
+
HttpServerData.new(
|
31
|
+
transport: 'http',
|
32
|
+
client_ip: rack_request.ip,
|
33
|
+
tracing_identifier: trace_id
|
34
|
+
)
|
35
|
+
end
|
36
|
+
end
|
37
|
+
end
|
38
|
+
end
|
39
|
+
end
|