opentracing 0.4.0 → 0.4.1

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.
@@ -5,4 +5,4 @@ rvm:
5
5
  - 2.4.1
6
6
  - jruby-9.1.8.0
7
7
  before_install: gem install bundler -v 1.13.6
8
- script: JRUBY_OPTS="--debug" bundle exec rake test
8
+ script: JRUBY_OPTS="--debug" bundle exec rake
@@ -1,5 +1,14 @@
1
1
  # Changelog
2
2
 
3
+ ## Master
4
+
5
+ ## 0.4.1
6
+
7
+ * Add active_span convenience method to OpenTracing module ([#30](https://github.com/opentracing/opentracing-ruby/pull/30))
8
+ * Fix global tracer delegators ([#28](https://github.com/opentracing/opentracing-ruby/pull/28))
9
+ * Add Rubocop ([#29](https://github.com/opentracing/opentracing-ruby/pull/27))
10
+ * Update license from MIT => Apache 2.0 ([#26](https://github.com/opentracing/opentracing-ruby/pull/26))
11
+
3
12
  ## 0.4.0
4
13
 
5
14
  * The tracer now implements the OpenTracing Scope API for in-process scope propagation([#21](https://github.com/opentracing/opentracing-ruby/pull/21))
data/LICENSE CHANGED
@@ -186,7 +186,7 @@
186
186
  same "printed page" as the copyright notice for easier
187
187
  identification within third-party archives.
188
188
 
189
- Copyright {yyyy} {name of copyright owner}
189
+ Copyright The OpenTracing Authors
190
190
 
191
191
  Licensed under the Apache License, Version 2.0 (the "License");
192
192
  you may not use this file except in compliance with the License.
data/README.md CHANGED
@@ -25,15 +25,15 @@ And then execute:
25
25
  Or install it yourself as:
26
26
 
27
27
  $ gem install opentracing
28
-
28
+
29
29
  `opentracing` supports Ruby 2.0+.
30
30
 
31
31
  ## Usage
32
32
 
33
33
  Everyday consumers of this `opentracing` gem really only need to worry
34
- about a couple of key abstractions: the `start_span` function, the `Span`
35
- interface, and binding a `Tracer` at runtime. Here are code snippets
36
- demonstrating some important use cases.
34
+ about a couple of key abstractions: the `start_active_span` and `start_span`
35
+ methods, the `Span` and `ScopeManager` interfaces, and binding a `Tracer`
36
+ at runtime. Here are code snippets demonstrating some important use cases.
37
37
 
38
38
  ### Singleton initialization
39
39
 
@@ -41,38 +41,101 @@ As early as possible, call
41
41
 
42
42
  ```ruby
43
43
  require 'opentracing'
44
- OpenTracing.global_tracer = MyTracerImplementation.New(...)
44
+ OpenTracing.global_tracer = MyTracerImplementation.new(...)
45
45
  ```
46
46
 
47
47
  Where `MyTracerImplementation` is your tracer. For testing, you can use
48
- the provided `OpenTracing::NilTracer`
48
+ the provided `OpenTracing::Tracer`
49
49
 
50
50
  ### Non-Singleton initialization
51
51
 
52
52
  If you prefer direct control to singletons, manage ownership of the
53
53
  `Tracer` implementation explicitly.
54
54
 
55
- ### Starting an empty trace by creating a "root span"
55
+ ### Scopes and within-process propagation
56
+
57
+ For any thread, at most one `Span` may be "active". Of course there may be many
58
+ other `Spans` involved with the thread which are (a) started, (b) not finished,
59
+ and yet (c) not "active": perhaps they are waiting for I/O, blocked on a child
60
+ `Span`, or otherwise off of the critical path.
61
+
62
+ It's inconvenient to pass an active `Span` from function to function manually,
63
+ so OpenTracing requires that every `Tracer` contains a `ScopeManager` that
64
+ grants access to the active `Span` through a `Scope`. Any `Span` may be
65
+ transferred to another callback or thread, but not `Scope`.
56
66
 
57
- It's always possible to create a "root" `Span` with no parent or other causal
58
- reference.
67
+ #### Accessing the active Span through Scope
59
68
 
60
69
  ```ruby
61
- span = OpenTracing.start_span("operation_name")
62
- span.finish
70
+ # Access to the active span is straightforward.
71
+
72
+ span = OpenTracing.active_span
73
+ if span
74
+ span.set_tag('...', '...')
75
+ end
76
+
77
+ # or
78
+
79
+ scope = OpenTracing.scope_manager.active
80
+ if scope
81
+ scope.span.set_tag('...', '...')
82
+ end
63
83
  ```
64
84
 
65
- This example will start a span on the global tracer (initialized above). If
66
- you are managing your own tracer you'll need to call `start_span` on your
67
- tracer.
85
+ ### Starting a new Span
68
86
 
69
- ### Creating a (child) Span given an existing (parent) Span
87
+ The common case starts a `Scope` that's automatically registered for
88
+ intra-process propagation via `ScopeManager`.
89
+
90
+ Note that `start_active_span('...')` automatically finishes the span on
91
+ `Scope#close` (`start_active_span('...', finish_on_close: false)` does not
92
+ finish it, in contrast).
70
93
 
71
94
  ```ruby
72
- span = OpenTracing.start_span("parent")
73
- child = OpenTracing.start_span("child", child_of: span)
74
- child.finish
75
- span.finish
95
+ # Automatic activation of the Span.
96
+ # By default the active span will be finished when the returned scope is closed.
97
+ # This can be controlled by passing finish_on_close parameter to
98
+ # start_active_span
99
+ scope = OpenTracing.start_active_span('operation_name')
100
+ # Do things.
101
+
102
+ # Block form of start_active_span
103
+ # start_active_span optionally accepts a block. If a block is passed to
104
+ # start_active_span it will yield the newly created scope. The scope will
105
+ # be closed and its associated span will be finished unless
106
+ # finish_on_close: false is passed to start_active_span.
107
+ OpenTracing.start_active_span('operation_name') do |scope|
108
+ # Do things.
109
+ end
110
+
111
+ # Manual activation of the Span.
112
+ # Spans can be managed manually. This is equivalent to the more concise examples
113
+ # above.
114
+ span = OpenTracing.start_span('operation_name')
115
+ OpenTracing.scope_manager.activate(span)
116
+ scope = OpenTracing.scope_manager.active
117
+ # Do things.
118
+
119
+ # If there is an active Scope, it will act as the parent to any newly started
120
+ # Span unless ignore_active_scope: true is passed to start_span or
121
+ # start_active_span.
122
+
123
+ # create a root span, ignoring the currently active scope (if it's set)
124
+ scope = OpenTracing.start_active_span('operation_name', ignore_active_scope: true)
125
+
126
+ # or
127
+ span = OpenTracing.start_span('operation_name', ignore_active_scope: true)
128
+
129
+ # It's possible to create a child Span given an existing parent Span by
130
+ # using the child_of option.
131
+
132
+ parent_scope = OpenTracing.start_active_span('parent_operation, ignore_active_scope: true)
133
+ child_scope = OpenTracing.start_active_span('child_operation', child_of: parent_scope.span)
134
+
135
+ # or
136
+ parent_span = OpenTracing.start_span('parent_operation', ignore_active_scope: true)
137
+ child_span = OpenTracing.start_span('child_operation', child_of: parent_span)
138
+
76
139
  ```
77
140
 
78
141
  ### Serializing to the wire
@@ -130,7 +193,6 @@ To install this gem onto your local machine, run `bundle exec rake install`. To
130
193
 
131
194
  Bug reports and pull requests are welcome on GitHub at https://github.com/opentracing/opentracing-ruby. This project is intended to be a safe, welcoming space for collaboration, and contributors are expected to adhere to the [Contributor Covenant](http://contributor-covenant.org) code of conduct.
132
195
 
196
+ ## Licensing
133
197
 
134
- ## License
135
-
136
- The gem is available as open source under the terms of the [MIT License](http://opensource.org/licenses/MIT).
198
+ [Apache 2.0 License](./LICENSE).
data/Rakefile CHANGED
@@ -1,10 +1,17 @@
1
- require "bundler/gem_tasks"
2
- require "rake/testtask"
1
+ require 'bundler/gem_tasks'
2
+ require 'rake/testtask'
3
+ require 'rubocop/rake_task'
3
4
 
4
5
  Rake::TestTask.new(:test) do |t|
5
- t.libs << "test"
6
- t.libs << "lib"
6
+ t.libs << 'test'
7
+ t.libs << 'lib'
7
8
  t.test_files = FileList['test/**/*_test.rb']
8
9
  end
9
10
 
10
- task :default => :test
11
+ RuboCop::RakeTask.new(:rubocop)
12
+
13
+ if RUBY_PLATFORM == 'java'
14
+ task default: :test
15
+ else
16
+ task default: %i[rubocop test]
17
+ end
@@ -1,6 +1,6 @@
1
1
  #!/usr/bin/env ruby
2
2
 
3
- require "bundler/setup"
4
- require "opentracing"
5
- require "irb"
3
+ require 'bundler/setup'
4
+ require 'opentracing'
5
+ require 'irb'
6
6
  IRB.start
@@ -1,12 +1,13 @@
1
- require "forwardable"
2
- require "opentracing/version"
3
- require "opentracing/span_context"
4
- require "opentracing/span"
5
- require "opentracing/reference"
6
- require "opentracing/tracer"
7
- require "opentracing/scope"
8
- require "opentracing/scope_manager"
1
+ require 'forwardable'
2
+ require 'opentracing/version'
3
+ require 'opentracing/span_context'
4
+ require 'opentracing/span'
5
+ require 'opentracing/reference'
6
+ require 'opentracing/tracer'
7
+ require 'opentracing/scope'
8
+ require 'opentracing/scope_manager'
9
9
 
10
+ #:nodoc:
10
11
  module OpenTracing
11
12
  # Text format for Tracer#inject and Tracer#extract.
12
13
  #
@@ -35,7 +36,17 @@ module OpenTracing
35
36
  extend Forwardable
36
37
  # Global tracer to be used when OpenTracing.start_span, inject or extract is called
37
38
  attr_accessor :global_tracer
38
- def_delegators :global_tracer, :start_span, :inject, :extract
39
+ def_delegators :global_tracer, :scope_manager, :start_active_span,
40
+ :start_span, :inject, :extract
41
+
42
+ # Convenience method to access the currently active span. This is equivalent
43
+ # to calling `OpenTracing.scope_manager.active.span`
44
+ #
45
+ # @return [Span, nil] the currently active span or nil
46
+ def active_span
47
+ scope = scope_manager.active
48
+ scope.span if scope
49
+ end
39
50
  end
40
51
  end
41
52
 
@@ -6,20 +6,17 @@ module OpenTracing
6
6
  # [] retrieves a value by the given key
7
7
  # @param key [String] key to retrieve the value
8
8
  # @return [String] the desired value
9
- def [](key)
10
- end
9
+ def [](key); end
11
10
 
12
11
  # []= sets the value for the given key
13
12
  # @param key [String] key to set
14
13
  # @param value [String] value to set
15
- def []=(key, value)
16
- end
14
+ def []=(key, value); end
17
15
 
18
16
  # each iterates over every key-value pair in the carrier
19
17
  # @yield [key, value]
20
18
  # @yieldparam key [String] the key of the tuple
21
19
  # @yieldparam value [String] the value of the tuple
22
- def each(&block)
23
- end
20
+ def each(&block); end
24
21
  end
25
22
  end
@@ -1,4 +1,5 @@
1
1
  module OpenTracing
2
+ #:nodoc:
2
3
  class Reference
3
4
  CHILD_OF = 'child_of'.freeze
4
5
  FOLLOWS_FROM = 'follows_from'.freeze
@@ -17,7 +17,6 @@ module OpenTracing
17
17
  #
18
18
  # NOTE: Calling close more than once on a single Scope instance leads to
19
19
  # undefined behavior.
20
- def close
21
- end
20
+ def close; end
22
21
  end
23
22
  end
@@ -6,7 +6,7 @@ module OpenTracing
6
6
  # The ScopeManager interface abstracts both the activation of Span instances
7
7
  # via ScopeManager#activate and access to an active Span/Scope via
8
8
  # ScopeManager#active
9
-
9
+ #
10
10
  class ScopeManager
11
11
  NOOP_INSTANCE = ScopeManager.new.freeze
12
12
 
@@ -8,8 +8,7 @@ module OpenTracing
8
8
  # Set the name of the operation
9
9
  #
10
10
  # @param [String] name
11
- def operation_name=(name)
12
- end
11
+ def operation_name=(name); end
13
12
 
14
13
  # Span Context
15
14
  #
@@ -49,7 +48,7 @@ module OpenTracing
49
48
  # @param timestamp [Time] time of the log
50
49
  # @param fields [Hash] Additional information to log
51
50
  def log(event: nil, timestamp: Time.now, **fields)
52
- warn "Span#log is deprecated. Please use Span#log_kv instead."
51
+ warn 'Span#log is deprecated. Please use Span#log_kv instead.'
53
52
  nil
54
53
  end
55
54
 
@@ -9,7 +9,6 @@ module OpenTracing
9
9
  # @param id the ID of the Context
10
10
  # @param trace_id the ID of the current trace
11
11
  # @param baggage baggage
12
- def initialize(baggage: {})
13
- end
12
+ def initialize(baggage: {}); end
14
13
  end
15
14
  end
@@ -1,4 +1,10 @@
1
1
  module OpenTracing
2
+ # Tracer is the entry point API between instrumentation code and the tracing
3
+ # implementation.
4
+ #
5
+ # This implementation both defines the public Tracer API, and provides a
6
+ # default no-op behavior.
7
+ #
2
8
  class Tracer
3
9
  # @return [ScopeManager] the current ScopeManager, which may be a no-op but
4
10
  # may not be nil.
@@ -1,3 +1,3 @@
1
1
  module OpenTracing
2
- VERSION = "0.4.0"
2
+ VERSION = '0.4.1'.freeze
3
3
  end
@@ -1,28 +1,29 @@
1
- # coding: utf-8
2
- lib = File.expand_path('../lib', __FILE__)
1
+
2
+ lib = File.expand_path('lib', __dir__)
3
3
  $LOAD_PATH.unshift(lib) unless $LOAD_PATH.include?(lib)
4
4
  require 'opentracing/version'
5
5
 
6
6
  Gem::Specification.new do |spec|
7
- spec.name = "opentracing"
7
+ spec.name = 'opentracing'
8
8
  spec.version = OpenTracing::VERSION
9
- spec.authors = ["ngauthier", "bcronin", "bensigelman"]
10
- spec.email = ["info@opentracing.io"]
9
+ spec.authors = %w[ngauthier bcronin bensigelman]
10
+ spec.email = ['info@opentracing.io']
11
11
 
12
- spec.summary = %q{OpenTracing Ruby Platform API}
13
- spec.homepage = "https://github.com/opentracing/opentracing-ruby"
14
- spec.license = "MIT"
12
+ spec.summary = 'OpenTracing Ruby Platform API'
13
+ spec.homepage = 'https://github.com/opentracing/opentracing-ruby'
14
+ spec.license = 'Apache 2.0'
15
15
 
16
16
  spec.files = `git ls-files -z`.split("\x0").reject do |f|
17
17
  f.match(%r{^(test|spec|features)/})
18
18
  end
19
- spec.bindir = "exe"
19
+ spec.bindir = 'exe'
20
20
  spec.executables = spec.files.grep(%r{^exe/}) { |f| File.basename(f) }
21
- spec.require_paths = ["lib"]
21
+ spec.require_paths = ['lib']
22
22
 
23
- spec.add_development_dependency "bundler"
24
- spec.add_development_dependency "rake", "~> 10.0"
25
- spec.add_development_dependency "minitest", "~> 5.0"
26
- spec.add_development_dependency "simplecov"
27
- spec.add_development_dependency "simplecov-console"
23
+ spec.add_development_dependency 'bundler'
24
+ spec.add_development_dependency 'minitest', '~> 5.0'
25
+ spec.add_development_dependency 'rake', '~> 10.0'
26
+ spec.add_development_dependency 'rubocop', '~> 0.54.0'
27
+ spec.add_development_dependency 'simplecov'
28
+ spec.add_development_dependency 'simplecov-console'
28
29
  end
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: opentracing
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.4.0
4
+ version: 0.4.1
5
5
  platform: ruby
6
6
  authors:
7
7
  - ngauthier
@@ -10,7 +10,7 @@ authors:
10
10
  autorequire:
11
11
  bindir: exe
12
12
  cert_chain: []
13
- date: 2018-03-29 00:00:00.000000000 Z
13
+ date: 2018-04-27 00:00:00.000000000 Z
14
14
  dependencies:
15
15
  - !ruby/object:Gem::Dependency
16
16
  name: bundler
@@ -26,6 +26,20 @@ dependencies:
26
26
  - - ">="
27
27
  - !ruby/object:Gem::Version
28
28
  version: '0'
29
+ - !ruby/object:Gem::Dependency
30
+ name: minitest
31
+ requirement: !ruby/object:Gem::Requirement
32
+ requirements:
33
+ - - "~>"
34
+ - !ruby/object:Gem::Version
35
+ version: '5.0'
36
+ type: :development
37
+ prerelease: false
38
+ version_requirements: !ruby/object:Gem::Requirement
39
+ requirements:
40
+ - - "~>"
41
+ - !ruby/object:Gem::Version
42
+ version: '5.0'
29
43
  - !ruby/object:Gem::Dependency
30
44
  name: rake
31
45
  requirement: !ruby/object:Gem::Requirement
@@ -41,19 +55,19 @@ dependencies:
41
55
  - !ruby/object:Gem::Version
42
56
  version: '10.0'
43
57
  - !ruby/object:Gem::Dependency
44
- name: minitest
58
+ name: rubocop
45
59
  requirement: !ruby/object:Gem::Requirement
46
60
  requirements:
47
61
  - - "~>"
48
62
  - !ruby/object:Gem::Version
49
- version: '5.0'
63
+ version: 0.54.0
50
64
  type: :development
51
65
  prerelease: false
52
66
  version_requirements: !ruby/object:Gem::Requirement
53
67
  requirements:
54
68
  - - "~>"
55
69
  - !ruby/object:Gem::Version
56
- version: '5.0'
70
+ version: 0.54.0
57
71
  - !ruby/object:Gem::Dependency
58
72
  name: simplecov
59
73
  requirement: !ruby/object:Gem::Requirement
@@ -112,7 +126,7 @@ files:
112
126
  - opentracing.gemspec
113
127
  homepage: https://github.com/opentracing/opentracing-ruby
114
128
  licenses:
115
- - MIT
129
+ - Apache 2.0
116
130
  metadata: {}
117
131
  post_install_message:
118
132
  rdoc_options: []
@@ -130,7 +144,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
130
144
  version: '0'
131
145
  requirements: []
132
146
  rubyforge_project:
133
- rubygems_version: 2.4.6
147
+ rubygems_version: 2.7.6
134
148
  signing_key:
135
149
  specification_version: 4
136
150
  summary: OpenTracing Ruby Platform API