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 CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA256:
3
- metadata.gz: 8f684163e7a5fa25682ee75132b4fed0f45893f6c30c9d0676562841e0046af5
4
- data.tar.gz: 01b19897590f665373abbc108c35f002f45bf91a8a4c08407c742176881face1
3
+ metadata.gz: 617a746f57e557883faa90fc72e8c3a078483585df6f97f4cebb64130daf68f4
4
+ data.tar.gz: 396d2536e8209f0481bf305431a8b2f8a06952e863e7fd8a9a95df41c4855719
5
5
  SHA512:
6
- metadata.gz: 7f8b0515d2442eb9c44a8d06f46e6f5cf728f41a3a682cb760d537275a4ffeb2a776167cffe6cf1417fee713a726f2b6f9bfb6a8ab9460a1fc61ba4668a401cb
7
- data.tar.gz: 4c6baec516cfdf7a7e44d03f8d58b22cf0d9689962c42a525fcc9025813bba34408e722813e092a17f798c35b0d1d664197dca3c08eccc7e6a54f3d61c83808a
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
@@ -1,6 +1,7 @@
1
1
  # frozen_string_literal: true
2
2
 
3
3
  require "minato/trace/middleware/distributed_trace_context"
4
+ require "minato/trace/middleware/integrate_with_cloud_logging"
4
5
 
5
6
  module Minato
6
7
  module Trace
@@ -4,8 +4,8 @@ module Minato
4
4
  module Trace
5
5
  class Railtie < ::Rails::Railtie
6
6
  initializer "minato_trace_setup",
7
- before: "load_environment_config" do
8
- Minato::Trace.init
7
+ before: "load_environment_config" do |app|
8
+ Minato::Trace.init(app)
9
9
  end
10
10
  end
11
11
  end
@@ -2,6 +2,6 @@
2
2
 
3
3
  module Minato
4
4
  module Trace
5
- VERSION = "0.1.6-2"
5
+ VERSION = "0.1.6-4"
6
6
  end
7
7
  end
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
- Google::Cloud.configure do |config|
14
- config.use_logging = false
15
- config.use_trace = true
16
- config.trace.sampler = Google::Cloud::Trace::TimeSampler.new(path_blacklist: BLACKLIST_PATHS.dup)
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.2
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-06 00:00:00.000000000 Z
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