lightstep 0.12.0 → 0.13.0

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: 4061236d2e72a5a8af39a92ee36074193a9dfe0bd48032cdecdfcc3d01054557
4
- data.tar.gz: ff20651fafa157cfeeecc789c73fb4a0c5dc4abbe910ef048625a39286251f6f
3
+ metadata.gz: 412b678787b505c5c97155f3d702adf01e8ebd60254fb793a07e8ae4da2cd7fa
4
+ data.tar.gz: bdd33820334d2306ce78b7e84928e4be5193211d0c359bba02b4032ed3c6fc42
5
5
  SHA512:
6
- metadata.gz: 0f7b6a24656af8708d935b7afa2e47f5f7ee3fcd768518679450326140b6ead0ef1191718a487f3bed035eec99f8a263edc1d04b1fb18ea9c05b126ad23a0f88
7
- data.tar.gz: 23bb222bae518baa0bf4151883b9cc525cc6226d485fff7bce7cc13c12b4d7ea3a41821ba30bec0f7a19438b1a2bed039aabed27a947799613f9cf91e8eaff6b
6
+ metadata.gz: 8d1395123221d74ce722e748dc21951f8462103dd505edc42f3f04c32f3f9eed524358a684085cb8ba55acd35dc3909102447cb0133700f8b91016687bf0ba00
7
+ data.tar.gz: 597593ee87d988b10f9c79fc80ddfa5e4b3f05290e5033873aeb1e7655d6562dacb5f81410a3d0db62d2a418958e9165557e17f062f188db4602c2e3c09a0b44
@@ -0,0 +1,31 @@
1
+ version: 2
2
+
3
+ jobs:
4
+ test:
5
+ docker:
6
+ - image: circleci/ruby:2
7
+ steps:
8
+ - checkout
9
+ - restore_cache:
10
+ keys:
11
+ - gem-cache-v2-{{ .Branch }}-{{ checksum "Gemfile.lock" }}
12
+ - gem-cache-v2-{{ .Branch }}-
13
+ - gem-cache-v2-
14
+ - run:
15
+ name: "set up environment"
16
+ command: |
17
+ echo 'export BUNDLE_PATH="$HOME/project/.bundler_cache"' >> $BASH_ENV
18
+ source $BASH_ENV
19
+ - run: bundle
20
+ - save_cache:
21
+ paths:
22
+ - ~/project/.bundler_cache
23
+ key: gem-cache-v2-{{ .Branch }}-{{ checksum "Gemfile.lock" }}
24
+ - run: make test
25
+
26
+ workflows:
27
+ version: 2
28
+ test:
29
+ jobs:
30
+ - test
31
+
data/.gitignore CHANGED
@@ -1,6 +1,5 @@
1
1
  .bundle/
2
2
  .yardoc
3
- Gemfile.lock
4
3
  _yardoc/
5
4
  coverage/
6
5
  /doc/
@@ -8,6 +7,5 @@ coverage/
8
7
  /spec/reports/
9
8
  /tmp/
10
9
  *~
11
- Gemfile.lock
12
10
  lightstep-tracer*.gem
13
11
  lightstep*.gem
