traces 0.3.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.
- checksums.yaml +4 -4
- checksums.yaml.gz.sig +0 -0
- data/lib/traces/backend/console.rb +30 -30
- data/lib/traces/backend/test.rb +34 -33
- data/lib/traces/backend.rb +0 -4
- data/lib/traces/context.rb +1 -1
- data/lib/traces/provider.rb +1 -1
- data/lib/traces/version.rb +1 -1
- data.tar.gz.sig +0 -0
- metadata +1 -1
- metadata.gz.sig +0 -0
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA256:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: '08840f587a19c2f5f8300c832a29409c5fa2e59c9607cc2c38586baa7db4b573'
|
4
|
+
data.tar.gz: 42c1503ae596a3d8bdc8ece4bd839c09cdfa638236e4c64b1d4c42fcfcbe503e
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
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
|
-
|
54
|
-
|
55
|
-
|
56
|
-
|
57
|
-
|
58
|
-
|
59
|
-
|
60
|
-
|
61
|
-
|
62
|
-
|
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
|
-
|
65
|
-
|
66
|
-
|
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
|
-
|
70
|
-
|
71
|
-
|
72
|
-
|
73
|
-
|
74
|
-
|
75
|
-
|
76
|
-
|
77
|
-
|
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
|
-
|
88
|
-
self.include(Console)
|
88
|
+
Interface = Console::Interface
|
89
89
|
end
|
90
90
|
end
|
data/lib/traces/backend/test.rb
CHANGED
@@ -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(
|
50
|
+
unless String(value)
|
50
51
|
raise ArgumentError, "Invalid value!"
|
51
52
|
end
|
52
53
|
end
|
53
54
|
end
|
54
55
|
|
55
|
-
|
56
|
-
|
57
|
-
|
58
|
-
|
59
|
-
|
60
|
-
|
61
|
-
|
62
|
-
|
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
|
66
|
-
|
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
|
-
|
75
|
-
|
76
|
-
|
77
|
-
|
78
|
-
|
79
|
-
|
80
|
-
|
81
|
-
|
82
|
-
|
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
|
-
|
93
|
+
Interface = Test::Interface
|
93
94
|
end
|
94
|
-
end
|
95
|
+
end
|
data/lib/traces/backend.rb
CHANGED
data/lib/traces/context.rb
CHANGED
@@ -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.
|
data/lib/traces/provider.rb
CHANGED
data/lib/traces/version.rb
CHANGED
data.tar.gz.sig
CHANGED
Binary file
|
metadata
CHANGED
metadata.gz.sig
CHANGED
Binary file
|