minato-trace 0.1.6.pre.1 → 0.1.6.pre.3

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: c5da6d0d800d5e45a03a0f95ae3419aa3aa25a4084429f47066533149981aa96
4
- data.tar.gz: 802469a563d427bed67e8d099d6215b2952d731ced4a4f735ec56a36dee3a12b
3
+ metadata.gz: 67494dc73f9479f8f0960880825e85f916cbb9497c47b573a6a93b5929cec8a5
4
+ data.tar.gz: 157a7f9a964934f6545dafdc1cd3b8e93e11970222621b81e846fe40b5305d3d
5
5
  SHA512:
6
- metadata.gz: 85ebba3c8575ec517768aadce56dce393031f6defb30ef3e7b282ad5529e0c20bf3acc6e44441e329229149a95ab965708f427e5f351aab739d25de48d014669
7
- data.tar.gz: eac532b05dc3c7f86e53b6dc4c7f81d1cb23c80537a26b42a2ba8c0b93d0cb6d3cc3fb662d5f16b824b6d593b3f8dfddb0c55c9f3959c0b655e55ef40fb6c7b0
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
@@ -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-1"
5
+ VERSION = "0.1.6-3"
6
6
  end
7
7
  end
data/lib/minato/trace.rb CHANGED
@@ -3,17 +3,36 @@
3
3
  require "minato/trace/version"
4
4
  require "minato/trace/railtie"
5
5
  require "minato/trace/middleware"
6
- require "stackdriver"
6
+ require "google/cloud/trace/rails"
7
7
 
8
8
  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::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,43 +1,43 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: minato-trace
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.1.6.pre.1
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-05 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
- name: rails
14
+ name: google-cloud-trace
15
15
  requirement: !ruby/object:Gem::Requirement
16
16
  requirements:
17
- - - ">="
17
+ - - "~>"
18
18
  - !ruby/object:Gem::Version
19
- version: 7.0.0
19
+ version: 0.42.2
20
20
  type: :runtime
21
21
  prerelease: false
22
22
  version_requirements: !ruby/object:Gem::Requirement
23
23
  requirements:
24
- - - ">="
24
+ - - "~>"
25
25
  - !ruby/object:Gem::Version
26
- version: 7.0.0
26
+ version: 0.42.2
27
27
  - !ruby/object:Gem::Dependency
28
- name: stackdriver
28
+ name: rails
29
29
  requirement: !ruby/object:Gem::Requirement
30
30
  requirements:
31
- - - "~>"
31
+ - - ">="
32
32
  - !ruby/object:Gem::Version
33
- version: 0.21.1
33
+ version: 7.0.0
34
34
  type: :runtime
35
35
  prerelease: false
36
36
  version_requirements: !ruby/object:Gem::Requirement
37
37
  requirements:
38
- - - "~>"
38
+ - - ">="
39
39
  - !ruby/object:Gem::Version
40
- version: 0.21.1
40
+ version: 7.0.0
41
41
  description: Default setup of trace gem in Minato Rails Apps.
42
42
  email:
43
43
  - contato@ferreri.co
@@ -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