traces 0.3.1 → 0.5.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 +4 -4
- checksums.yaml.gz.sig +0 -0
- data/lib/traces/backend/console.rb +30 -30
- data/lib/traces/backend/test.rb +40 -34
- data/lib/traces/backend.rb +0 -4
- data/lib/traces/context.rb +1 -1
- data/lib/traces/provider.rb +7 -2
- data/lib/traces/version.rb +1 -1
- data.tar.gz.sig +0 -0
- metadata +2 -2
- 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: 284452f4bfc37587b942b74918b2807ad6c51ee09d5a93bd39d5eefa6ba66aa1
|
4
|
+
data.tar.gz: 7f2d42000701312aeeb5015b19f888d5ed5acb4d4c79322e894b584292c0aed1
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: b32ad9f2018cce91b418907c052b6f9c8b63b2fad08ccdc4e1abcf3dd623e0209ad3bed87b5dfdf4138c20110e0e1806caec1a1b62bbd064b2699498822e7e24
|
7
|
+
data.tar.gz: 41e7cd96fb1dcb21f727d2753854ba77c08378fee1ad459b9f696d2bdecc857841c7fda0f3cf2d3e3b03647bfbe6cd137a846cb1c6230a5cbcc1d149899ea031
|
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, resource: self, attributes: {}, &block)
|
59
|
+
context = Context.nested(Fiber.current.traces_backend_context)
|
60
|
+
Fiber.current.traces_backend_context = context
|
61
|
+
|
62
|
+
::Console.logger.info(resource, 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
|
@@ -43,52 +44,57 @@ module Traces
|
|
43
44
|
# @parameter value [Object] The metadata value. Should be coercable to a string.
|
44
45
|
def []= key, value
|
45
46
|
unless key.is_a?(String)
|
46
|
-
raise ArgumentError, "Invalid name!"
|
47
|
+
raise ArgumentError, "Invalid name (must be String): #{key.inspect}!"
|
47
48
|
end
|
48
49
|
|
49
50
|
unless String(value)
|
50
|
-
raise ArgumentError, "Invalid value!"
|
51
|
+
raise ArgumentError, "Invalid value (must be String): #{value.inspect}!"
|
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, resource: self.class.name, attributes: nil, &block)
|
61
|
+
unless name.is_a?(String)
|
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
|
68
|
+
end
|
69
|
+
|
70
|
+
context = Context.nested(Fiber.current.traces_backend_context)
|
71
|
+
Fiber.current.traces_backend_context = context
|
72
|
+
|
73
|
+
if block.arity.zero?
|
74
|
+
yield
|
75
|
+
else
|
76
|
+
span = Span.new(context)
|
77
|
+
yield span
|
78
|
+
end
|
63
79
|
end
|
64
80
|
|
65
|
-
context
|
66
|
-
|
67
|
-
|
68
|
-
if block.arity.zero?
|
69
|
-
yield
|
70
|
-
else
|
71
|
-
span = Span.new(context)
|
72
|
-
yield span
|
81
|
+
# Assign a trace context to the current execution scope.
|
82
|
+
def trace_context= context
|
83
|
+
Fiber.current.traces_backend_context = context
|
73
84
|
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
|
85
|
+
|
86
|
+
# Get a trace context from the current execution scope.
|
87
|
+
# @parameter span [Span] An optional span from which to extract the context.
|
88
|
+
def trace_context(span = nil)
|
89
|
+
if span
|
90
|
+
span.context
|
91
|
+
else
|
92
|
+
Fiber.current.traces_backend_context
|
93
|
+
end
|
88
94
|
end
|
89
95
|
end
|
90
96
|
end
|
91
97
|
|
92
|
-
|
98
|
+
Interface = Test::Interface
|
93
99
|
end
|
94
|
-
end
|
100
|
+
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
@@ -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,13 +36,13 @@ module Traces
|
|
31
36
|
end
|
32
37
|
|
33
38
|
# Bail out if there is no backend configured.
|
34
|
-
if self.
|
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)
|
38
43
|
|
39
44
|
provider = klass.traces_provider
|
40
|
-
provider.prepend(Backend)
|
45
|
+
provider.prepend(Backend::Interface)
|
41
46
|
|
42
47
|
klass.prepend(provider)
|
43
48
|
|
data/lib/traces/version.rb
CHANGED
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
|
+
version: 0.5.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:
|
39
|
+
date: 2022-01-27 00:00:00.000000000 Z
|
40
40
|
dependencies:
|
41
41
|
- !ruby/object:Gem::Dependency
|
42
42
|
name: rspec
|
metadata.gz.sig
CHANGED
Binary file
|