trace 0.3.0 → 0.3.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
- data/lib/trace/backend/console.rb +20 -1
- data/lib/trace/backend/open_telemetry.rb +32 -1
- data/lib/trace/backend/test.rb +16 -1
- data/lib/trace/version.rb +1 -1
- metadata +1 -1
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA256:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: c675b7217702e13f10c5bb1b4b0a12d8c190b02fa4a25c72c8b86ccc4c1b2924
|
4
|
+
data.tar.gz: 7515cc6b87e32a49c0c859be13e07519e74099ef493db8001d372d5f858915af
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: c83f8843932c0d9f84356b4fa45dd14252e920752ea271ba367cf5d57041ee92762e8b2a221fb11315aee1c5708264852c73361a85e555702e3064ef5f977e42
|
7
|
+
data.tar.gz: 2e890163ef6241ab39376689e6cd1c909e662609c5a2fcd21fabb950f1329c76a6b8053616a768c02062545d48132ea3ed9e32987e55d942722750583d3b8547
|
@@ -26,7 +26,26 @@ module Trace
|
|
26
26
|
module Backend
|
27
27
|
private
|
28
28
|
|
29
|
-
|
29
|
+
# Increment or decrement (part of a count) a named metric.
|
30
|
+
def adjust_metric(name, amount, **attributes)
|
31
|
+
if amount > 0
|
32
|
+
Console.logger.info(self, "#{name} +#{amount}")
|
33
|
+
else
|
34
|
+
Console.logger.info(self, "#{name} -#{amount}")
|
35
|
+
end
|
36
|
+
end
|
37
|
+
|
38
|
+
# Record a specific value (part of a distribution) for a named metric.
|
39
|
+
def record_metric(name, value, **attributes)
|
40
|
+
Console.logger.info(self, "#{name} << #{value}")
|
41
|
+
end
|
42
|
+
|
43
|
+
# Record a specific value (part of a gauge) for a named metric.
|
44
|
+
def observe_metric(name, value, **attributes)
|
45
|
+
Console.logger.info(self, "#{name} = #{value}")
|
46
|
+
end
|
47
|
+
|
48
|
+
def trace(name, parent = nil, **attributes, &block)
|
30
49
|
Console.logger.measure(self, name, parent: parent, **attributes) do
|
31
50
|
begin
|
32
51
|
yield
|
@@ -26,6 +26,21 @@ module Trace
|
|
26
26
|
module Backend
|
27
27
|
private
|
28
28
|
|
29
|
+
# Increment or decrement (part of a count) a named metric.
|
30
|
+
def adjust_metric(name, amount, **attributes)
|
31
|
+
# No-op.
|
32
|
+
end
|
33
|
+
|
34
|
+
# Record a specific value (part of a distribution) for a named metric.
|
35
|
+
def record_metric(name, value, **attributes)
|
36
|
+
# No-op.
|
37
|
+
end
|
38
|
+
|
39
|
+
# Record a specific value (part of a gauge) for a named metric.
|
40
|
+
def observe_metric(name, value, **attributes)
|
41
|
+
# No-op.
|
42
|
+
end
|
43
|
+
|
29
44
|
# Provides a backend that writes data to OpenTelemetry.
|
30
45
|
# See <https://github.com/open-telemetry/opentelemetry-ruby> for more details.
|
31
46
|
TRACER = ::OpenTelemetry.tracer_provider.tracer(Trace, Trace::VERSION)
|
@@ -45,7 +60,11 @@ module Trace
|
|
45
60
|
span = TRACER.start_span(name, with_parent: parent, attributes: attributes)
|
46
61
|
|
47
62
|
begin
|
48
|
-
|
63
|
+
if block.arity.zero?
|
64
|
+
yield
|
65
|
+
else
|
66
|
+
yield trace_span_context(span)
|
67
|
+
end
|
49
68
|
rescue Exception => error
|
50
69
|
span&.record_exception(error)
|
51
70
|
span&.status = ::OpenTelemetry::Trace::Status.error("Unhandled exception of type: #{error.class}")
|
@@ -54,5 +73,17 @@ module Trace
|
|
54
73
|
span&.finish
|
55
74
|
end
|
56
75
|
end
|
76
|
+
|
77
|
+
def trace_span_context(span)
|
78
|
+
context = span.context
|
79
|
+
|
80
|
+
return Context.new(
|
81
|
+
context.trace_id,
|
82
|
+
context.span_id,
|
83
|
+
context.trace_flags,
|
84
|
+
context.tracestate,
|
85
|
+
remote: context.remote?
|
86
|
+
)
|
87
|
+
end
|
57
88
|
end
|
58
89
|
end
|
data/lib/trace/backend/test.rb
CHANGED
@@ -26,7 +26,22 @@ module Trace
|
|
26
26
|
module Backend
|
27
27
|
private
|
28
28
|
|
29
|
-
|
29
|
+
# Increment or decrement (part of a count) a named metric.
|
30
|
+
def adjust_metric(name, amount, **attributes)
|
31
|
+
# No-op.
|
32
|
+
end
|
33
|
+
|
34
|
+
# Record a specific value (part of a distribution) for a named metric.
|
35
|
+
def record_metric(name, value, **attributes)
|
36
|
+
# No-op.
|
37
|
+
end
|
38
|
+
|
39
|
+
# Record a specific value (part of a gauge) for a named metric.
|
40
|
+
def observe_metric(name, value, **attributes)
|
41
|
+
# No-op.
|
42
|
+
end
|
43
|
+
|
44
|
+
def trace(name, parent = nil, **attributes, &block)
|
30
45
|
yield
|
31
46
|
end
|
32
47
|
end
|
data/lib/trace/version.rb
CHANGED