@@ -0,0 +1,48 @@
1
+ AllCops:
2
+ Exclude:
3
+ - spec/**/*
4
+ - .bundle/**/*
5
+ - bin/**/*
6
+ - vendor/**/*
7
+ - tmp/**/*
8
+ - log/**/*
9
+ - Rakefile
10
+ - lightstep.gemspec
11
+
12
+ Lint/AmbiguousOperator:
13
+ Enabled: false
14
+
15
+ Metrics/ParameterLists:
16
+ Enabled: false
17
+
18
+ Metrics/AbcSize:
19
+ Max: 147
20
+
21
+ Metrics/BlockNesting:
22
+ Max: 4
23
+
24
+ # Configuration parameters: CountComments.
25
+ Metrics/ClassLength:
26
+ Max: 406
27
+
28
+ Metrics/CyclomaticComplexity:
29
+ Max: 24
30
+
31
+ # Configuration parameters: AllowHeredoc, AllowURI, URISchemes.
32
+ # URISchemes: http, https
33
+ Metrics/LineLength:
34
+ Enabled: false
35
+
36
+ # Configuration parameters: CountComments.
37
+ Metrics/MethodLength:
38
+ Max: 88
39
+
40
+ # Configuration parameters: CountComments.
41
+ Metrics/ModuleLength:
42
+ Max: 1000
43
+
44
+ Performance/RedundantBlockCall:
45
+ Enabled: false
46
+
47
+ Style/PercentLiteralDelimiters:
48
+ Enabled: false
@@ -0,0 +1,52 @@
1
+ PATH
2
+ remote: .
3
+ specs:
4
+ lightstep (0.13.0)
5
+ concurrent-ruby (~> 1.0)
6
+ opentracing (~> 0.4.1)
7
+
8
+ GEM
9
+ remote: https://rubygems.org/
10
+ specs:
11
+ bump (0.6.1)
12
+ concurrent-ruby (1.0.5)
13
+ diff-lcs (1.3)
14
+ docile (1.3.1)
15
+ json (2.1.0)
16
+ opentracing (0.4.1)
17
+ rack (2.0.5)
18
+ rake (11.3.0)
19
+ rspec (3.7.0)
20
+ rspec-core (~> 3.7.0)
21
+ rspec-expectations (~> 3.7.0)
22
+ rspec-mocks (~> 3.7.0)
23
+ rspec-core (3.7.1)
24
+ rspec-support (~> 3.7.0)
25
+ rspec-expectations (3.7.0)
26
+ diff-lcs (>= 1.2.0, < 2.0)
27
+ rspec-support (~> 3.7.0)
28
+ rspec-mocks (3.7.0)
29
+ diff-lcs (>= 1.2.0, < 2.0)
30
+ rspec-support (~> 3.7.0)
31
+ rspec-support (3.7.1)
32
+ simplecov (0.16.1)
33
+ docile (~> 1.1)
34
+ json (>= 1.8, < 3)
35
+ simplecov-html (~> 0.10.0)
36
+ simplecov-html (0.10.2)
37
+ timecop (0.8.1)
38
+
39
+ PLATFORMS
40
+ ruby
41
+
42
+ DEPENDENCIES
43
+ bump (~> 0.5)
44
+ lightstep!
45
+ rack (~> 2.0)
46
+ rake (~> 11.3)
47
+ rspec (~> 3.0)
48
+ simplecov (~> 0.16)
49
+ timecop (~> 0.8.0)
50
+
51
+ BUNDLED WITH
52
+ 1.16.6
data/Makefile CHANGED
@@ -14,8 +14,8 @@ benchmark:
14
14
  ruby benchmark/threading/thread_test.rb
15
15
 
16
16
  bump-version:
17
- # ruby -e 'require "bump"; Bump::Bump.run("minor")'
18
- # make build # rebuild after version increment
17
+ # ruby -e 'require "bump"; Bump::Bump.run("patch")'
18
+ make build # rebuild after version increment
19
19
  git tag `ruby scripts/version.rb`
20
20
  # git push
21
21
  git push --tags
