hubstep 2.0.2 → 2.0.3
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 +4 -4
- data/.rubocop.yml +3 -1
- data/.rubocop_todo.yml +11 -0
- data/.rubocop_upstream.yml +30 -0
- data/hubstep.gemspec +1 -0
- data/lib/hubstep/faraday/middleware.rb +15 -2
- data/lib/hubstep/internal/instrumenter/memory.rb +35 -0
- data/lib/hubstep/internal/instrumenter/noop.rb +16 -0
- data/lib/hubstep/tracer.rb +23 -11
- data/lib/hubstep/transport/http_json.rb +52 -0
- data/lib/hubstep/version.rb +1 -1
- data/lib/hubstep.rb +20 -0
- metadata +21 -2
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA1:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: f9f16b63e7a1bcb313327bc0ce955c9acd971b05
|
4
|
+
data.tar.gz: 392c2321669a3a307cd93018ca66c1690d55961d
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: fafcdc535bc8ff9b6ae00b462938585231ef12ba73cbe4c51ccc735d057635eda1f8ac8dd909965242e8f4bc624d5cd3562f16c22cd145764772176e9fd2abdd
|
7
|
+
data.tar.gz: 76fc1fbe37fae6b971cd86b6324b68ddc07f2d139a9a56097d0ae640e3ce54fad17a69656e081b7b63318d473d3895811abc88843a59407fad52059d566630f2
|
data/.rubocop.yml
CHANGED
data/.rubocop_todo.yml
ADDED
@@ -0,0 +1,11 @@
|
|
1
|
+
# This configuration was generated by
|
2
|
+
# `rubocop --auto-gen-config`
|
3
|
+
# on 2017-05-15 19:07:22 -0400 using RuboCop version 0.46.0.
|
4
|
+
# The point is for the user to remove these configuration records
|
5
|
+
# one by one as the offenses are removed from the code base.
|
6
|
+
# Note that changes in the inspected code, or installation of new
|
7
|
+
# versions of RuboCop, may require this file to be generated again.
|
8
|
+
|
9
|
+
# Offense count: 2
|
10
|
+
# Configuration parameters: AllowHeredoc, AllowURI, URISchemes, IgnoreCopDirectives, IgnoredPatterns.
|
11
|
+
# URISchemes: http, https
|
@@ -0,0 +1,30 @@
|
|
1
|
+
# Exclude violations in upstream code
|
2
|
+
|
3
|
+
# Offense count: 1
|
4
|
+
Metrics/AbcSize:
|
5
|
+
Max: 16
|
6
|
+
|
7
|
+
# Offense count: 1
|
8
|
+
# Configuration parameters: CountKeywordArgs.
|
9
|
+
Metrics/ParameterLists:
|
10
|
+
Max: 6
|
11
|
+
|
12
|
+
# Offense count: 1
|
13
|
+
Style/CaseEquality:
|
14
|
+
Exclude:
|
15
|
+
- 'lib/hubstep/transport/http_json.rb'
|
16
|
+
|
17
|
+
# Offense count: 1
|
18
|
+
# Cop supports --auto-correct.
|
19
|
+
# Configuration parameters: SupportedStyles, EnforcedStyleForEmptyBraces, SpaceBeforeBlockParameters.
|
20
|
+
# SupportedStyles: space, no_space
|
21
|
+
Style/SpaceInsideBlockBraces:
|
22
|
+
EnforcedStyle: space
|
23
|
+
|
24
|
+
# Offense count: 6
|
25
|
+
# Cop supports --auto-correct.
|
26
|
+
# Configuration parameters: EnforcedStyle, SupportedStyles, ConsistentQuotesInMultiline.
|
27
|
+
# SupportedStyles: single_quotes, double_quotes
|
28
|
+
Style/StringLiterals:
|
29
|
+
Exclude:
|
30
|
+
- 'lib/hubstep/transport/http_json.rb'
|
data/hubstep.gemspec
CHANGED
@@ -13,9 +13,17 @@ module HubStep
|
|
13
13
|
# b.adapter(:typhoeus)
|
14
14
|
# end
|
15
15
|
class Middleware < ::Faraday::Middleware
|
16
|
-
|
16
|
+
# Create a Middleware
|
17
|
+
#
|
18
|
+
# tracer - a HubStep::Tracer instance
|
19
|
+
# include_urls - Boolean specifying whether the `http.url` tag should be
|
20
|
+
# added to the spans this middleware creates. URLs can
|
21
|
+
# contain sensitive information, so they are omitted by
|
22
|
+
# default.
|
23
|
+
def initialize(app, tracer, include_urls: false)
|
17
24
|
super(app)
|
18
25
|
@tracer = tracer
|
26
|
+
@include_urls = include_urls
|
19
27
|
end
|
20
28
|
|
21
29
|
def call(request_env)
|
@@ -43,8 +51,13 @@ module HubStep
|
|
43
51
|
method = request_env[:method].to_s.upcase
|
44
52
|
span.operation_name = "Faraday #{method}"
|
45
53
|
span.set_tag("component", "faraday")
|
46
|
-
span.set_tag("http.url", request_env[:url])
|
47
54
|
span.set_tag("http.method", method)
|
55
|
+
|
56
|
+
url = request_env[:url]
|
57
|
+
span.set_tag("http.url", url) if @include_urls
|
58
|
+
|
59
|
+
uri = URI.parse(url.to_s)
|
60
|
+
span.set_tag("http.domain", uri.host)
|
48
61
|
end
|
49
62
|
|
50
63
|
def record_response(span, response_env)
|
@@ -0,0 +1,35 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
3
|
+
module HubStep
|
4
|
+
module Internal
|
5
|
+
module Instrumenter
|
6
|
+
# A memory instrumenter to be used in to test instrumentation. This class records
|
7
|
+
# each instrument call in a HubStep::Internal::Instrumenter::Memory::Event instance
|
8
|
+
# and stores the instance in an events array.
|
9
|
+
class Memory
|
10
|
+
class Event # rubocop:disable Style/Documentation
|
11
|
+
attr_reader :name, :payload, :result
|
12
|
+
|
13
|
+
def initialize(name, payload, result)
|
14
|
+
@name = name
|
15
|
+
@payload = payload
|
16
|
+
@result = result
|
17
|
+
end
|
18
|
+
end
|
19
|
+
|
20
|
+
def initialize
|
21
|
+
@events = []
|
22
|
+
end
|
23
|
+
|
24
|
+
attr_reader :events
|
25
|
+
|
26
|
+
def instrument(name, payload = {})
|
27
|
+
payload = payload.dup
|
28
|
+
result = (yield payload if block_given?)
|
29
|
+
@events << Event.new(name, payload, result)
|
30
|
+
result
|
31
|
+
end
|
32
|
+
end
|
33
|
+
end
|
34
|
+
end
|
35
|
+
end
|
@@ -0,0 +1,16 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
3
|
+
module HubStep
|
4
|
+
module Internal
|
5
|
+
module Instrumenter
|
6
|
+
# A noop instrumenter that fulfills the interface for ActiveSupport::Notifications
|
7
|
+
# but does nothing. This is the default instrumenter when the client does not pass
|
8
|
+
# one in
|
9
|
+
class Noop
|
10
|
+
def instrument(_name, payload = {})
|
11
|
+
yield payload if block_given?
|
12
|
+
end
|
13
|
+
end
|
14
|
+
end
|
15
|
+
end
|
16
|
+
end
|
data/lib/hubstep/tracer.rb
CHANGED
@@ -3,6 +3,7 @@
|
|
3
3
|
require "English"
|
4
4
|
require "lightstep"
|
5
5
|
require "singleton"
|
6
|
+
require "hubstep/transport/http_json"
|
6
7
|
|
7
8
|
module HubStep
|
8
9
|
# Tracer wraps LightStep::Tracer. It provides a block-based API for creating
|
@@ -11,10 +12,13 @@ module HubStep
|
|
11
12
|
class Tracer
|
12
13
|
# Create a Tracer.
|
13
14
|
#
|
14
|
-
# tags
|
15
|
-
#
|
16
|
-
# transport
|
17
|
-
|
15
|
+
# tags - Hash of tags to assign to the tracer. These will be
|
16
|
+
# associated with every span the tracer creates.
|
17
|
+
# transport - instance of a LightStep::Transport::Base subclass
|
18
|
+
# verbose - Whether or not to emit verbose spans, default true
|
19
|
+
def initialize(transport: default_transport, tags: {}, verbose: true)
|
20
|
+
@verbose = verbose
|
21
|
+
|
18
22
|
name = HubStep.server_metadata.values_at("app", "role").join("-")
|
19
23
|
|
20
24
|
default_tags = {
|
@@ -24,6 +28,7 @@ module HubStep
|
|
24
28
|
@tracer = LightStep::Tracer.new(component_name: name,
|
25
29
|
transport: transport,
|
26
30
|
tags: default_tags.merge(tags))
|
31
|
+
|
27
32
|
@spans = []
|
28
33
|
self.enabled = false
|
29
34
|
end
|
@@ -57,6 +62,10 @@ module HubStep
|
|
57
62
|
span || InertSpan.instance
|
58
63
|
end
|
59
64
|
|
65
|
+
def should_emit?(verbose)
|
66
|
+
@verbose || !verbose
|
67
|
+
end
|
68
|
+
|
60
69
|
# Record a span representing the execution of the given block
|
61
70
|
#
|
62
71
|
# operation_name - short human-readable String identifying the work done by the span
|
@@ -65,11 +74,14 @@ module HubStep
|
|
65
74
|
# finish - Boolean indicating whether to "finish" (i.e., record the
|
66
75
|
# span's end time and submit it to the collector).
|
67
76
|
# Defaults to true.
|
77
|
+
# verbose - Boolean indicating this is a ancilary span, only
|
78
|
+
# emitted when the tracer has verbose enabled, default
|
79
|
+
# false
|
68
80
|
#
|
69
81
|
# Yields a LightStep::Span or InertSpan to the block. Returns the block's
|
70
82
|
# return value.
|
71
|
-
def span(operation_name, start_time: nil, tags: nil, finish: true)
|
72
|
-
unless enabled?
|
83
|
+
def span(operation_name, start_time: nil, tags: nil, finish: true, verbose: false)
|
84
|
+
unless enabled? && should_emit?(verbose)
|
73
85
|
return yield InertSpan.instance
|
74
86
|
end
|
75
87
|
|
@@ -124,11 +136,11 @@ module HubStep
|
|
124
136
|
access_token = ENV["LIGHTSTEP_ACCESS_TOKEN"]
|
125
137
|
|
126
138
|
if host && port && encryption && access_token
|
127
|
-
|
128
|
-
|
129
|
-
|
130
|
-
|
131
|
-
|
139
|
+
HubStep::Transport::HTTPJSON.new(host: host,
|
140
|
+
port: port.to_i,
|
141
|
+
encryption: encryption,
|
142
|
+
verbose: verbosity,
|
143
|
+
access_token: access_token)
|
132
144
|
else
|
133
145
|
LightStep::Transport::Nil.new
|
134
146
|
end
|
@@ -0,0 +1,52 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
3
|
+
require "English"
|
4
|
+
require "net/http"
|
5
|
+
|
6
|
+
unless LightStep::VERSION == '0.10.9'
|
7
|
+
raise <<-MSG
|
8
|
+
This monkey patch needs to be reviewed for LightStep versions other than 0.10.9.
|
9
|
+
To review, diff the changes between the `LightStep::Transport::HTTPJSON#report`
|
10
|
+
method and the `HubStep::Transport::HTTPJSON#report` method below and port any
|
11
|
+
changes that seem necessary.
|
12
|
+
MSG
|
13
|
+
end
|
14
|
+
|
15
|
+
module HubStep
|
16
|
+
module Transport
|
17
|
+
# HTTPJSON is a transport that sends reports via HTTP in JSON format.
|
18
|
+
# It is thread-safe, however it is *not* fork-safe. When forking, all items
|
19
|
+
# in the queue will be copied and sent in duplicate.
|
20
|
+
#
|
21
|
+
# When forking, you should first `disable` the tracer, then `enable` it from
|
22
|
+
# within the fork (and in the parent post-fork). See
|
23
|
+
# `examples/fork_children/main.rb` for an example.
|
24
|
+
class HTTPJSON < LightStep::Transport::HTTPJSON
|
25
|
+
# Queue a report for sending
|
26
|
+
def report(report) # rubocop:disable Metrics/AbcSize,Metrics/MethodLength
|
27
|
+
p report if @verbose >= 3
|
28
|
+
|
29
|
+
HubStep.instrumenter.instrument('lightstep.transport.report', {}) do |payload|
|
30
|
+
https = Net::HTTP.new(@host, @port)
|
31
|
+
https.use_ssl = @encryption == ENCRYPTION_TLS
|
32
|
+
req = Net::HTTP::Post.new('/api/v0/reports')
|
33
|
+
req['LightStep-Access-Token'] = @access_token
|
34
|
+
req['Content-Type'] = 'application/json'
|
35
|
+
req['Connection'] = 'keep-alive'
|
36
|
+
req.body = report.to_json
|
37
|
+
res = https.request(req)
|
38
|
+
|
39
|
+
payload[:request_body] = req.body
|
40
|
+
|
41
|
+
puts res.to_s, res.body if @verbose >= 3
|
42
|
+
|
43
|
+
payload[:response] = res
|
44
|
+
end
|
45
|
+
|
46
|
+
nil
|
47
|
+
rescue => e
|
48
|
+
HubStep.instrumenter.instrument('lightstep.transport.error', error: e)
|
49
|
+
end
|
50
|
+
end
|
51
|
+
end
|
52
|
+
end
|
data/lib/hubstep/version.rb
CHANGED
data/lib/hubstep.rb
CHANGED
@@ -1,6 +1,7 @@
|
|
1
1
|
# frozen_string_literal: true
|
2
2
|
|
3
3
|
require "hubstep/tracer"
|
4
|
+
require "hubstep/internal/instrumenter/noop"
|
4
5
|
require "hubstep/version"
|
5
6
|
|
6
7
|
require "socket"
|
@@ -26,4 +27,23 @@ module HubStep
|
|
26
27
|
{}.freeze
|
27
28
|
end
|
28
29
|
end
|
30
|
+
|
31
|
+
# setter for instrumenter that defaults to the Noop instrumenter
|
32
|
+
#
|
33
|
+
# instrumenter - an object that responds to the ActiveSupport::Notifications
|
34
|
+
# interface, when omitted the Noop instrumenter will be used
|
35
|
+
#
|
36
|
+
def self.instrumenter=(instrumenter)
|
37
|
+
@instrumenter = instrumenter
|
38
|
+
end
|
39
|
+
|
40
|
+
# getter for the instrumenter ivar. When the ivar isn't set it will
|
41
|
+
# default to the Noop instrumenter
|
42
|
+
#
|
43
|
+
# instrumenter - an object that responds to the ActiveSupport::Notifications
|
44
|
+
# interface, when omitted the Noop instrumenter will be used
|
45
|
+
#
|
46
|
+
def self.instrumenter(instrumenter: nil)
|
47
|
+
@instrumenter ||= (instrumenter || HubStep::Internal::Instrumenter::Noop.new)
|
48
|
+
end
|
29
49
|
end
|
metadata
CHANGED
@@ -1,14 +1,14 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: hubstep
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 2.0.
|
4
|
+
version: 2.0.3
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- GitHub
|
8
8
|
autorequire:
|
9
9
|
bindir: exe
|
10
10
|
cert_chain: []
|
11
|
-
date: 2017-
|
11
|
+
date: 2017-10-11 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: lightstep
|
@@ -164,6 +164,20 @@ dependencies:
|
|
164
164
|
- - ">="
|
165
165
|
- !ruby/object:Gem::Version
|
166
166
|
version: '0'
|
167
|
+
- !ruby/object:Gem::Dependency
|
168
|
+
name: mocha
|
169
|
+
requirement: !ruby/object:Gem::Requirement
|
170
|
+
requirements:
|
171
|
+
- - "~>"
|
172
|
+
- !ruby/object:Gem::Version
|
173
|
+
version: 1.2.1
|
174
|
+
type: :development
|
175
|
+
prerelease: false
|
176
|
+
version_requirements: !ruby/object:Gem::Requirement
|
177
|
+
requirements:
|
178
|
+
- - "~>"
|
179
|
+
- !ruby/object:Gem::Version
|
180
|
+
version: 1.2.1
|
167
181
|
description: Makes it easy to trace Sinatra and Ruby apps that use GitHub conventions.
|
168
182
|
email:
|
169
183
|
- engineering@github.com
|
@@ -173,6 +187,8 @@ extra_rdoc_files: []
|
|
173
187
|
files:
|
174
188
|
- ".gitignore"
|
175
189
|
- ".rubocop.yml"
|
190
|
+
- ".rubocop_todo.yml"
|
191
|
+
- ".rubocop_upstream.yml"
|
176
192
|
- ".ruby-version"
|
177
193
|
- ".travis.yml"
|
178
194
|
- CODE_OF_CONDUCT.md
|
@@ -186,8 +202,11 @@ files:
|
|
186
202
|
- lib/hubstep/failbot.rb
|
187
203
|
- lib/hubstep/faraday/middleware.rb
|
188
204
|
- lib/hubstep/instrumenter.rb
|
205
|
+
- lib/hubstep/internal/instrumenter/memory.rb
|
206
|
+
- lib/hubstep/internal/instrumenter/noop.rb
|
189
207
|
- lib/hubstep/rack/middleware.rb
|
190
208
|
- lib/hubstep/tracer.rb
|
209
|
+
- lib/hubstep/transport/http_json.rb
|
191
210
|
- lib/hubstep/version.rb
|
192
211
|
- script/bootstrap
|
193
212
|
- script/console
|