minato-trace 0.1.6.pre.2 → 0.1.6.pre.3
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: 67494dc73f9479f8f0960880825e85f916cbb9497c47b573a6a93b5929cec8a5
|
4
|
+
data.tar.gz: 157a7f9a964934f6545dafdc1cd3b8e93e11970222621b81e846fe40b5305d3d
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: da50ee9d96d081f2e61f66fe0afac5d32b27ceb7d40e5255db5bfa6c9e8d083367c6a357f9b2659fbeca2d3204929baa81f4acb740695cebf7cf95324d9c3a2d
|
7
|
+
data.tar.gz: '018586efc6c8f5a8a6488d25e67914bd23ffc53ff248a031d4a45a7ad05bc79e94c83994c49b5096f0cd368d59513d83a4dbf712cfbaf1598df2ea6776a92067'
|
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::Trance.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.3
|
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
|