data/example.rb CHANGED
@@ -11,7 +11,7 @@ LightStep.configure(component_name: 'lightstep/ruby/example', access_token: acce
11
11
  puts 'Starting operation...'
12
12
  span = LightStep.start_span('my_span')
13
13
  thread1 = Thread.new do
14
- for i in 1..10
14
+ (1..10).each do |i|
15
15
  sleep(0.15)
16
16
  puts "Logging event #{i}..."
17
17
  span.log(event: 'hello world', count: i)
@@ -19,7 +19,7 @@ thread1 = Thread.new do
19
19
  end
20
20
  thread2 = Thread.new do
21
21
  current = 1
22
- for i in 1..16
22
+ (1..16).each do |i|
23
23
  child = LightStep.start_span('my_child', child_of: span.span_context)
24
24
  sleep(0.1)
25
25
  current *= 2
@@ -60,7 +60,7 @@ end
60
60
 
61
61
  loop do
62
62
  begin
63
- p Net::HTTP.get(URI("http://localhost:9001/"))
63
+ p Net::HTTP.get(URI("http://127.0.0.1:9001/"))
64
64
  break
65
65
  rescue Errno::ECONNREFUSED
66
66
  sleep 0.05
@@ -45,3 +45,5 @@ end
45
45
 
46
46
  require 'lightstep/tracer'
47
47
  require 'lightstep/global_tracer'
48
+ require 'lightstep/scope'
49
+ require 'lightstep/scope_manager'
@@ -57,7 +57,10 @@ module LightStep
57
57
 
58
58
  span_records = @span_records.slice!(0, @span_records.length)
59
59
  dropped_spans = 0
60
- @dropped_spans.update{|old| dropped_spans = old; 0 }
60
+ @dropped_spans.update do |old|
61
+ dropped_spans = old
62
+ 0
63
+ end
61
64
 
62
65
  report_request = {
63
66
  runtime: @runtime,
@@ -65,9 +68,10 @@ module LightStep
65
68
  youngest_micros: now,
66
69
  span_records: span_records,
67
70
  internal_metrics: {
68
- counts: [
69
- {name: "spans.dropped", int64_value: dropped_spans},
70
- ]
71
+ counts: [{
72
+ name: 'spans.dropped',
73
+ int64_value: dropped_spans
74
+ }]
71
75
  }
72
76
  }
73
77
 
@@ -75,9 +79,10 @@ module LightStep
75
79
 
76
80
  begin
77
81
  @transport.report(report_request)
78
- rescue
79
- # an error occurs, add the previous dropped_spans and count of spans
80
- # that would have been recorded
82
+ rescue StandardError => e
83
+ LightStep.logger.error "LightStep error reporting to collector: #{e.message}"
84
+ # an error occurs, add the previous dropped_spans and count of spans
85
+ # that would have been recorded
81
86
  @dropped_spans.increment(dropped_spans + span_records.length)
82
87
  end
83
88
  end
@@ -103,8 +108,8 @@ module LightStep
103
108
  sleep(@period)
104
109
  flush
105
110
  end
106
- rescue => ex
107
- # TODO: internally log the exception
111
+ rescue StandardError => e
112
+ LightStep.logger.error "LightStep failed to report spans: #{e.message}"
108
113
  end
109
114
  end
110
115
  end
@@ -0,0 +1,23 @@
1
+ module LightStep
2
+ # Scope represents an OpenTracing Scope
3
+ #
4
+ # See http://www.opentracing.io for more information.
5
+ class Scope
6
+ attr_reader :span
7
+
8
+ def initialize(manager:, span:, finish_on_close: true)
9
+ @manager = manager
10
+ @span = span
11
+ @finish_on_close = finish_on_close
12
+ end
13
+
14
+ # Mark the end of the active period for the current thread and Scope,
15
+ # updating the ScopeManager#active in the process.
16
+ def close
17
+ raise(LightStep::Error, 'already closed') if @closed
18
+ @closed = true
19
+ @span.finish if @finish_on_close
20
+ @manager.deactivate
21
+ end
22
+ end
23
+ end
@@ -0,0 +1,54 @@
1
+ module LightStep
2
+ # ScopeManager represents an OpenTracing ScopeManager
3
+ #
4
+ # See http://www.opentracing.io for more information.
5
+ #
6
+ # The ScopeManager interface abstracts both the activation of Span instances
7
+ # via ScopeManager#activate and access to an active Span/Scope via
8
+ # ScopeManager#active
9
+ #
10
+ class ScopeManager
11
+ # Make a span instance active.
12
+ #
13
+ # @param span [Span] the Span that should become active
14
+ # @param finish_on_close [Boolean] whether the Span should automatically be
15
+ # finished when Scope#close is called
16
+ # @return [Scope] instance to control the end of the active period for the
17
+ # Span. It is a programming error to neglect to call Scope#close on the
18
+ # returned instance.
19
+ def activate(span:, finish_on_close: true)
20
+ return active if active && active.span == span
21
+ LightStep::Scope.new(manager: self, span: span, finish_on_close: finish_on_close).tap do |scope|
22
+ add_scope(scope)
23
+ end
24
+ end
25
+
26
+ # @return [Scope] the currently active Scope which can be used to access the
27
+ # currently active Span.
28
+ #
29
+ # If there is a non-null Scope, its wrapped Span becomes an implicit parent
30
+ # (as Reference#CHILD_OF) of any newly-created Span at Tracer#start_active_span
31
+ # or Tracer#start_span time.
32
+ def active
33
+ scopes.last
34
+ end
35
+
36
+ def deactivate
37
+ scopes.pop
38
+ end
39
+
40
+ private
41
+
42
+ def scopes
43
+ Thread.current[object_id.to_s] || []
44
+ end
45
+
46
+ def add_scope(scope)
47
+ if Thread.current[object_id.to_s].nil?
48
+ Thread.current[object_id.to_s] = [scope]
49
+ else
50
+ Thread.current[object_id.to_s] << scope
51
+ end
52
+ end
53
+ end
54
+ end
@@ -11,7 +11,10 @@ module LightStep
11
11
 
12
12
  # Internal use only
13
13
  # @private
14
- attr_reader :start_micros, :end_micros, :tags, :operation_name, :span_context
14
+ attr_reader :start_micros, :end_micros, :tags, :operation_name, :context
15
+
16
+ # To keep backwards compatibility
17
+ alias_method :span_context, :context
15
18
 
16
19
  # Creates a new {Span}
17
20
  #
@@ -37,6 +40,7 @@ module LightStep
37
40
  tags: nil,
38
41
  max_log_records:
39
42
  )
