minato-trace 0.1.6.pre.1
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +7 -0
- data/MIT-LICENSE +20 -0
- data/README.md +41 -0
- data/Rakefile +5 -0
- data/lib/minato/trace/middleware/distributed_trace_context.rb +38 -0
- data/lib/minato/trace/middleware.rb +10 -0
- data/lib/minato/trace/railtie.rb +12 -0
- data/lib/minato/trace/version.rb +7 -0
- data/lib/minato/trace.rb +20 -0
- data/lib/tasks/minato/trace_tasks.rake +5 -0
- metadata +84 -0
checksums.yaml
ADDED
@@ -0,0 +1,7 @@
|
|
1
|
+
---
|
2
|
+
SHA256:
|
3
|
+
metadata.gz: c5da6d0d800d5e45a03a0f95ae3419aa3aa25a4084429f47066533149981aa96
|
4
|
+
data.tar.gz: 802469a563d427bed67e8d099d6215b2952d731ced4a4f735ec56a36dee3a12b
|
5
|
+
SHA512:
|
6
|
+
metadata.gz: 85ebba3c8575ec517768aadce56dce393031f6defb30ef3e7b282ad5529e0c20bf3acc6e44441e329229149a95ab965708f427e5f351aab739d25de48d014669
|
7
|
+
data.tar.gz: eac532b05dc3c7f86e53b6dc4c7f81d1cb23c80537a26b42a2ba8c0b93d0cb6d3cc3fb662d5f16b824b6d593b3f8dfddb0c55c9f3959c0b655e55ef40fb6c7b0
|
data/MIT-LICENSE
ADDED
@@ -0,0 +1,20 @@
|
|
1
|
+
Copyright 2024 TODO: Write your name
|
2
|
+
|
3
|
+
Permission is hereby granted, free of charge, to any person obtaining
|
4
|
+
a copy of this software and associated documentation files (the
|
5
|
+
"Software"), to deal in the Software without restriction, including
|
6
|
+
without limitation the rights to use, copy, modify, merge, publish,
|
7
|
+
distribute, sublicense, and/or sell copies of the Software, and to
|
8
|
+
permit persons to whom the Software is furnished to do so, subject to
|
9
|
+
the following conditions:
|
10
|
+
|
11
|
+
The above copyright notice and this permission notice shall be
|
12
|
+
included in all copies or substantial portions of the Software.
|
13
|
+
|
14
|
+
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
|
15
|
+
EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
|
16
|
+
MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
|
17
|
+
NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
|
18
|
+
LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
|
19
|
+
OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
|
20
|
+
WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
|
data/README.md
ADDED
@@ -0,0 +1,41 @@
|
|
1
|
+
# Minato::Trace
|
2
|
+
Add support to [Google Cloud Trace](https://cloud.google.com/trace) to your Minato Rails Application.
|
3
|
+
|
4
|
+
## Usage
|
5
|
+
Install this gem and your application will be abble to send trace information to Google Cloud Trace for any request. To configure distributed trace with other microservices see [Configuring distributed trace](#configuring-distributed-trace)
|
6
|
+
|
7
|
+
## Integration with Google Cloud Logging
|
8
|
+
For integration with [Google Cloud Logging](https://cloud.google.com/logging?hl=en) you have to install [minato-logger-rails](https://gitlab.com/ferreri/minato/minato-logger-rails) v0.1.12+.
|
9
|
+
|
10
|
+
## Installation
|
11
|
+
Add this line to your application's Gemfile:
|
12
|
+
|
13
|
+
```ruby
|
14
|
+
gem "minato-trace"
|
15
|
+
```
|
16
|
+
|
17
|
+
And then execute:
|
18
|
+
```bash
|
19
|
+
$ bundle
|
20
|
+
```
|
21
|
+
|
22
|
+
Or install it yourself as:
|
23
|
+
```bash
|
24
|
+
$ gem install minato-trace
|
25
|
+
```
|
26
|
+
## Configuring distributed trace
|
27
|
+
To configure distributed trace with others services, put this config into the service config file:
|
28
|
+
|
29
|
+
Add to service SDK initializer config file:
|
30
|
+
config/initializers/{service_name}.rb
|
31
|
+
```ruby
|
32
|
+
{ServiceClass}.configure do |config|
|
33
|
+
config.use Minato::Trace::Middleware::DistributedTraceContext
|
34
|
+
end
|
35
|
+
```
|
36
|
+
|
37
|
+
## Changelog
|
38
|
+
Changelog information could be found [here](CHANGELOG.md).
|
39
|
+
|
40
|
+
## License
|
41
|
+
The gem is available as open source under the terms of the [MIT License](https://opensource.org/licenses/MIT).
|
data/Rakefile
ADDED
@@ -0,0 +1,38 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
3
|
+
module Minato
|
4
|
+
module Trace
|
5
|
+
module Middleware
|
6
|
+
class DistributedTraceContext
|
7
|
+
TRACE_HEADER_KEY = "X-Cloud-Trace-Context"
|
8
|
+
|
9
|
+
def initialize(app)
|
10
|
+
@app = app
|
11
|
+
end
|
12
|
+
|
13
|
+
def call(env)
|
14
|
+
add_trace_context_header(env)
|
15
|
+
|
16
|
+
@app.call(env)
|
17
|
+
end
|
18
|
+
|
19
|
+
private
|
20
|
+
|
21
|
+
def add_trace_context_header(env)
|
22
|
+
return unless Rails.env.production?
|
23
|
+
|
24
|
+
env.request_headers.merge!({ "#{TRACE_HEADER_KEY}": "#{current_cloud_trace.trace.trace_id};o=1" })
|
25
|
+
end
|
26
|
+
|
27
|
+
def current_cloud_trace
|
28
|
+
@current_cloud_trace ||= current_trace_from_google_cloud
|
29
|
+
end
|
30
|
+
|
31
|
+
def current_trace_from_google_cloud
|
32
|
+
_trace_client = Google::Cloud::Trace.new
|
33
|
+
Google::Cloud::Trace.get
|
34
|
+
end
|
35
|
+
end
|
36
|
+
end
|
37
|
+
end
|
38
|
+
end
|
data/lib/minato/trace.rb
ADDED
@@ -0,0 +1,20 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
3
|
+
require "minato/trace/version"
|
4
|
+
require "minato/trace/railtie"
|
5
|
+
require "minato/trace/middleware"
|
6
|
+
require "stackdriver"
|
7
|
+
|
8
|
+
module Minato
|
9
|
+
module Trace
|
10
|
+
BLACKLIST_PATHS = ["/health/alive", "/health/ready"].freeze
|
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)
|
17
|
+
end
|
18
|
+
end
|
19
|
+
end
|
20
|
+
end
|
metadata
ADDED
@@ -0,0 +1,84 @@
|
|
1
|
+
--- !ruby/object:Gem::Specification
|
2
|
+
name: minato-trace
|
3
|
+
version: !ruby/object:Gem::Version
|
4
|
+
version: 0.1.6.pre.1
|
5
|
+
platform: ruby
|
6
|
+
authors:
|
7
|
+
- Ferreri
|
8
|
+
autorequire:
|
9
|
+
bindir: bin
|
10
|
+
cert_chain: []
|
11
|
+
date: 2024-02-05 00:00:00.000000000 Z
|
12
|
+
dependencies:
|
13
|
+
- !ruby/object:Gem::Dependency
|
14
|
+
name: rails
|
15
|
+
requirement: !ruby/object:Gem::Requirement
|
16
|
+
requirements:
|
17
|
+
- - ">="
|
18
|
+
- !ruby/object:Gem::Version
|
19
|
+
version: 7.0.0
|
20
|
+
type: :runtime
|
21
|
+
prerelease: false
|
22
|
+
version_requirements: !ruby/object:Gem::Requirement
|
23
|
+
requirements:
|
24
|
+
- - ">="
|
25
|
+
- !ruby/object:Gem::Version
|
26
|
+
version: 7.0.0
|
27
|
+
- !ruby/object:Gem::Dependency
|
28
|
+
name: stackdriver
|
29
|
+
requirement: !ruby/object:Gem::Requirement
|
30
|
+
requirements:
|
31
|
+
- - "~>"
|
32
|
+
- !ruby/object:Gem::Version
|
33
|
+
version: 0.21.1
|
34
|
+
type: :runtime
|
35
|
+
prerelease: false
|
36
|
+
version_requirements: !ruby/object:Gem::Requirement
|
37
|
+
requirements:
|
38
|
+
- - "~>"
|
39
|
+
- !ruby/object:Gem::Version
|
40
|
+
version: 0.21.1
|
41
|
+
description: Default setup of trace gem in Minato Rails Apps.
|
42
|
+
email:
|
43
|
+
- contato@ferreri.co
|
44
|
+
executables: []
|
45
|
+
extensions: []
|
46
|
+
extra_rdoc_files: []
|
47
|
+
files:
|
48
|
+
- MIT-LICENSE
|
49
|
+
- README.md
|
50
|
+
- Rakefile
|
51
|
+
- lib/minato/trace.rb
|
52
|
+
- lib/minato/trace/middleware.rb
|
53
|
+
- lib/minato/trace/middleware/distributed_trace_context.rb
|
54
|
+
- lib/minato/trace/railtie.rb
|
55
|
+
- lib/minato/trace/version.rb
|
56
|
+
- lib/tasks/minato/trace_tasks.rake
|
57
|
+
homepage: https://gitlab.com/ferreri/minato/minato-trace
|
58
|
+
licenses:
|
59
|
+
- MIT
|
60
|
+
metadata:
|
61
|
+
homepage_uri: https://gitlab.com/ferreri/minato/minato-trace
|
62
|
+
source_code_uri: https://gitlab.com/ferreri/minato/minato-trace
|
63
|
+
changelog_uri: https://gitlab.com/ferreri/minato/minato-trace/-/blob/main/CHANGELOG.md?ref_type=heads
|
64
|
+
rubygems_mfa_required: 'true'
|
65
|
+
post_install_message:
|
66
|
+
rdoc_options: []
|
67
|
+
require_paths:
|
68
|
+
- lib
|
69
|
+
required_ruby_version: !ruby/object:Gem::Requirement
|
70
|
+
requirements:
|
71
|
+
- - ">="
|
72
|
+
- !ruby/object:Gem::Version
|
73
|
+
version: 2.6.0
|
74
|
+
required_rubygems_version: !ruby/object:Gem::Requirement
|
75
|
+
requirements:
|
76
|
+
- - ">"
|
77
|
+
- !ruby/object:Gem::Version
|
78
|
+
version: 1.3.1
|
79
|
+
requirements: []
|
80
|
+
rubygems_version: 3.4.1
|
81
|
+
signing_key:
|
82
|
+
specification_version: 4
|
83
|
+
summary: trace configuration for Minato Rails Apps.
|
84
|
+
test_files: []
|