sidekiq-tracer 0.1.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- checksums.yaml +7 -0
- data/.gitignore +9 -0
- data/.gitlab-ci.yml +8 -0
- data/CONDUCT.md +74 -0
- data/Gemfile +2 -0
- data/README.md +71 -0
- data/Rakefile +10 -0
- data/bin/console +7 -0
- data/bin/rake +17 -0
- data/bin/setup +6 -0
- data/lib/sidekiq/tracer/auto.rb +18 -0
- data/lib/sidekiq/tracer/client_middleware.rb +20 -0
- data/lib/sidekiq/tracer/json_log_formatter.rb +42 -0
- data/lib/sidekiq/tracer/server_middleware.rb +19 -0
- data/lib/sidekiq/tracer/version.rb +5 -0
- data/lib/sidekiq/tracer.rb +9 -0
- data/sidekiq-tracer.gemspec +30 -0
- metadata +158 -0
checksums.yaml
ADDED
@@ -0,0 +1,7 @@
|
|
1
|
+
---
|
2
|
+
SHA1:
|
3
|
+
metadata.gz: 9e44e41b425b76ef703d37afa180e4276159dcce
|
4
|
+
data.tar.gz: '081e3ba96fcb5f23056264a22ab27289f7099311'
|
5
|
+
SHA512:
|
6
|
+
metadata.gz: 61457298631770addafa03b7ab54249de66cceddff512eb275e9b4ee947876b01b76c3e64edfe14d758a5f86a39a87a375c637db726e2eaa37e771ee8a600795
|
7
|
+
data.tar.gz: 27126a9e38300aaa9f642adaadc7499399616e6ae9fad49280f8cb6af628492b6c7d417bb1fbc12aa815863cd3d5504f165a824ca31bf12989b2861897f3deff
|
data/.gitignore
ADDED
data/.gitlab-ci.yml
ADDED
data/CONDUCT.md
ADDED
@@ -0,0 +1,74 @@
|
|
1
|
+
# Contributor Covenant Code of Conduct
|
2
|
+
|
3
|
+
## Our Pledge
|
4
|
+
|
5
|
+
In the interest of fostering an open and welcoming environment, we as
|
6
|
+
contributors and maintainers pledge to making participation in our project and
|
7
|
+
our community a harassment-free experience for everyone, regardless of age, body
|
8
|
+
size, disability, ethnicity, gender identity and expression, level of experience,
|
9
|
+
nationality, personal appearance, race, religion, or sexual identity and
|
10
|
+
orientation.
|
11
|
+
|
12
|
+
## Our Standards
|
13
|
+
|
14
|
+
Examples of behavior that contributes to creating a positive environment
|
15
|
+
include:
|
16
|
+
|
17
|
+
* Using welcoming and inclusive language
|
18
|
+
* Being respectful of differing viewpoints and experiences
|
19
|
+
* Gracefully accepting constructive criticism
|
20
|
+
* Focusing on what is best for the community
|
21
|
+
* Showing empathy towards other community members
|
22
|
+
|
23
|
+
Examples of unacceptable behavior by participants include:
|
24
|
+
|
25
|
+
* The use of sexualized language or imagery and unwelcome sexual attention or
|
26
|
+
advances
|
27
|
+
* Trolling, insulting/derogatory comments, and personal or political attacks
|
28
|
+
* Public or private harassment
|
29
|
+
* Publishing others' private information, such as a physical or electronic
|
30
|
+
address, without explicit permission
|
31
|
+
* Other conduct which could reasonably be considered inappropriate in a
|
32
|
+
professional setting
|
33
|
+
|
34
|
+
## Our Responsibilities
|
35
|
+
|
36
|
+
Project maintainers are responsible for clarifying the standards of acceptable
|
37
|
+
behavior and are expected to take appropriate and fair corrective action in
|
38
|
+
response to any instances of unacceptable behavior.
|
39
|
+
|
40
|
+
Project maintainers have the right and responsibility to remove, edit, or
|
41
|
+
reject comments, commits, code, wiki edits, issues, and other contributions
|
42
|
+
that are not aligned to this Code of Conduct, or to ban temporarily or
|
43
|
+
permanently any contributor for other behaviors that they deem inappropriate,
|
44
|
+
threatening, offensive, or harmful.
|
45
|
+
|
46
|
+
## Scope
|
47
|
+
|
48
|
+
This Code of Conduct applies both within project spaces and in public spaces
|
49
|
+
when an individual is representing the project or its community. Examples of
|
50
|
+
representing a project or community include using an official project e-mail
|
51
|
+
address, posting via an official social media account, or acting as an appointed
|
52
|
+
representative at an online or offline event. Representation of a project may be
|
53
|
+
further defined and clarified by project maintainers.
|
54
|
+
|
55
|
+
## Enforcement
|
56
|
+
|
57
|
+
Instances of abusive, harassing, or otherwise unacceptable behavior may be
|
58
|
+
reported by contacting the project team at sidekiqtracer@darrencoxall.com. All
|
59
|
+
complaints will be reviewed and investigated and will result in a response that
|
60
|
+
is deemed necessary and appropriate to the circumstances. The project team is
|
61
|
+
obligated to maintain confidentiality with regard to the reporter of an incident.
|
62
|
+
Further details of specific enforcement policies may be posted separately.
|
63
|
+
|
64
|
+
Project maintainers who do not follow or enforce the Code of Conduct in good
|
65
|
+
faith may face temporary or permanent repercussions as determined by other
|
66
|
+
members of the project's leadership.
|
67
|
+
|
68
|
+
## Attribution
|
69
|
+
|
70
|
+
This Code of Conduct is adapted from the [Contributor Covenant][homepage], version 1.4,
|
71
|
+
available at [http://contributor-covenant.org/version/1/4][version]
|
72
|
+
|
73
|
+
[homepage]: http://contributor-covenant.org
|
74
|
+
[version]: http://contributor-covenant.org/version/1/4/
|
data/Gemfile
ADDED
data/README.md
ADDED
@@ -0,0 +1,71 @@
|
|
1
|
+
[](https://gitlab.com/dcoxall/sidekiq-tracer/commits/master)
|
2
|
+
|
3
|
+
# Sidekiq Tracer
|
4
|
+
|
5
|
+
Sidekiq Tracer aims to provide better logging for sidekiq jobs to make debugging issues easier. It does this by either generating a tracing id which is included in the logs. If a job is then created during the execution of another then the tracing id is passed down.
|
6
|
+
|
7
|
+
On it's own it does little but when the tracing ID is pulled into logs then it becomes possible to follow complex chains of jobs when 1 worker will queue up multiple others.
|
8
|
+
|
9
|
+
## Installation
|
10
|
+
|
11
|
+
Add this line to your application's Gemfile:
|
12
|
+
|
13
|
+
```ruby
|
14
|
+
gem 'sidekiq-tracer'
|
15
|
+
```
|
16
|
+
|
17
|
+
And then execute:
|
18
|
+
|
19
|
+
$ bundle
|
20
|
+
|
21
|
+
Or install it yourself as:
|
22
|
+
|
23
|
+
$ gem install sidekiq-tracer
|
24
|
+
|
25
|
+
## Usage
|
26
|
+
|
27
|
+
The easiest way to configure and use sidekiq-tracer is to add the following to you Gemfile
|
28
|
+
|
29
|
+
```ruby
|
30
|
+
gem "sidekiq-tracer", require: "sidekiq/tracer/auto"
|
31
|
+
```
|
32
|
+
|
33
|
+
This will then require and configure the gem in the standard way.
|
34
|
+
|
35
|
+
If you want more control over the configuration however then include sidekiq-tracer in your Gemfile
|
36
|
+
in the standard way and then use the following to enable it for Sidekiq.
|
37
|
+
|
38
|
+
```ruby
|
39
|
+
require "sidekiq/tracer"
|
40
|
+
|
41
|
+
Sidekiq.logger.formatter = Sidekiq::Tracer::JsonLogFormatter.new
|
42
|
+
|
43
|
+
Sidekiq.configure_client do |config|
|
44
|
+
config.client_middleware do |chain|
|
45
|
+
chain.add Sidekiq::Tracer::ClientMiddleware
|
46
|
+
end
|
47
|
+
end
|
48
|
+
|
49
|
+
Sidekiq.configure_server do |config|
|
50
|
+
config.client_middleware do |chain|
|
51
|
+
chain.add Sidekiq::Tracer::ClientMiddleware
|
52
|
+
end
|
53
|
+
config.server_middleware do |chain|
|
54
|
+
chain.add Sidekiq::Tracer::ServerMiddleware
|
55
|
+
end
|
56
|
+
end
|
57
|
+
```
|
58
|
+
|
59
|
+
## Development
|
60
|
+
|
61
|
+
After checking out the repo, run `bin/setup` to install dependencies. Then, run `rake test` to run the tests. You can also run `bin/console` for an interactive prompt that will allow you to experiment.
|
62
|
+
|
63
|
+
## Contributing
|
64
|
+
|
65
|
+
First, please read and understand the Code of Conduct for this project. This project is open to contribution from all and to ensure that everyone feels welcome then following the code of conduct is very important.
|
66
|
+
|
67
|
+
Bug reports and pull requests are welcome at https://gitlab.com/dcoxall/sidekiq-tracer.
|
68
|
+
|
69
|
+
When reporting an issue be descriptive and provide as much information as possible to re-create it.
|
70
|
+
|
71
|
+
When submitting a pull request then feel free to create the request early and ask for feedback or advice. New additions should be covered with tests and the community should be more than happy to help if you are unsure how best to achieve that.
|
data/Rakefile
ADDED
data/bin/console
ADDED
data/bin/rake
ADDED
@@ -0,0 +1,17 @@
|
|
1
|
+
#!/usr/bin/env ruby
|
2
|
+
# frozen_string_literal: true
|
3
|
+
#
|
4
|
+
# This file was generated by Bundler.
|
5
|
+
#
|
6
|
+
# The application 'rake' is installed as part of a gem, and
|
7
|
+
# this file is here to facilitate running it.
|
8
|
+
#
|
9
|
+
|
10
|
+
require "pathname"
|
11
|
+
ENV["BUNDLE_GEMFILE"] ||= File.expand_path("../../Gemfile",
|
12
|
+
Pathname.new(__FILE__).realpath)
|
13
|
+
|
14
|
+
require "rubygems"
|
15
|
+
require "bundler/setup"
|
16
|
+
|
17
|
+
load Gem.bin_path("rake", "rake")
|
data/bin/setup
ADDED
@@ -0,0 +1,18 @@
|
|
1
|
+
require "sidekiq/tracer"
|
2
|
+
|
3
|
+
Sidekiq.logger.formatter = Sidekiq::Tracer::JsonLogFormatter.new
|
4
|
+
|
5
|
+
Sidekiq.configure_client do |config|
|
6
|
+
config.client_middleware do |chain|
|
7
|
+
chain.add Sidekiq::Tracer::ClientMiddleware
|
8
|
+
end
|
9
|
+
end
|
10
|
+
|
11
|
+
Sidekiq.configure_server do |config|
|
12
|
+
config.client_middleware do |chain|
|
13
|
+
chain.add Sidekiq::Tracer::ClientMiddleware
|
14
|
+
end
|
15
|
+
config.server_middleware do |chain|
|
16
|
+
chain.add Sidekiq::Tracer::ServerMiddleware
|
17
|
+
end
|
18
|
+
end
|
@@ -0,0 +1,20 @@
|
|
1
|
+
module Sidekiq
|
2
|
+
module Tracer
|
3
|
+
class ClientMiddleware
|
4
|
+
def call(_worker_class, job, _queue, _redis_pool)
|
5
|
+
job["root_trace"] = root_trace
|
6
|
+
yield
|
7
|
+
end
|
8
|
+
|
9
|
+
private
|
10
|
+
|
11
|
+
def root_trace
|
12
|
+
if Thread.current[:sidekiq_root_trace] &&
|
13
|
+
Thread.current[:sidekiq_root_trace].last
|
14
|
+
return Thread.current[:sidekiq_root_trace].last
|
15
|
+
end
|
16
|
+
SecureRandom.uuid
|
17
|
+
end
|
18
|
+
end
|
19
|
+
end
|
20
|
+
end
|
@@ -0,0 +1,42 @@
|
|
1
|
+
require "multi_json"
|
2
|
+
|
3
|
+
module Sidekiq
|
4
|
+
module Tracer
|
5
|
+
class JsonLogFormatter < ::Logger::Formatter
|
6
|
+
def initialize(pretty: false)
|
7
|
+
@pretty = !!pretty
|
8
|
+
end
|
9
|
+
|
10
|
+
def call(severity, time, _progname, msg)
|
11
|
+
MultiJson.dump({
|
12
|
+
tms: time.utc.iso8601(3),
|
13
|
+
pid: pid,
|
14
|
+
tid: format("TID-%s", thread_id),
|
15
|
+
cxt: context,
|
16
|
+
sev: severity,
|
17
|
+
msg: msg,
|
18
|
+
trc: trace,
|
19
|
+
}, pretty: @pretty)
|
20
|
+
end
|
21
|
+
|
22
|
+
private
|
23
|
+
|
24
|
+
def pid
|
25
|
+
::Process.pid
|
26
|
+
end
|
27
|
+
|
28
|
+
def thread_id
|
29
|
+
Thread.current.object_id.to_s(36)
|
30
|
+
end
|
31
|
+
|
32
|
+
def context
|
33
|
+
Thread.current[:sidekiq_context]
|
34
|
+
end
|
35
|
+
|
36
|
+
def trace
|
37
|
+
trace_id = Thread.current[:sidekiq_root_trace]
|
38
|
+
trace_id.last unless trace_id.nil?
|
39
|
+
end
|
40
|
+
end
|
41
|
+
end
|
42
|
+
end
|
@@ -0,0 +1,19 @@
|
|
1
|
+
module Sidekiq
|
2
|
+
module Tracer
|
3
|
+
class ServerMiddleware
|
4
|
+
def call(worker, msg, queue)
|
5
|
+
with_trace(msg["root_trace"]) { yield }
|
6
|
+
end
|
7
|
+
|
8
|
+
private
|
9
|
+
|
10
|
+
def with_trace(value)
|
11
|
+
Thread.current[:sidekiq_root_trace] ||= []
|
12
|
+
Thread.current[:sidekiq_root_trace] << value unless value.nil?
|
13
|
+
yield
|
14
|
+
ensure
|
15
|
+
Thread.current[:sidekiq_root_trace].pop
|
16
|
+
end
|
17
|
+
end
|
18
|
+
end
|
19
|
+
end
|
@@ -0,0 +1,30 @@
|
|
1
|
+
# coding: utf-8
|
2
|
+
lib = File.expand_path('../lib', __FILE__)
|
3
|
+
$LOAD_PATH.unshift(lib) unless $LOAD_PATH.include?(lib)
|
4
|
+
require 'sidekiq/tracer/version'
|
5
|
+
|
6
|
+
Gem::Specification.new do |spec|
|
7
|
+
spec.name = "sidekiq-tracer"
|
8
|
+
spec.version = Sidekiq::Tracer::VERSION
|
9
|
+
spec.authors = ["Darren Coxall"]
|
10
|
+
spec.email = ["darren@darrencoxall.com"]
|
11
|
+
|
12
|
+
spec.summary = %q{Sidekiq middleware to better trace how jobs are executed}
|
13
|
+
spec.description = %q{Sidekiq middleware that adds JSON logging and job tracing for better debugging}
|
14
|
+
spec.homepage = "https://gitlab.com/dcoxall/sidekiq-tracer"
|
15
|
+
|
16
|
+
spec.files = `git ls-files -z`.split("\x0").reject do |f|
|
17
|
+
f.match(%r{^(test|spec|features)/})
|
18
|
+
end
|
19
|
+
spec.bindir = "exe"
|
20
|
+
spec.executables = spec.files.grep(%r{^exe/}) { |f| File.basename(f) }
|
21
|
+
spec.require_paths = ["lib"]
|
22
|
+
|
23
|
+
spec.add_development_dependency "bundler", "~> 1.13"
|
24
|
+
spec.add_development_dependency "rake", "~> 10.0"
|
25
|
+
spec.add_development_dependency "minitest", "~> 5.0"
|
26
|
+
spec.add_development_dependency "pry", "> 0"
|
27
|
+
spec.add_development_dependency "timecop", "~> 0.8.0"
|
28
|
+
spec.add_runtime_dependency "sidekiq", ">= 2.0"
|
29
|
+
spec.add_runtime_dependency "multi_json", "~> 1.0"
|
30
|
+
end
|
metadata
ADDED
@@ -0,0 +1,158 @@
|
|
1
|
+
--- !ruby/object:Gem::Specification
|
2
|
+
name: sidekiq-tracer
|
3
|
+
version: !ruby/object:Gem::Version
|
4
|
+
version: 0.1.0
|
5
|
+
platform: ruby
|
6
|
+
authors:
|
7
|
+
- Darren Coxall
|
8
|
+
autorequire:
|
9
|
+
bindir: exe
|
10
|
+
cert_chain: []
|
11
|
+
date: 2016-11-24 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: '1.13'
|
20
|
+
type: :development
|
21
|
+
prerelease: false
|
22
|
+
version_requirements: !ruby/object:Gem::Requirement
|
23
|
+
requirements:
|
24
|
+
- - "~>"
|
25
|
+
- !ruby/object:Gem::Version
|
26
|
+
version: '1.13'
|
27
|
+
- !ruby/object:Gem::Dependency
|
28
|
+
name: rake
|
29
|
+
requirement: !ruby/object:Gem::Requirement
|
30
|
+
requirements:
|
31
|
+
- - "~>"
|
32
|
+
- !ruby/object:Gem::Version
|
33
|
+
version: '10.0'
|
34
|
+
type: :development
|
35
|
+
prerelease: false
|
36
|
+
version_requirements: !ruby/object:Gem::Requirement
|
37
|
+
requirements:
|
38
|
+
- - "~>"
|
39
|
+
- !ruby/object:Gem::Version
|
40
|
+
version: '10.0'
|
41
|
+
- !ruby/object:Gem::Dependency
|
42
|
+
name: minitest
|
43
|
+
requirement: !ruby/object:Gem::Requirement
|
44
|
+
requirements:
|
45
|
+
- - "~>"
|
46
|
+
- !ruby/object:Gem::Version
|
47
|
+
version: '5.0'
|
48
|
+
type: :development
|
49
|
+
prerelease: false
|
50
|
+
version_requirements: !ruby/object:Gem::Requirement
|
51
|
+
requirements:
|
52
|
+
- - "~>"
|
53
|
+
- !ruby/object:Gem::Version
|
54
|
+
version: '5.0'
|
55
|
+
- !ruby/object:Gem::Dependency
|
56
|
+
name: pry
|
57
|
+
requirement: !ruby/object:Gem::Requirement
|
58
|
+
requirements:
|
59
|
+
- - ">"
|
60
|
+
- !ruby/object:Gem::Version
|
61
|
+
version: '0'
|
62
|
+
type: :development
|
63
|
+
prerelease: false
|
64
|
+
version_requirements: !ruby/object:Gem::Requirement
|
65
|
+
requirements:
|
66
|
+
- - ">"
|
67
|
+
- !ruby/object:Gem::Version
|
68
|
+
version: '0'
|
69
|
+
- !ruby/object:Gem::Dependency
|
70
|
+
name: timecop
|
71
|
+
requirement: !ruby/object:Gem::Requirement
|
72
|
+
requirements:
|
73
|
+
- - "~>"
|
74
|
+
- !ruby/object:Gem::Version
|
75
|
+
version: 0.8.0
|
76
|
+
type: :development
|
77
|
+
prerelease: false
|
78
|
+
version_requirements: !ruby/object:Gem::Requirement
|
79
|
+
requirements:
|
80
|
+
- - "~>"
|
81
|
+
- !ruby/object:Gem::Version
|
82
|
+
version: 0.8.0
|
83
|
+
- !ruby/object:Gem::Dependency
|
84
|
+
name: sidekiq
|
85
|
+
requirement: !ruby/object:Gem::Requirement
|
86
|
+
requirements:
|
87
|
+
- - ">="
|
88
|
+
- !ruby/object:Gem::Version
|
89
|
+
version: '2.0'
|
90
|
+
type: :runtime
|
91
|
+
prerelease: false
|
92
|
+
version_requirements: !ruby/object:Gem::Requirement
|
93
|
+
requirements:
|
94
|
+
- - ">="
|
95
|
+
- !ruby/object:Gem::Version
|
96
|
+
version: '2.0'
|
97
|
+
- !ruby/object:Gem::Dependency
|
98
|
+
name: multi_json
|
99
|
+
requirement: !ruby/object:Gem::Requirement
|
100
|
+
requirements:
|
101
|
+
- - "~>"
|
102
|
+
- !ruby/object:Gem::Version
|
103
|
+
version: '1.0'
|
104
|
+
type: :runtime
|
105
|
+
prerelease: false
|
106
|
+
version_requirements: !ruby/object:Gem::Requirement
|
107
|
+
requirements:
|
108
|
+
- - "~>"
|
109
|
+
- !ruby/object:Gem::Version
|
110
|
+
version: '1.0'
|
111
|
+
description: Sidekiq middleware that adds JSON logging and job tracing for better
|
112
|
+
debugging
|
113
|
+
email:
|
114
|
+
- darren@darrencoxall.com
|
115
|
+
executables: []
|
116
|
+
extensions: []
|
117
|
+
extra_rdoc_files: []
|
118
|
+
files:
|
119
|
+
- ".gitignore"
|
120
|
+
- ".gitlab-ci.yml"
|
121
|
+
- CONDUCT.md
|
122
|
+
- Gemfile
|
123
|
+
- README.md
|
124
|
+
- Rakefile
|
125
|
+
- bin/console
|
126
|
+
- bin/rake
|
127
|
+
- bin/setup
|
128
|
+
- lib/sidekiq/tracer.rb
|
129
|
+
- lib/sidekiq/tracer/auto.rb
|
130
|
+
- lib/sidekiq/tracer/client_middleware.rb
|
131
|
+
- lib/sidekiq/tracer/json_log_formatter.rb
|
132
|
+
- lib/sidekiq/tracer/server_middleware.rb
|
133
|
+
- lib/sidekiq/tracer/version.rb
|
134
|
+
- sidekiq-tracer.gemspec
|
135
|
+
homepage: https://gitlab.com/dcoxall/sidekiq-tracer
|
136
|
+
licenses: []
|
137
|
+
metadata: {}
|
138
|
+
post_install_message:
|
139
|
+
rdoc_options: []
|
140
|
+
require_paths:
|
141
|
+
- lib
|
142
|
+
required_ruby_version: !ruby/object:Gem::Requirement
|
143
|
+
requirements:
|
144
|
+
- - ">="
|
145
|
+
- !ruby/object:Gem::Version
|
146
|
+
version: '0'
|
147
|
+
required_rubygems_version: !ruby/object:Gem::Requirement
|
148
|
+
requirements:
|
149
|
+
- - ">="
|
150
|
+
- !ruby/object:Gem::Version
|
151
|
+
version: '0'
|
152
|
+
requirements: []
|
153
|
+
rubyforge_project:
|
154
|
+
rubygems_version: 2.5.2
|
155
|
+
signing_key:
|
156
|
+
specification_version: 4
|
157
|
+
summary: Sidekiq middleware to better trace how jobs are executed
|
158
|
+
test_files: []
|