43
+
40
44
  @tags = Concurrent::Hash.new
41
45
  @tags.update(tags) unless tags.nil?
42
46
  @log_records = Concurrent::Array.new
@@ -49,14 +53,14 @@ module LightStep
49
53
 
50
54
  ref = child_of ? child_of : references
51
55
  ref = ref[0] if (Array === ref)
52
- ref = ref.span_context if (Span === ref)
56
+ ref = ref.context if (Span === ref)
53
57
 
54
58
  if SpanContext === ref
55
- @span_context = SpanContext.new(id: LightStep.guid, trace_id: ref.trace_id)
59
+ @context = SpanContext.new(id: LightStep.guid, trace_id: ref.trace_id)
56
60
  set_baggage(ref.baggage)
57
61
  set_tag(:parent_span_guid, ref.id)
58
62
  else
59
- @span_context = SpanContext.new(id: LightStep.guid, trace_id: LightStep.guid)
63
+ @context = SpanContext.new(id: LightStep.guid, trace_id: LightStep.guid)
60
64
  end
61
65
  end
62
66
 
@@ -76,10 +80,10 @@ module LightStep
76
80
  # @param key [String] the key of the baggage item
77
81
  # @param value [String] the value of the baggage item
78
82
  def set_baggage_item(key, value)
