traces 0.3.0 → 0.4.1

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: cebb7ae2c860c548687f52033498988db4098d4fe4cba8a14c3fc72cfe957049
4
- data.tar.gz: 5d13eb16c1d4506680b675568caa8e6f34751a2e1c6cd3abe8a1985c2e20933b
3
+ metadata.gz: '08840f587a19c2f5f8300c832a29409c5fa2e59c9607cc2c38586baa7db4b573'
4
+ data.tar.gz: 42c1503ae596a3d8bdc8ece4bd839c09cdfa638236e4c64b1d4c42fcfcbe503e
5
5
  SHA512:
6
- metadata.gz: 31c2216adb04fdb0c0bb63efac6a1f3e542c9b631bba09f66661d0adc16f15cb68102f374b67c65215a945b3c3a3e9bb71d1bd4295749aed856e75bbe6c35942
7
- data.tar.gz: fa7f67ae12ddd7c2bc71525e2b0390dc862689a87f6c92ffa10058ca7f788a7c0974891de94c003245531666a1335efa4ab10c4895f8c5b897ff9cd77e156e8c
6
+ metadata.gz: cf699c4c10ddca5ffc2a40b70498dee12df99cd801c5820a20eab9ef0aa1772871e09fb4d4019415b3be66f02396260613950c124229374401356bc9536e90a6
7
+ data.tar.gz: 192db05a4272dd9420aa3341928289da2afd31a0c0181ec621f6bce0ba87ede6ac6575d3c17c6f2513cae94ce48c9216c5da1ddfe45ea6fdaa5f5a067aca985d
checksums.yaml.gz.sig CHANGED
Binary file
@@ -31,6 +31,7 @@ end
31
31
 
32
32
  module Traces
33
33
  module Backend
34
+ # A backend which logs all spans to the console logger output.
34
35
  module Console
35
36
  # A span which validates tag assignment.
36
37
  class Span
@@ -50,41 +51,40 @@ module Traces
50
51
  end
51
52
  end
52
53
 
53
- private
54
-
55
- # Trace the given block of code and log the execution.
56
- # @parameter name [String] A useful name/annotation for the recorded span.
57
- # @parameter attributes [Hash] Metadata for the recorded span.
58
- def trace(name, attributes: {}, &block)
59
- context = Context.nested(Fiber.current.traces_backend_context)
60
- Fiber.current.traces_backend_context = context
61
-
62
- ::Console.logger.info(self, name, attributes)
54
+ module Interface
55
+ # Trace the given block of code and log the execution.
56
+ # @parameter name [String] A useful name/annotation for the recorded span.
57
+ # @parameter attributes [Hash] Metadata for the recorded span.
58
+ def trace(name, attributes: {}, &block)
59
+ context = Context.nested(Fiber.current.traces_backend_context)
60
+ Fiber.current.traces_backend_context = context
61
+
62
+ ::Console.logger.info(self, name, attributes)
63
+
64
+ if block.arity.zero?
65
+ yield
66
+ else
67
+ yield Span.new(context, self, name)
68
+ end
69
+ end
63
70
 
64
- if block.arity.zero?
65
- yield
66
- else
67
- yield Span.new(context, self, name)
71
+ # Assign a trace context to the current execution scope.
72
+ def trace_context= context
73
+ Fiber.current.traces_backend_context = context
68
74
  end
69
- end
70
-
71
- # Assign a trace context to the current execution scope.
72
- def trace_context= context
73
- Fiber.current.traces_backend_context = context
74
- end
75
-
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
75
+
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
83
84
  end
84
85
  end
85
86
  end
86
87
 
87
- # This is the default.
88
- self.include(Console)
88
+ Interface = Console::Interface
89
89
  end
90
90
  end
@@ -29,6 +29,7 @@ end
29
29
 
30
30
  module Traces
31
31
  module Backend
32
+ # A backend which validates interface usage.
32
33
  module Test
33
34
  # A span which validates tag assignment.
34
35
  class Span
@@ -46,49 +47,49 @@ module Traces
46
47
  raise ArgumentError, "Invalid name!"
47
48
  end
48
49
 
49
- unless String(Value)
50
+ unless String(value)
50
51
  raise ArgumentError, "Invalid value!"
51
52
  end
52
53
  end
53
54
  end
54
55
 
55
- private
56
-
57
- # Trace the given block of code and validate the interface usage.
58
- # @parameter name [String] A useful name/annotation for the recorded span.
59
- # @parameter attributes [Hash] Metadata for the recorded span.
60
- def trace(name, attributes: nil, &block)
61
- unless name.is_a?(String)
62
- raise ArgumentError, "Invalid name!"
56
+ module Interface
57
+ # Trace the given block of code and validate the interface usage.
58
+ # @parameter name [String] A useful name/annotation for the recorded span.
59
+ # @parameter attributes [Hash] Metadata for the recorded span.
60
+ def trace(name, attributes: nil, &block)
61
+ unless name.is_a?(String)
62
+ raise ArgumentError, "Invalid name!"
63
+ end
64
+
65
+ context = Context.nested(Fiber.current.traces_backend_context)
66
+ Fiber.current.traces_backend_context = context
67
+
68
+ if block.arity.zero?
69
+ yield
70
+ else
71
+ span = Span.new(context)
72
+ yield span
73
+ end
63
74
  end
64
75
 
65
- context = Context.nested(Fiber.current.traces_backend_context)
66
- Fiber.current.traces_backend_context = context
67
-
68
- if block.arity.zero?
69
- yield
70
- else
71
- span = Span.new(context)
72
- yield span
76
+ # Assign a trace context to the current execution scope.
77
+ def trace_context= context
78
+ Fiber.current.traces_backend_context = context
73
79
  end
74
- end
75
-
76
- # Assign a trace context to the current execution scope.
77
- def trace_context= context
78
- Fiber.current.traces_backend_context = context
79
- end
80
-
81
- # 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
80
+
81
+ # 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
88
89
  end
89
90
  end
90
91
  end
91
92
 
92
- self.include(Test)
93
+ Interface = Test::Interface
93
94
  end
94
- end
95
+ 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
@@ -49,7 +49,7 @@ module Traces
49
49
  # Create a local trace context which is likley to be globally unique.
50
50
  # @parameter flags [Integer] Any trace context flags.
51
51
  def self.local(flags = 0, **options)
52
- self.new(SecureRandom.hex(16), SecureRandom.hex(8), flags, options)
52
+ self.new(SecureRandom.hex(16), SecureRandom.hex(8), flags, **options)
53
53
  end
54
54
 
55
55
  # Nest a local trace context in an optional parent context.
@@ -37,7 +37,7 @@ module Traces
37
37
  klass.extend(Provider)
38
38
 
39
39
  provider = klass.traces_provider
40
- provider.prepend(Backend)
40
+ provider.prepend(Backend::Interface)
41
41
 
42
42
  klass.prepend(provider)
43
43
 
@@ -21,5 +21,5 @@
21
21
  # THE SOFTWARE.
22
22
 
23
23
  module Traces
24
- VERSION = "0.3.0"
24
+ VERSION = "0.4.1"
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.3.0
4
+ version: 0.4.1
5
5
  platform: ruby
6
6
  authors:
7
7
  - Samuel Williams
metadata.gz.sig CHANGED
Binary file