minato-trace 0.1.6.pre.2 → 0.1.6.pre.4
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/README.md +2 -0
- data/lib/minato/trace/middleware/distributed_trace_context.rb +1 -1
- data/lib/minato/trace/middleware/integrate_with_cloud_logging.rb +33 -0
- data/lib/minato/trace/middleware.rb +1 -0
- data/lib/minato/trace/railtie.rb +2 -2
- data/lib/minato/trace/version.rb +1 -1
- data/lib/minato/trace.rb +24 -5
- metadata +3 -2
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA256:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 617a746f57e557883faa90fc72e8c3a078483585df6f97f4cebb64130daf68f4
|
4
|
+
data.tar.gz: 396d2536e8209f0481bf305431a8b2f8a06952e863e7fd8a9a95df41c4855719
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: e06b1e3043379e75f268dc69f35a70acf07f66f7160bf241a0959c6bd8ce11cb400581d7f1b274f3f85acba02ad91e1194ec37fa552e6389166a4995a46d8e84
|
7
|
+
data.tar.gz: 614be0218c0805fcb7e01ff2097fa54f30d83317fe7dc5f9afc81dd95cc9bcea5eaf5dc912a52d6a5d46c75f7719765981a6d315cceec30cc10758854f7b83cb
|
data/README.md
CHANGED
@@ -33,6 +33,8 @@ config/initializers/{service_name}.rb
|
|
33
33
|
config.use Minato::Trace::Middleware::DistributedTraceContext
|
34
34
|
end
|
35
35
|
```
|
36
|
+
## Disable trace
|
37
|
+
Trace is enabled by default. If you want to disable trace, set an environment variable `MINATO_TRACE_DISABLE=true` in your app.
|
36
38
|
|
37
39
|
## Changelog
|
38
40
|
Changelog information could be found [here](CHANGELOG.md).
|
@@ -19,7 +19,7 @@ module Minato
|
|
19
19
|
private
|
20
20
|
|
21
21
|
def add_trace_context_header(env)
|
22
|
-
return unless Rails.env.production?
|
22
|
+
return unless Rails.env.production? && Minato::Trace.enabled?
|
23
23
|
|
24
24
|
env.request_headers.merge!({ "#{TRACE_HEADER_KEY}": "#{current_cloud_trace.trace.trace_id};o=1" })
|
25
25
|
end
|
@@ -0,0 +1,33 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
3
|
+
module Minato
|
4
|
+
module Trace
|
5
|
+
module Middleware
|
6
|
+
class IntegrateWithCloudLogging
|
7
|
+
def call(log)
|
8
|
+
return log unless ::Rails.env.production? && Minato::Trace.enabled?
|
9
|
+
|
10
|
+
add_trace_to_logs(log)
|
11
|
+
end
|
12
|
+
|
13
|
+
private
|
14
|
+
|
15
|
+
def add_trace_to_logs(log)
|
16
|
+
trace_log = "projects/#{current_cloud_trace.trace.project_id}/traces/#{current_cloud_trace.trace.trace_id}"
|
17
|
+
|
18
|
+
log.merge({ "logging.googleapis.com/trace": trace_log,
|
19
|
+
"logging.googleapis.com/spanId": current_cloud_trace.span_id.to_s })
|
20
|
+
end
|
21
|
+
|
22
|
+
def current_cloud_trace
|
23
|
+
@current_cloud_trace ||= current_trace_from_google_cloud
|
24
|
+
end
|
25
|
+
|
26
|
+
def current_trace_from_google_cloud
|
27
|
+
_trace_client = Google::Cloud::Trace.new
|
28
|
+
Google::Cloud::Trace.get
|
29
|
+
end
|
30
|
+
end
|
31
|
+
end
|
32
|
+
end
|
33
|
+
end
|
data/lib/minato/trace/railtie.rb
CHANGED
data/lib/minato/trace/version.rb
CHANGED
data/lib/minato/trace.rb
CHANGED
@@ -9,11 +9,30 @@ module Minato
|
|
9
9
|
module Trace
|
10
10
|
BLACKLIST_PATHS = ["/health/alive", "/health/ready"].freeze
|
11
11
|
|
12
|
-
def self.init
|
13
|
-
|
14
|
-
|
15
|
-
|
16
|
-
|
12
|
+
def self.init(app)
|
13
|
+
if Minato::Trace.enabled?
|
14
|
+
Minato::Trace.configure_loggging(app)
|
15
|
+
Minato::Trace.configure_trace(app)
|
16
|
+
end
|
17
|
+
|
18
|
+
app
|
19
|
+
end
|
20
|
+
|
21
|
+
def self.enabled?
|
22
|
+
ENV["MINATO_TRACE_DISABLED"] != "true"
|
23
|
+
end
|
24
|
+
|
25
|
+
def self.configure_trace(app)
|
26
|
+
app.configure do
|
27
|
+
config.google_cloud.use_trace = true
|
28
|
+
config.google_cloud.trace.sampler = Google::Cloud::Trace::TimeSampler.new(path_blacklist: BLACKLIST_PATHS.dup)
|
29
|
+
config.minato_logger.trace_logs = Minato::Trace::Middleware::IntegrateWithCloudLogging.new
|
30
|
+
end
|
31
|
+
end
|
32
|
+
|
33
|
+
def self.configure_loggging(app)
|
34
|
+
app.configure do
|
35
|
+
config.google_cloud.use_logging = false
|
17
36
|
end
|
18
37
|
end
|
19
38
|
end
|
metadata
CHANGED
@@ -1,14 +1,14 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: minato-trace
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.1.6.pre.
|
4
|
+
version: 0.1.6.pre.4
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Ferreri
|
8
8
|
autorequire:
|
9
9
|
bindir: bin
|
10
10
|
cert_chain: []
|
11
|
-
date: 2024-02-
|
11
|
+
date: 2024-02-14 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: google-cloud-trace
|
@@ -51,6 +51,7 @@ files:
|
|
51
51
|
- lib/minato/trace.rb
|
52
52
|
- lib/minato/trace/middleware.rb
|
53
53
|
- lib/minato/trace/middleware/distributed_trace_context.rb
|
54
|
+
- lib/minato/trace/middleware/integrate_with_cloud_logging.rb
|
54
55
|
- lib/minato/trace/railtie.rb
|
55
56
|
- lib/minato/trace/version.rb
|
56
57
|
- lib/tasks/minato/trace_tasks.rake
|