79
- @span_context = SpanContext.new(
80
- id: span_context.id,
81
- trace_id: span_context.trace_id,
82
- baggage: span_context.baggage.merge({key => value})
83
+ @context = SpanContext.new(
84
+ id: context.id,
85
+ trace_id: context.trace_id,
86
+ baggage: context.baggage.merge({key => value})
83
87
  )
84
88
  self
85
89
  end
@@ -87,9 +91,9 @@ module LightStep
87
91
  # Set all baggage at once. This will reset the baggage to the given param.
88
92
  # @param baggage [Hash] new baggage for the span
89
93
  def set_baggage(baggage = {})
90
- @span_context = SpanContext.new(
91
- id: span_context.id,
92
- trace_id: span_context.trace_id,
94
+ @context = SpanContext.new(
95
+ id: context.id,
96
+ trace_id: context.trace_id,
93
97
  baggage: baggage
94
98
  )
95
99
  end
@@ -98,7 +102,7 @@ module LightStep
98
102
  # @param key [String] the key of the baggage item
99
103
  # @return Value of the baggage item
100
104
  def get_baggage_item(key)
101
- span_context.baggage[key]
105
+ context.baggage[key]
102
106
  end
103
107
 
104
108
  # Add a log entry to this span
@@ -140,8 +144,8 @@ module LightStep
140
144
  def to_h
141
145
  {
142
146
  runtime_guid: tracer.guid,
143
- span_guid: span_context.id,
144
- trace_guid: span_context.trace_id,
147
+ span_guid: context.id,
148
+ trace_guid: context.trace_id,
145
149
  span_name: operation_name,
146
150
  attributes: tags.map {|key, value|
147
151
  {Key: key.to_s, Value: value}
@@ -53,6 +53,78 @@ module LightStep
53
53
 
54
54
  # TODO(bhs): Support FollowsFrom and multiple references
55
55
 
56
+ # Creates a scope manager or returns the already-created one.
57
+ #
58
+ # @return [ScopeManager] the current ScopeManager, which may be a no-op but
59
+ # may not be nil.
60
+ def scope_manager
61
+ @scope_manager ||= LightStep::ScopeManager.new
62
+ end
63
+
64
+ # Returns a newly started and activated Scope.
65
+ #
66
+ # If ScopeManager#active is not nil, no explicit references are provided,
67
+ # and `ignore_active_scope` is false, then an inferred References#CHILD_OF
68
+ # reference is created to the ScopeManager#active's SpanContext when
69
+ # start_active_span is invoked.
70
+ #
71
+ # @param operation_name [String] The operation name for the Span
72
+ # @param child_of [SpanContext, Span] SpanContext that acts as a parent to
73
+ # the newly-started Span. If a Span instance is provided, its
74
+ # context is automatically substituted. See [Reference] for more
75
+ # information.
76
+ #
77
+ # If specified, the `references` parameter must be omitted.
78
+ # @param references [Array<Reference>] An array of reference
79
+ # objects that identify one or more parent SpanContexts.
80
+ # @param start_time [Time] When the Span started, if not now
81
+ # @param tags [Hash] Tags to assign to the Span at start time
82
+ # @param ignore_active_scope [Boolean] whether to create an implicit
83
+ # References#CHILD_OF reference to the ScopeManager#active.
84
+ # @param finish_on_close [Boolean] whether span should automatically be
85
+ # finished when Scope#close is called
86
+ # @yield [Scope] If an optional block is passed to start_active it will
87
+ # yield the newly-started Scope. If `finish_on_close` is true then the
88
+ # Span will be finished automatically after the block is executed.
89
+ # @return [Scope] The newly-started and activated Scope
90
+ def start_active_span(operation_name,
91
+ child_of: nil,
92
+ references: nil,
93
+ start_time: Time.now,
94
+ tags: nil,
95
+ ignore_active_scope: false,
96
+ finish_on_close: true)
97
+ if child_of.nil? && references.nil? && !ignore_active_scope
98
+ child_of = active_span
99
+ end
100
+
101
+ span = start_span(
102
+ operation_name,
103
+ child_of: child_of,
104
+ references: references,
105
+ start_time: start_time,
106
+ tags: tags,
107
+ ignore_active_scope: ignore_active_scope
108
+ )
109
+
110
+ scope_manager.activate(span: span, finish_on_close: finish_on_close).tap do |scope|
111
+ if block_given?
112
+ yield scope
113
+ scope.close
114
+ end
115
+ end
116
+ end
117
+
118
+ # Returns the span from the active scope, if any.
119
+ #
120
+ # @return [Span, nil] the active span. This is a shorthand for
121
+ # `scope_manager.active.span`, and nil will be returned if
122
+ # Scope#active is nil.
123
+ def active_span
124
+ scope = scope_manager.active
125
+ scope.span if scope
126
+ end
127
+
56
128
  # Starts a new span.
57
129
  #
58
130
  # @param operation_name [String] The operation name for the Span
@@ -64,8 +136,13 @@ module LightStep
64
136
  # are provided, their .span_context is automatically substituted.
65
137
  # @param start_time [Time] When the Span started, if not now
66
138
  # @param tags [Hash] Tags to assign to the Span at start time
139
+ # @param ignore_active_scope [Boolean] whether to create an implicit
140
+ # References#CHILD_OF reference to the ScopeManager#active.
67
141
  # @return [Span]
68
- def start_span(operation_name, child_of: nil, references: [], start_time: nil, tags: nil)
142
+ def start_span(operation_name, child_of: nil, references: nil, start_time: nil, tags: nil, ignore_active_scope: false)
143
+ if child_of.nil? && references.nil? && !ignore_active_scope
144
+ child_of = active_span
145
+ end
69
146
 
70
147
  Span.new(
71
148
  tracer: self,
@@ -150,7 +227,7 @@ module LightStep
150
227
  protected
151
228
 
152
229
  def configure(component_name:, access_token: nil, transport: nil, tags: {})
153
- raise ConfigurationError, "component_name must be a string" unless String === component_name
230
+ raise ConfigurationError, "component_name must be a string" unless component_name.is_a?(String)
154
231
  raise ConfigurationError, "component_name cannot be blank" if component_name.empty?
155
232
 
156
233
  if transport.nil? and !access_token.nil?
@@ -234,7 +311,7 @@ module LightStep
234
311
  def extract_from_rack(env)
235
312
  extract_from_text_map(env.reduce({}){|memo, tuple|
236
313
  raw_header, value = tuple
237
- header = raw_header.gsub(/^HTTP_/, '').gsub("_", "-").downcase
314
+ header = raw_header.gsub(/^HTTP_/, '').tr('_', '-').downcase
238
315
 
239
316
  memo[header] = value if header.start_with?(CARRIER_TRACER_STATE_PREFIX, CARRIER_BAGGAGE_PREFIX)
240
317
  memo
@@ -2,9 +2,6 @@ module LightStep
2
2
  module Transport
3
3
  # Base Transport type
4
4
  class Base
5
- def initialize
6
- end
7
-
8
5
  def report(_report)
9
6
  nil
10
7
  end
@@ -11,46 +11,102 @@ module LightStep
11
11
  # within the fork (and in the parent post-fork). See
12
12
  # `examples/fork_children/main.rb` for an example.
13
13
  class HTTPJSON < Base
14
- LIGHTSTEP_HOST = "collector.lightstep.com"
14
+ LIGHTSTEP_HOST = 'collector.lightstep.com'.freeze
15
15
  LIGHTSTEP_PORT = 443
16
16
 
17
- ENCRYPTION_TLS = 'tls'
18
- ENCRYPTION_NONE = 'none'
17
+ ENCRYPTION_TLS = 'tls'.freeze
18
+ ENCRYPTION_NONE = 'none'.freeze
19
19
 
20
+ REPORTS_API_ENDPOINT = '/api/v0/reports'.freeze
21
+ HEADER_ACCESS_TOKEN = 'LightStep-Access-Token'.freeze
22
+
23
+ ##
20
24
  # Initialize the transport
21
- # @param host [String] host of the domain to the endpoind to push data
25
+ #
26
+ # @param host [String] host of the domain to the endpoint to push data
22
27
  # @param port [Numeric] port on which to connect
23
28
  # @param verbose [Numeric] verbosity level. Right now 0-3 are supported
24
29
  # @param encryption [ENCRYPTION_TLS, ENCRYPTION_NONE] kind of encryption to use
25
30
  # @param access_token [String] access token for LightStep server
26
- # @return [HTTPJSON]
27
- def initialize(host: LIGHTSTEP_HOST, port: LIGHTSTEP_PORT, verbose: 0, encryption: ENCRYPTION_TLS, access_token:)
31
+ # @param ssl_verify_peer [Boolean]
32
+ # @param open_timeout [Integer]
33
+ # @param read_timeout [Integer]
34
+ # @param continue_timeout [Integer]
35
+ # @param keep_alive_timeout [Integer]
36
+ # @param logger [Logger]
37
+ #
38
+ def initialize(
39
+ host: LIGHTSTEP_HOST,
40
+ port: LIGHTSTEP_PORT,
41
+ verbose: 0,
42
+ encryption: ENCRYPTION_TLS,
43
+ access_token:,
44
+ ssl_verify_peer: true,
45
+ open_timeout: 20,
46
+ read_timeout: 20,
47
+ continue_timeout: nil,
48
+ keep_alive_timeout: 2,
49
+ logger: nil
50
+ )
28
51
  @host = host
29
52
  @port = port
30
53
  @verbose = verbose
31
54
  @encryption = encryption
55
+ @ssl_verify_peer = ssl_verify_peer
56
+ @open_timeout = open_timeout.to_i
57
+ @read_timeout = read_timeout.to_i
58
+ @continue_timeout = continue_timeout
59
+ @keep_alive_timeout = keep_alive_timeout.to_i
32
60
 
33
- raise Tracer::ConfigurationError, "access_token must be a string" unless String === access_token
34
- raise Tracer::ConfigurationError, "access_token cannot be blank" if access_token.empty?
61
+ raise Tracer::ConfigurationError, 'access_token must be a string' unless access_token.is_a?(String)
62
+ raise Tracer::ConfigurationError, 'access_token cannot be blank' if access_token.empty?
35
63
  @access_token = access_token
64
+ @logger = logger || LightStep.logger
36
65
  end
37
66
 
67
+ ##
38
68
  # Queue a report for sending
69
+ #
39
70
  def report(report)
40
- p report if @verbose >= 3
71
+ @logger.info report if @verbose >= 3
72
+
73
+ req = build_request(report)
74
+ res = connection.request(req)
75
+
76
+ @logger.info res.to_s if @verbose >= 3
77
+
78
+ nil
79
+ end
80
+
81
+ private
41
82
 
42
- https = Net::HTTP.new(@host, @port)
43
- https.use_ssl = @encryption == ENCRYPTION_TLS
44
- req = Net::HTTP::Post.new('/api/v0/reports')
45
- req['LightStep-Access-Token'] = @access_token
83
+ ##
84
+ # @param [Hash] report
85
+ # @return [Net::HTTP::Post]
86
+ #
87
+ def build_request(report)
88
+ req = Net::HTTP::Post.new(REPORTS_API_ENDPOINT)
89
+ req[HEADER_ACCESS_TOKEN] = @access_token
46
90
  req['Content-Type'] = 'application/json'
47
91
  req['Connection'] = 'keep-alive'
48
92
  req.body = report.to_json
49
- res = https.request(req)
50
-
51
- puts res.to_s if @verbose >= 3
93
+ req
94
+ end
52
95
 
53
- nil
96
+ ##
97
+ # @return [Net::HTTP]
98
+ #
99
+ def connection
100
+ unless @connection
101
+ @connection = ::Net::HTTP.new(@host, @port)
102
+ @connection.use_ssl = @encryption == ENCRYPTION_TLS
103
+ @connection.verify_mode = ::OpenSSL::SSL::VERIFY_NONE unless @ssl_verify_peer
104
+ @connection.open_timeout = @open_timeout
105
+ @connection.read_timeout = @read_timeout
106
+ @connection.continue_timeout = @continue_timeout
107
+ @connection.keep_alive_timeout = @keep_alive_timeout
108
+ end
109
+ @connection
54
110
  end
55
111
  end
56
112
  end
@@ -1,3 +1,3 @@
1
1
  module LightStep
2
- VERSION = '0.12.0'.freeze
2
+ VERSION = '0.13.0'.freeze
3
3
  end
@@ -17,11 +17,11 @@ Gem::Specification.new do |spec|
17
17
  spec.require_paths = ['lib']
18
18
 
19
19
  spec.add_dependency 'concurrent-ruby', '~> 1.0'
20
- spec.add_dependency 'opentracing', '~> 0.3'
20
+ spec.add_dependency 'opentracing', '~> 0.4.1'
21
21
  spec.add_development_dependency 'rake', '~> 11.3'
22
22
  spec.add_development_dependency 'rack', '~> 2.0'
23
23
  spec.add_development_dependency 'rspec', '~> 3.0'
24
24
  spec.add_development_dependency 'bump', '~> 0.5'
25
- spec.add_development_dependency 'simplecov', '~> 0.12.0'
25
+ spec.add_development_dependency 'simplecov', '~> 0.16'
26
26
  spec.add_development_dependency 'timecop', '~> 0.8.0'
27
27
  end
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: lightstep
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.12.0
4
+ version: 0.13.0
5
5
  platform: ruby
6
6
  authors:
7
7
  - bcronin
8
8
  autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
- date: 2018-07-30 00:00:00.000000000 Z
11
+ date: 2018-10-18 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: concurrent-ruby
@@ -30,14 +30,14 @@ dependencies:
30
30
  requirements:
31
31
  - - "~>"
32
32
  - !ruby/object:Gem::Version
33
- version: '0.3'
33
+ version: 0.4.1
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.3'
40
+ version: 0.4.1
41
41
  - !ruby/object:Gem::Dependency
42
42
  name: rake
43
43
  requirement: !ruby/object:Gem::Requirement
@@ -100,14 +100,14 @@ dependencies:
100
100
  requirements:
101
101
  - - "~>"
102
102
  - !ruby/object:Gem::Version
103
- version: 0.12.0
103
+ version: '0.16'
104
104
  type: :development
105
105
  prerelease: false
106
106
  version_requirements: !ruby/object:Gem::Requirement
107
107
  requirements:
108
108
  - - "~>"
109
109
  - !ruby/object:Gem::Version
110
- version: 0.12.0
110
+ version: '0.16'
111
111
  - !ruby/object:Gem::Dependency
112
112
  name: timecop
113
113
  requirement: !ruby/object:Gem::Requirement
@@ -129,9 +129,12 @@ executables: []
129
129
  extensions: []
130
130
  extra_rdoc_files: []
131
131
  files:
132
+ - ".circleci/config.yml"
132
133
  - ".gitignore"
133
134
  - ".rspec"
135
+ - ".rubocop.yml"
134
136
  - Gemfile
137
+ - Gemfile.lock
135
138
  - LICENSE.txt
136
139
  - Makefile
137
140
  - README.md
@@ -149,6 +152,8 @@ files:
149
152
  - lib/lightstep.rb
150
153
  - lib/lightstep/global_tracer.rb
151
154
  - lib/lightstep/reporter.rb
155
+ - lib/lightstep/scope.rb
156
+ - lib/lightstep/scope_manager.rb
152
157
  - lib/lightstep/span.rb
153
158
  - lib/lightstep/span_context.rb
154
159
  - lib/lightstep/tracer.rb