traces 0.4.0 → 0.6.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 CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA256:
3
- metadata.gz: 389518e7025f63c5c99a5599000e12191ca8634b38f8d05ba727fe22b0fe3aa5
4
- data.tar.gz: f8648d7990686c3abbd955f4b45869cf67c88e2b644da156e914bc2cac92087d
3
+ metadata.gz: f43a022f924d80549fb54edeb3624e67ff1bfbf682115a5a83ac721249b53806
4
+ data.tar.gz: a307c39fb5decf64d338c2c6f414744fbb4a7e6e523ba84182171d386e68f09a
5
5
  SHA512:
6
- metadata.gz: a3d9834ff556a722bb7a82dae4c824c94888af648a70954ab2a7c720e26e622ce826262838016169388734b8f9beaa6c2b74cd0a4ea9a669295fce70ae41c61c
7
- data.tar.gz: 4fd9a0b83fb293e04fec5ff91431ee55ac2a6fcb86609288795d4d22486cf51fdcb16ec21610487b6e99d9b5662ab30d0999360ce5aaf430408b75a56ae077b8
6
+ metadata.gz: 2fcb2d979a672924a6167753e9e3e9b4e7d75be028d14b0a623458c7d0a5a656859648ec1a728195dbacedcfcd3817474a37ac3778556a5920c6ace5bb598f28
7
+ data.tar.gz: 7b4fb88b6ebda8d3ad9cddc5e6132c9e2b50d669eb69f827383aceb4902b32334cb7bd7ab227e51a873881e3e8f98dbae39cef147ac924a2dcc98e701908513e
checksums.yaml.gz.sig CHANGED
Binary file
@@ -55,11 +55,11 @@ module Traces
55
55
  # Trace the given block of code and log the execution.
56
56
  # @parameter name [String] A useful name/annotation for the recorded span.
57
57
  # @parameter attributes [Hash] Metadata for the recorded span.
58
- def trace(name, attributes: {}, &block)
58
+ def trace(name, resource: self, attributes: {}, &block)
59
59
  context = Context.nested(Fiber.current.traces_backend_context)
60
60
  Fiber.current.traces_backend_context = context
61
61
 
62
- ::Console.logger.info(self, name, attributes)
62
+ ::Console.logger.info(resource, name, attributes)
63
63
 
64
64
  if block.arity.zero?
65
65
  yield
@@ -74,13 +74,8 @@ module Traces
74
74
  end
75
75
 
76
76
  # Get a trace context from the current execution scope.
77
- # @parameter span [Span] An optional span from which to extract the context.
78
- def trace_context(span = nil)
79
- if span
80
- span.context
81
- else
82
- Fiber.current.traces_backend_context
83
- end
77
+ def trace_context
78
+ Fiber.current.traces_backend_context
84
79
  end
85
80
  end
86
81
  end
@@ -44,11 +44,11 @@ module Traces
44
44
  # @parameter value [Object] The metadata value. Should be coercable to a string.
45
45
  def []= key, value
46
46
  unless key.is_a?(String)
47
- raise ArgumentError, "Invalid name!"
47
+ raise ArgumentError, "Invalid name (must be String): #{key.inspect}!"
48
48
  end
49
49
 
50
50
  unless String(value)
51
- raise ArgumentError, "Invalid value!"
51
+ raise ArgumentError, "Invalid value (must be String): #{value.inspect}!"
52
52
  end
53
53
  end
54
54
  end
@@ -57,9 +57,14 @@ module Traces
57
57
  # Trace the given block of code and validate the interface usage.
58
58
  # @parameter name [String] A useful name/annotation for the recorded span.
59
59
  # @parameter attributes [Hash] Metadata for the recorded span.
60
- def trace(name, attributes: nil, &block)
60
+ def trace(name, resource: self.class.name, attributes: nil, &block)
61
61
  unless name.is_a?(String)
62
- raise ArgumentError, "Invalid name!"
62
+ raise ArgumentError, "Invalid name (must be String): #{name.inspect}!"
63
+ end
64
+
65
+ if resource
66
+ # It should be convertable:
67
+ resource = resource.to_s
63
68
  end
64
69
 
65
70
  context = Context.nested(Fiber.current.traces_backend_context)
@@ -79,13 +84,8 @@ module Traces
79
84
  end
80
85
 
81
86
  # Get a trace context from the current execution scope.
82
- # @parameter span [Span] An optional span from which to extract the context.
83
- def trace_context(span = nil)
84
- if span
85
- span.context
86
- else
87
- Fiber.current.traces_backend_context
88
- end
87
+ def trace_context
88
+ Fiber.current.traces_backend_context
89
89
  end
90
90
  end
91
91
  end
@@ -23,10 +23,6 @@
23
23
  module Traces
24
24
  # Require a specific trace backend.
25
25
  def self.require_backend(env = ENV)
26
- if const_defined?(:Backend)
27
- raise RuntimeError, "Backend already required!"
28
- end
29
-
30
26
  if backend = env['TRACES_BACKEND']
31
27
  require(backend)
32
28
  end
@@ -23,6 +23,11 @@
23
23
  require_relative 'backend'
24
24
 
25
25
  module Traces
26
+ # @returns [Boolean] Whether there is an active backend.
27
+ def self.enabled?
28
+ self.const_defined?(:Backend)
29
+ end
30
+
26
31
  # A module which contains tracing specific wrappers.
27
32
  module Provider
28
33
  def traces_provider
@@ -31,7 +36,7 @@ module Traces
31
36
  end
32
37
 
33
38
  # Bail out if there is no backend configured.
34
- if self.const_defined?(:Backend)
39
+ if self.enabled?
35
40
  # Extend the specified class in order to emit traces.
36
41
  def self.Provider(klass, &block)
37
42
  klass.extend(Provider)
@@ -21,5 +21,5 @@
21
21
  # THE SOFTWARE.
22
22
 
23
23
  module Traces
24
- VERSION = "0.4.0"
24
+ VERSION = "0.6.0"
25
25
  end
data.tar.gz.sig CHANGED
Binary file
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: traces
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.4.0
4
+ version: 0.6.0
5
5
  platform: ruby
6
6
  authors:
7
7
  - Samuel Williams
@@ -36,7 +36,7 @@ cert_chain:
36
36
  RAOsIl+HOBTb252nx1kIRN5hqQx272AJCbCjKx8egcUQKffFVVCI0nye09v5CK+a
37
37
  HiLJ8VOFx6w=
38
38
  -----END CERTIFICATE-----
39
- date: 2021-10-18 00:00:00.000000000 Z
39
+ date: 2022-06-09 00:00:00.000000000 Z
40
40
  dependencies:
41
41
  - !ruby/object:Gem::Dependency
42
42
  name: rspec
@@ -84,7 +84,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
84
84
  - !ruby/object:Gem::Version
85
85
  version: '0'
86
86
  requirements: []
87
- rubygems_version: 3.1.6
87
+ rubygems_version: 3.3.7
88
88
  signing_key:
89
89
  specification_version: 4
90
90
  summary: Application instrumentation and tracing.
metadata.gz.sig CHANGED
Binary file