trifle-traces 1.0.1
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +7 -0
- data/.github/workflows/ruby.yml +36 -0
- data/.gitignore +12 -0
- data/.gitpod/Dockerfile +1 -0
- data/.gitpod.yml +18 -0
- data/.rspec +3 -0
- data/.rubocop.yml +15 -0
- data/.ruby-version +1 -0
- data/.tool-versions +1 -0
- data/Gemfile +7 -0
- data/Gemfile.lock +59 -0
- data/LICENSE +21 -0
- data/README.md +53 -0
- data/Rakefile +6 -0
- data/bin/console +14 -0
- data/bin/setup +8 -0
- data/lib/trifle/traces/configuration.rb +37 -0
- data/lib/trifle/traces/middleware/rack.rb +26 -0
- data/lib/trifle/traces/middleware/rails_controller.rb +43 -0
- data/lib/trifle/traces/middleware/sidekiq.rb +28 -0
- data/lib/trifle/traces/tracer/hash.rb +131 -0
- data/lib/trifle/traces/tracer/null.rb +29 -0
- data/lib/trifle/traces/version.rb +7 -0
- data/lib/trifle/traces.rb +72 -0
- data/trifle-traces.gemspec +34 -0
- metadata +141 -0
checksums.yaml
ADDED
@@ -0,0 +1,7 @@
|
|
1
|
+
---
|
2
|
+
SHA256:
|
3
|
+
metadata.gz: e70e8771d1d11a1b52b2d7bc059d05f6e6082f876f1e5b28440d914e91acf789
|
4
|
+
data.tar.gz: 4ec2c1d3ed119b40166e7129e35f0ad70f5b9d5dab5a4cc20095f7265f3e2dc3
|
5
|
+
SHA512:
|
6
|
+
metadata.gz: 8b9c3a99caecdf88a6d57d08ad4c0429b443122d5fbee1511978e629040805edb6e76599e366577cbb57734f2af163ed60e0029efc6b6726b66b24ec0ab00cbd
|
7
|
+
data.tar.gz: '02838f426cba718cce2137db2f4ff3de1f2af44a31a73839de9ffe0701199d3fa83563ad98f4ccb73b8b3237776ea5958539d52e85ffe7d76b80b2daadac57cc'
|
@@ -0,0 +1,36 @@
|
|
1
|
+
# This workflow uses actions that are not certified by GitHub.
|
2
|
+
# They are provided by a third-party and are governed by
|
3
|
+
# separate terms of service, privacy policy, and support
|
4
|
+
# documentation.
|
5
|
+
# This workflow will download a prebuilt Ruby version, install dependencies and run tests with Rake
|
6
|
+
# For more information see: https://github.com/marketplace/actions/setup-ruby-jruby-and-truffleruby
|
7
|
+
|
8
|
+
name: Ruby
|
9
|
+
|
10
|
+
on:
|
11
|
+
push:
|
12
|
+
branches: [main]
|
13
|
+
pull_request:
|
14
|
+
branches: [main]
|
15
|
+
|
16
|
+
jobs:
|
17
|
+
test:
|
18
|
+
runs-on: ubuntu-latest
|
19
|
+
strategy:
|
20
|
+
matrix:
|
21
|
+
ruby-version: ["3.0"]
|
22
|
+
|
23
|
+
steps:
|
24
|
+
- uses: actions/checkout@v2
|
25
|
+
- name: Set up Ruby
|
26
|
+
# To automatically get bug fixes and new Ruby versions for ruby/setup-ruby,
|
27
|
+
# change this to (see https://github.com/ruby/setup-ruby#versioning):
|
28
|
+
# uses: ruby/setup-ruby@v1
|
29
|
+
uses: ruby/setup-ruby@473e4d8fe5dd94ee328fdfca9f8c9c7afc9dae5e
|
30
|
+
with:
|
31
|
+
ruby-version: ${{ matrix.ruby-version }}
|
32
|
+
bundler-cache: true # runs 'bundle install' and caches installed gems automatically
|
33
|
+
- name: Rspec
|
34
|
+
run: bundle exec rspec
|
35
|
+
- name: Rubocop
|
36
|
+
run: bundle exec rubocop
|
data/.gitignore
ADDED
data/.gitpod/Dockerfile
ADDED
@@ -0,0 +1 @@
|
|
1
|
+
FROM trifle/gitpod:0.1.0
|
data/.gitpod.yml
ADDED
@@ -0,0 +1,18 @@
|
|
1
|
+
image:
|
2
|
+
file: .gitpod/Dockerfile
|
3
|
+
tasks:
|
4
|
+
- init: bundle install
|
5
|
+
command: ./bin/console
|
6
|
+
- command: redis-server
|
7
|
+
github:
|
8
|
+
prebuilds:
|
9
|
+
# enable for the master/default branch (defaults to true)
|
10
|
+
master: true
|
11
|
+
# enable for all branches in this repo (defaults to false)
|
12
|
+
branches: false
|
13
|
+
# enable for pull requests coming from this repo (defaults to true)
|
14
|
+
pullRequests: true
|
15
|
+
# add a check to pull requests (defaults to true)
|
16
|
+
addCheck: true
|
17
|
+
# add a "Review in Gitpod" button as a comment to pull requests (defaults to false)
|
18
|
+
addComment: false
|
data/.rspec
ADDED
data/.rubocop.yml
ADDED
data/.ruby-version
ADDED
@@ -0,0 +1 @@
|
|
1
|
+
ruby-3.1.0
|
data/.tool-versions
ADDED
@@ -0,0 +1 @@
|
|
1
|
+
ruby 3.1.0
|
data/Gemfile
ADDED
data/Gemfile.lock
ADDED
@@ -0,0 +1,59 @@
|
|
1
|
+
PATH
|
2
|
+
remote: .
|
3
|
+
specs:
|
4
|
+
trifle-traces (1.0.1)
|
5
|
+
|
6
|
+
GEM
|
7
|
+
remote: https://rubygems.org/
|
8
|
+
specs:
|
9
|
+
ast (2.4.2)
|
10
|
+
byebug (11.1.3)
|
11
|
+
diff-lcs (1.4.4)
|
12
|
+
parallel (1.20.1)
|
13
|
+
parser (3.0.0.0)
|
14
|
+
ast (~> 2.4.1)
|
15
|
+
rainbow (3.0.0)
|
16
|
+
rake (12.3.3)
|
17
|
+
regexp_parser (2.0.3)
|
18
|
+
rexml (3.2.4)
|
19
|
+
rspec (3.10.0)
|
20
|
+
rspec-core (~> 3.10.0)
|
21
|
+
rspec-expectations (~> 3.10.0)
|
22
|
+
rspec-mocks (~> 3.10.0)
|
23
|
+
rspec-core (3.10.1)
|
24
|
+
rspec-support (~> 3.10.0)
|
25
|
+
rspec-expectations (3.10.1)
|
26
|
+
diff-lcs (>= 1.2.0, < 2.0)
|
27
|
+
rspec-support (~> 3.10.0)
|
28
|
+
rspec-mocks (3.10.2)
|
29
|
+
diff-lcs (>= 1.2.0, < 2.0)
|
30
|
+
rspec-support (~> 3.10.0)
|
31
|
+
rspec-support (3.10.2)
|
32
|
+
rubocop (1.0.0)
|
33
|
+
parallel (~> 1.10)
|
34
|
+
parser (>= 2.7.1.5)
|
35
|
+
rainbow (>= 2.2.2, < 4.0)
|
36
|
+
regexp_parser (>= 1.8)
|
37
|
+
rexml
|
38
|
+
rubocop-ast (>= 0.6.0)
|
39
|
+
ruby-progressbar (~> 1.7)
|
40
|
+
unicode-display_width (>= 1.4.0, < 2.0)
|
41
|
+
rubocop-ast (1.4.1)
|
42
|
+
parser (>= 2.7.1.5)
|
43
|
+
ruby-progressbar (1.11.0)
|
44
|
+
unicode-display_width (1.7.0)
|
45
|
+
|
46
|
+
PLATFORMS
|
47
|
+
ruby
|
48
|
+
x86_64-darwin-20
|
49
|
+
|
50
|
+
DEPENDENCIES
|
51
|
+
bundler (~> 2.1)
|
52
|
+
byebug
|
53
|
+
rake (~> 12.0)
|
54
|
+
rspec (~> 3.0)
|
55
|
+
rubocop (= 1.0.0)
|
56
|
+
trifle-traces!
|
57
|
+
|
58
|
+
BUNDLED WITH
|
59
|
+
2.3.5
|
data/LICENSE
ADDED
@@ -0,0 +1,21 @@
|
|
1
|
+
MIT License
|
2
|
+
|
3
|
+
Copyright (c) 2021 Jozef Vaclavik
|
4
|
+
|
5
|
+
Permission is hereby granted, free of charge, to any person obtaining a copy
|
6
|
+
of this software and associated documentation files (the "Software"), to deal
|
7
|
+
in the Software without restriction, including without limitation the rights
|
8
|
+
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
9
|
+
copies of the Software, and to permit persons to whom the Software is
|
10
|
+
furnished to do so, subject to the following conditions:
|
11
|
+
|
12
|
+
The above copyright notice and this permission notice shall be included in all
|
13
|
+
copies or substantial portions of the Software.
|
14
|
+
|
15
|
+
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
16
|
+
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
17
|
+
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
18
|
+
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
19
|
+
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
20
|
+
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
|
21
|
+
SOFTWARE.
|
data/README.md
ADDED
@@ -0,0 +1,53 @@
|
|
1
|
+
# Trifle::Traces
|
2
|
+
|
3
|
+
[](https://badge.fury.io/rb/trifle-traces)
|
4
|
+

|
5
|
+
|
6
|
+
Simple tracer backed by Redis, Postgres, MongoDB, or whatever.
|
7
|
+
|
8
|
+
`Trifle::Traces` is a way too simple timeline tracer that helps you track custom outputs. Ideal for any code from blackbox category (aka background-job-that-talks-to-API-and-works-every-time-when-you-run-it-manually-but-never-when-in-production type of jobs)
|
9
|
+
|
10
|
+
## Documentation
|
11
|
+
|
12
|
+
You can find guides and documentation at https://trifle.io/trifle-traces
|
13
|
+
|
14
|
+
## Installation
|
15
|
+
|
16
|
+
Add this line to your application's Gemfile:
|
17
|
+
|
18
|
+
```ruby
|
19
|
+
gem 'trifle-traces'
|
20
|
+
```
|
21
|
+
|
22
|
+
And then execute:
|
23
|
+
|
24
|
+
$ bundle install
|
25
|
+
|
26
|
+
Or install it yourself as:
|
27
|
+
|
28
|
+
$ gem install trifle-traces
|
29
|
+
|
30
|
+
## Usage
|
31
|
+
|
32
|
+
It saves you from reading through your standard traces
|
33
|
+
|
34
|
+
```ruby
|
35
|
+
Trifle::Traces.trace('This is important output')
|
36
|
+
now = Trifle::Traces.trace('And it\'s important to know it happened at') do
|
37
|
+
Time.now
|
38
|
+
end
|
39
|
+
```
|
40
|
+
|
41
|
+
To being able to say what happened on 25th January 2021.
|
42
|
+
|
43
|
+
```ruby
|
44
|
+
[
|
45
|
+
{at: 2021-01-25 00:00:00 +0100, message: 'This is important output', state: :success, head: false, meta: false}
|
46
|
+
{at: 2021-01-25 00:00:00 +0100, message: 'And it\'s important to know it happened ', state: :success, head: false, meta: false}
|
47
|
+
{at: 2021-01-25 00:00:00 +0100, message: '=> 2021-01-25 00:00:00 +0100', state: :success, head: false, meta: true}
|
48
|
+
]
|
49
|
+
```
|
50
|
+
|
51
|
+
## Contributing
|
52
|
+
|
53
|
+
Bug reports and pull requests are welcome on GitHub at https://github.com/trifle-io/trifle-traces.
|
data/Rakefile
ADDED
data/bin/console
ADDED
@@ -0,0 +1,14 @@
|
|
1
|
+
#!/usr/bin/env ruby
|
2
|
+
|
3
|
+
require "bundler/setup"
|
4
|
+
require "trifle/traces"
|
5
|
+
|
6
|
+
# You can add fixtures and/or initialization code here to make experimenting
|
7
|
+
# with your gem easier. You can also use a different console, if you like.
|
8
|
+
|
9
|
+
# (If you use this, don't forget to add pry to your Gemfile!)
|
10
|
+
# require "pry"
|
11
|
+
# Pry.start
|
12
|
+
|
13
|
+
require "irb"
|
14
|
+
IRB.start(__FILE__)
|
data/bin/setup
ADDED
@@ -0,0 +1,37 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
3
|
+
module Trifle
|
4
|
+
module Traces
|
5
|
+
class Configuration
|
6
|
+
attr_accessor :tracer_class, :callbacks, :bump_every
|
7
|
+
|
8
|
+
def initialize
|
9
|
+
@tracer_class = Trifle::Traces::Tracer::Hash
|
10
|
+
@callbacks = { liftoff: [], bump: [], wrapup: [] }
|
11
|
+
@bump_every = 15.seconds
|
12
|
+
end
|
13
|
+
|
14
|
+
def on_liftoff(tracer)
|
15
|
+
@callbacks.fetch(:liftoff, []).map do |c|
|
16
|
+
c.call(tracer)
|
17
|
+
end
|
18
|
+
end
|
19
|
+
|
20
|
+
def on_bump(tracer)
|
21
|
+
@callbacks.fetch(:bump, []).map do |c|
|
22
|
+
c.call(tracer)
|
23
|
+
end
|
24
|
+
end
|
25
|
+
|
26
|
+
def on_wrapup(tracer)
|
27
|
+
@callbacks.fetch(:wrapup, []).map do |c|
|
28
|
+
c.call(tracer)
|
29
|
+
end
|
30
|
+
end
|
31
|
+
|
32
|
+
def on(event, &block)
|
33
|
+
@callbacks[event] << block
|
34
|
+
end
|
35
|
+
end
|
36
|
+
end
|
37
|
+
end
|
@@ -0,0 +1,26 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
3
|
+
module Trifle
|
4
|
+
module Traces
|
5
|
+
module Middleware
|
6
|
+
class Rack
|
7
|
+
def initialize(app)
|
8
|
+
@app = app
|
9
|
+
end
|
10
|
+
|
11
|
+
def call(env)
|
12
|
+
# TODO: set up key
|
13
|
+
# Trifle::Traces.tracer = Trifle::Traces.default.tracer_class.new
|
14
|
+
@status, @headers, @response = @app.call(env)
|
15
|
+
rescue => e # rubocop:disable Style/RescueStandardError
|
16
|
+
Trifle::Traces.tracer&.trace("Exception: #{e}", state: :error)
|
17
|
+
Trifle::Traces.tracer&.fail!
|
18
|
+
raise e
|
19
|
+
ensure
|
20
|
+
Trifle::Traces.tracer&.wrapup
|
21
|
+
[@status, @headers, @response]
|
22
|
+
end
|
23
|
+
end
|
24
|
+
end
|
25
|
+
end
|
26
|
+
end
|
@@ -0,0 +1,43 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
3
|
+
module Trifle
|
4
|
+
module Traces
|
5
|
+
module Middleware
|
6
|
+
module RailsController
|
7
|
+
def self.included(base)
|
8
|
+
base.extend ClassMethods
|
9
|
+
base.include InstanceMethods
|
10
|
+
end
|
11
|
+
|
12
|
+
module ClassMethods
|
13
|
+
def with_trifle_traces(options = {})
|
14
|
+
around_action :with_trifle_traces, options
|
15
|
+
end
|
16
|
+
end
|
17
|
+
|
18
|
+
module InstanceMethods
|
19
|
+
def with_trifle_traces
|
20
|
+
Trifle::Traces.tracer = Trifle::Traces.default.tracer_class.new(
|
21
|
+
key: trace_key, meta: trace_meta
|
22
|
+
)
|
23
|
+
yield
|
24
|
+
rescue => e # rubocop:disable Style/RescueStandardError
|
25
|
+
Trifle::Traces.tracer.trace("Exception: #{e}", state: :error)
|
26
|
+
Trifle::Traces.tracer.fail!
|
27
|
+
raise e
|
28
|
+
ensure
|
29
|
+
Trifle::Traces.tracer.wrapup
|
30
|
+
end
|
31
|
+
|
32
|
+
def trace_key
|
33
|
+
"#{params[:controller]}/#{params[:action]}"
|
34
|
+
end
|
35
|
+
|
36
|
+
def trace_meta
|
37
|
+
[params[:id]].compact
|
38
|
+
end
|
39
|
+
end
|
40
|
+
end
|
41
|
+
end
|
42
|
+
end
|
43
|
+
end
|
@@ -0,0 +1,28 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
3
|
+
module Trifle
|
4
|
+
module Traces
|
5
|
+
module Middleware
|
6
|
+
class Sidekiq
|
7
|
+
def call(_worker, job, _queue)
|
8
|
+
Trifle::Traces.tracer = tracer_for(job: job)
|
9
|
+
yield
|
10
|
+
rescue => e # rubocop:disable Style/RescueStandardError
|
11
|
+
Trifle::Traces.tracer&.trace("Exception: #{e}", state: :error)
|
12
|
+
Trifle::Traces.tracer&.fail!
|
13
|
+
raise e
|
14
|
+
ensure
|
15
|
+
Trifle::Traces.tracer&.wrapup
|
16
|
+
end
|
17
|
+
|
18
|
+
def tracer_for(job:)
|
19
|
+
return nil unless job['tracer_key']
|
20
|
+
|
21
|
+
Trifle::Traces.default.tracer_class.new(
|
22
|
+
key: job['tracer_key'], meta: job['args']
|
23
|
+
)
|
24
|
+
end
|
25
|
+
end
|
26
|
+
end
|
27
|
+
end
|
28
|
+
end
|
@@ -0,0 +1,131 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
3
|
+
module Trifle
|
4
|
+
module Traces
|
5
|
+
module Tracer
|
6
|
+
class Hash
|
7
|
+
attr_accessor :key, :meta, :data, :tags, :artifacts, :state, :ignore, :reference
|
8
|
+
|
9
|
+
def initialize(key:, reference: nil, meta: nil, config: nil)
|
10
|
+
@key = key
|
11
|
+
@meta = meta
|
12
|
+
@config = config
|
13
|
+
set_defaults!
|
14
|
+
|
15
|
+
trace("Tracer has been initialized for #{key}")
|
16
|
+
@reference = reference || liftoff.first
|
17
|
+
end
|
18
|
+
|
19
|
+
def set_defaults!
|
20
|
+
@tags = []
|
21
|
+
@data = []
|
22
|
+
@artifacts = []
|
23
|
+
@state = :running
|
24
|
+
@ignore = false
|
25
|
+
@result_prefix = '=> '
|
26
|
+
end
|
27
|
+
|
28
|
+
def pop_all_data
|
29
|
+
@data.pop(@data.count)
|
30
|
+
end
|
31
|
+
|
32
|
+
def pop_all_artifacts
|
33
|
+
@artifacts.pop(@artifacts.count)
|
34
|
+
end
|
35
|
+
|
36
|
+
def config
|
37
|
+
@config || Trifle::Traces.default
|
38
|
+
end
|
39
|
+
|
40
|
+
def keys
|
41
|
+
parts = key.split('/')
|
42
|
+
parts.count.times.map { |i| parts[0..i].join('/') }
|
43
|
+
end
|
44
|
+
|
45
|
+
def trace(message, state: :success, head: false) # rubocop:disable Metrics/MethodLength
|
46
|
+
result = yield if block_given?
|
47
|
+
rescue StandardError => e
|
48
|
+
raise e
|
49
|
+
ensure
|
50
|
+
dump_message(
|
51
|
+
message,
|
52
|
+
type: head ? :head : :text,
|
53
|
+
state: e ? :error : state
|
54
|
+
)
|
55
|
+
dump_result(result) if block_given?
|
56
|
+
bump
|
57
|
+
result
|
58
|
+
end
|
59
|
+
|
60
|
+
def dump_message(message, type:, state:)
|
61
|
+
@data << { at: now, message: message, state: state, type: type }
|
62
|
+
end
|
63
|
+
|
64
|
+
def dump_result(result)
|
65
|
+
@data << {
|
66
|
+
at: now, message: "#{@result_prefix}#{result.inspect}",
|
67
|
+
state: :success, type: :raw
|
68
|
+
}
|
69
|
+
end
|
70
|
+
|
71
|
+
def now
|
72
|
+
Time.now.to_i
|
73
|
+
end
|
74
|
+
|
75
|
+
def tag(tag)
|
76
|
+
@tags << tag
|
77
|
+
bump
|
78
|
+
tag
|
79
|
+
end
|
80
|
+
|
81
|
+
def artifact(name, path)
|
82
|
+
@data << { at: now, message: name, state: :success, type: :media, size: File.size(path) }
|
83
|
+
@artifacts << path
|
84
|
+
bump
|
85
|
+
path
|
86
|
+
end
|
87
|
+
|
88
|
+
def fail!
|
89
|
+
@state = :error
|
90
|
+
end
|
91
|
+
|
92
|
+
def warn!
|
93
|
+
@state = :warning
|
94
|
+
end
|
95
|
+
|
96
|
+
def success!
|
97
|
+
@state = :success
|
98
|
+
end
|
99
|
+
|
100
|
+
def success?
|
101
|
+
@state == :success
|
102
|
+
end
|
103
|
+
|
104
|
+
def running?
|
105
|
+
@state == :running
|
106
|
+
end
|
107
|
+
|
108
|
+
def ignore!
|
109
|
+
@ignore = true
|
110
|
+
end
|
111
|
+
|
112
|
+
def liftoff
|
113
|
+
@bumped_at = now
|
114
|
+
config.on_liftoff(self)
|
115
|
+
end
|
116
|
+
|
117
|
+
def bump
|
118
|
+
return unless @bumped_at && @bumped_at <= now - config.bump_every
|
119
|
+
|
120
|
+
@bumped_at = now
|
121
|
+
config.on_bump(self)
|
122
|
+
end
|
123
|
+
|
124
|
+
def wrapup
|
125
|
+
success! if running?
|
126
|
+
config.on_wrapup(self)
|
127
|
+
end
|
128
|
+
end
|
129
|
+
end
|
130
|
+
end
|
131
|
+
end
|
@@ -0,0 +1,29 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
3
|
+
module Trifle
|
4
|
+
module Traces
|
5
|
+
module Tracer
|
6
|
+
class Null
|
7
|
+
def trace(_message, **_keywords)
|
8
|
+
yield if block_given?
|
9
|
+
end
|
10
|
+
|
11
|
+
def tag(_tag); end
|
12
|
+
|
13
|
+
def artifact(_name, _path); end
|
14
|
+
|
15
|
+
def fail!; end
|
16
|
+
|
17
|
+
def warn!; end
|
18
|
+
|
19
|
+
def ignore!; end
|
20
|
+
|
21
|
+
def liftoff; end
|
22
|
+
|
23
|
+
def bump; end
|
24
|
+
|
25
|
+
def wrapup; end
|
26
|
+
end
|
27
|
+
end
|
28
|
+
end
|
29
|
+
end
|
@@ -0,0 +1,72 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
3
|
+
require 'trifle/traces/configuration'
|
4
|
+
require 'trifle/traces/tracer/hash'
|
5
|
+
require 'trifle/traces/tracer/null'
|
6
|
+
require 'trifle/traces/middleware/rack'
|
7
|
+
require 'trifle/traces/middleware/rails_controller'
|
8
|
+
require 'trifle/traces/middleware/sidekiq'
|
9
|
+
require 'trifle/traces/version'
|
10
|
+
|
11
|
+
module Trifle
|
12
|
+
module Traces
|
13
|
+
class Error < StandardError; end
|
14
|
+
# Your code goes here...
|
15
|
+
|
16
|
+
def self.default
|
17
|
+
@default ||= Configuration.new
|
18
|
+
end
|
19
|
+
|
20
|
+
def self.configure
|
21
|
+
yield(default)
|
22
|
+
|
23
|
+
default
|
24
|
+
end
|
25
|
+
|
26
|
+
def self.tracer=(tracer)
|
27
|
+
Thread.current[:trifle_tracer] = tracer
|
28
|
+
end
|
29
|
+
|
30
|
+
def self.tracer
|
31
|
+
Thread.current[:trifle_tracer]
|
32
|
+
end
|
33
|
+
|
34
|
+
def self.trace(*args, **keywords, &block)
|
35
|
+
if tracer.nil?
|
36
|
+
return block_given? ? yield : nil
|
37
|
+
end
|
38
|
+
|
39
|
+
tracer.trace(*args, **keywords, &block)
|
40
|
+
end
|
41
|
+
|
42
|
+
def self.tag(tag)
|
43
|
+
return unless tracer
|
44
|
+
|
45
|
+
tracer.tag(tag)
|
46
|
+
end
|
47
|
+
|
48
|
+
def self.artifact(name, path)
|
49
|
+
return unless tracer
|
50
|
+
|
51
|
+
tracer.artifact(name, path)
|
52
|
+
end
|
53
|
+
|
54
|
+
def self.fail!
|
55
|
+
return unless tracer
|
56
|
+
|
57
|
+
tracer.fail!
|
58
|
+
end
|
59
|
+
|
60
|
+
def self.warn!
|
61
|
+
return unless tracer
|
62
|
+
|
63
|
+
tracer.warn!
|
64
|
+
end
|
65
|
+
|
66
|
+
def self.ignore!
|
67
|
+
return unless tracer
|
68
|
+
|
69
|
+
tracer.ignore!
|
70
|
+
end
|
71
|
+
end
|
72
|
+
end
|
@@ -0,0 +1,34 @@
|
|
1
|
+
require_relative 'lib/trifle/traces/version'
|
2
|
+
|
3
|
+
Gem::Specification.new do |spec|
|
4
|
+
spec.name = 'trifle-traces'
|
5
|
+
spec.version = Trifle::Traces::VERSION
|
6
|
+
spec.authors = ['Jozef Vaclavik']
|
7
|
+
spec.email = ['jozef@hey.com']
|
8
|
+
|
9
|
+
spec.summary = 'Simple tracing backed by Hash'
|
10
|
+
spec.description = 'Trifle::Traces is a way too simple timeline tracer '\
|
11
|
+
'that helps you track custom outputs.'
|
12
|
+
spec.homepage = 'https://trifle.io'
|
13
|
+
spec.licenses = ['MIT']
|
14
|
+
spec.required_ruby_version = Gem::Requirement.new('>= 2.6')
|
15
|
+
|
16
|
+
spec.metadata['homepage_uri'] = spec.homepage
|
17
|
+
spec.metadata['source_code_uri'] = 'https://github.com/trifle-io/trifle-traces'
|
18
|
+
spec.metadata['changelog_uri'] = 'https://trifle.io/trifle-traces/changelog'
|
19
|
+
|
20
|
+
# Specify which files should be added to the gem when it is released.
|
21
|
+
# The `git ls-files -z` loads the files in the RubyGem that have been added into git.
|
22
|
+
spec.files = Dir.chdir(File.expand_path('..', __FILE__)) do
|
23
|
+
`git ls-files -z`.split("\x0").reject { |f| f.match(%r{^(test|spec|features)/}) }
|
24
|
+
end
|
25
|
+
spec.bindir = 'exe'
|
26
|
+
spec.executables = spec.files.grep(%r{^exe/}) { |f| File.basename(f) }
|
27
|
+
spec.require_paths = ['lib']
|
28
|
+
|
29
|
+
spec.add_development_dependency('bundler', '~> 2.1')
|
30
|
+
spec.add_development_dependency('byebug', '>= 0')
|
31
|
+
spec.add_development_dependency('rake', '~> 13.0')
|
32
|
+
spec.add_development_dependency('rspec', '~> 3.2')
|
33
|
+
spec.add_development_dependency('rubocop', '1.0.0')
|
34
|
+
end
|
metadata
ADDED
@@ -0,0 +1,141 @@
|
|
1
|
+
--- !ruby/object:Gem::Specification
|
2
|
+
name: trifle-traces
|
3
|
+
version: !ruby/object:Gem::Version
|
4
|
+
version: 1.0.1
|
5
|
+
platform: ruby
|
6
|
+
authors:
|
7
|
+
- Jozef Vaclavik
|
8
|
+
autorequire:
|
9
|
+
bindir: exe
|
10
|
+
cert_chain: []
|
11
|
+
date: 2022-11-16 00:00:00.000000000 Z
|
12
|
+
dependencies:
|
13
|
+
- !ruby/object:Gem::Dependency
|
14
|
+
name: bundler
|
15
|
+
requirement: !ruby/object:Gem::Requirement
|
16
|
+
requirements:
|
17
|
+
- - "~>"
|
18
|
+
- !ruby/object:Gem::Version
|
19
|
+
version: '2.1'
|
20
|
+
type: :development
|
21
|
+
prerelease: false
|
22
|
+
version_requirements: !ruby/object:Gem::Requirement
|
23
|
+
requirements:
|
24
|
+
- - "~>"
|
25
|
+
- !ruby/object:Gem::Version
|
26
|
+
version: '2.1'
|
27
|
+
- !ruby/object:Gem::Dependency
|
28
|
+
name: byebug
|
29
|
+
requirement: !ruby/object:Gem::Requirement
|
30
|
+
requirements:
|
31
|
+
- - ">="
|
32
|
+
- !ruby/object:Gem::Version
|
33
|
+
version: '0'
|
34
|
+
type: :development
|
35
|
+
prerelease: false
|
36
|
+
version_requirements: !ruby/object:Gem::Requirement
|
37
|
+
requirements:
|
38
|
+
- - ">="
|
39
|
+
- !ruby/object:Gem::Version
|
40
|
+
version: '0'
|
41
|
+
- !ruby/object:Gem::Dependency
|
42
|
+
name: rake
|
43
|
+
requirement: !ruby/object:Gem::Requirement
|
44
|
+
requirements:
|
45
|
+
- - "~>"
|
46
|
+
- !ruby/object:Gem::Version
|
47
|
+
version: '13.0'
|
48
|
+
type: :development
|
49
|
+
prerelease: false
|
50
|
+
version_requirements: !ruby/object:Gem::Requirement
|
51
|
+
requirements:
|
52
|
+
- - "~>"
|
53
|
+
- !ruby/object:Gem::Version
|
54
|
+
version: '13.0'
|
55
|
+
- !ruby/object:Gem::Dependency
|
56
|
+
name: rspec
|
57
|
+
requirement: !ruby/object:Gem::Requirement
|
58
|
+
requirements:
|
59
|
+
- - "~>"
|
60
|
+
- !ruby/object:Gem::Version
|
61
|
+
version: '3.2'
|
62
|
+
type: :development
|
63
|
+
prerelease: false
|
64
|
+
version_requirements: !ruby/object:Gem::Requirement
|
65
|
+
requirements:
|
66
|
+
- - "~>"
|
67
|
+
- !ruby/object:Gem::Version
|
68
|
+
version: '3.2'
|
69
|
+
- !ruby/object:Gem::Dependency
|
70
|
+
name: rubocop
|
71
|
+
requirement: !ruby/object:Gem::Requirement
|
72
|
+
requirements:
|
73
|
+
- - '='
|
74
|
+
- !ruby/object:Gem::Version
|
75
|
+
version: 1.0.0
|
76
|
+
type: :development
|
77
|
+
prerelease: false
|
78
|
+
version_requirements: !ruby/object:Gem::Requirement
|
79
|
+
requirements:
|
80
|
+
- - '='
|
81
|
+
- !ruby/object:Gem::Version
|
82
|
+
version: 1.0.0
|
83
|
+
description: Trifle::Traces is a way too simple timeline tracer that helps you track
|
84
|
+
custom outputs.
|
85
|
+
email:
|
86
|
+
- jozef@hey.com
|
87
|
+
executables: []
|
88
|
+
extensions: []
|
89
|
+
extra_rdoc_files: []
|
90
|
+
files:
|
91
|
+
- ".github/workflows/ruby.yml"
|
92
|
+
- ".gitignore"
|
93
|
+
- ".gitpod.yml"
|
94
|
+
- ".gitpod/Dockerfile"
|
95
|
+
- ".rspec"
|
96
|
+
- ".rubocop.yml"
|
97
|
+
- ".ruby-version"
|
98
|
+
- ".tool-versions"
|
99
|
+
- Gemfile
|
100
|
+
- Gemfile.lock
|
101
|
+
- LICENSE
|
102
|
+
- README.md
|
103
|
+
- Rakefile
|
104
|
+
- bin/console
|
105
|
+
- bin/setup
|
106
|
+
- lib/trifle/traces.rb
|
107
|
+
- lib/trifle/traces/configuration.rb
|
108
|
+
- lib/trifle/traces/middleware/rack.rb
|
109
|
+
- lib/trifle/traces/middleware/rails_controller.rb
|
110
|
+
- lib/trifle/traces/middleware/sidekiq.rb
|
111
|
+
- lib/trifle/traces/tracer/hash.rb
|
112
|
+
- lib/trifle/traces/tracer/null.rb
|
113
|
+
- lib/trifle/traces/version.rb
|
114
|
+
- trifle-traces.gemspec
|
115
|
+
homepage: https://trifle.io
|
116
|
+
licenses:
|
117
|
+
- MIT
|
118
|
+
metadata:
|
119
|
+
homepage_uri: https://trifle.io
|
120
|
+
source_code_uri: https://github.com/trifle-io/trifle-traces
|
121
|
+
changelog_uri: https://trifle.io/trifle-traces/changelog
|
122
|
+
post_install_message:
|
123
|
+
rdoc_options: []
|
124
|
+
require_paths:
|
125
|
+
- lib
|
126
|
+
required_ruby_version: !ruby/object:Gem::Requirement
|
127
|
+
requirements:
|
128
|
+
- - ">="
|
129
|
+
- !ruby/object:Gem::Version
|
130
|
+
version: '2.6'
|
131
|
+
required_rubygems_version: !ruby/object:Gem::Requirement
|
132
|
+
requirements:
|
133
|
+
- - ">="
|
134
|
+
- !ruby/object:Gem::Version
|
135
|
+
version: '0'
|
136
|
+
requirements: []
|
137
|
+
rubygems_version: 3.3.3
|
138
|
+
signing_key:
|
139
|
+
specification_version: 4
|
140
|
+
summary: Simple tracing backed by Hash
|
141
|
+
test_files: []
|