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 CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA256:
3
- metadata.gz: fa04b1bb4d22b20669eb74efbd0afdbd99b481817a16e2c20a9bdb11b6fa9353
4
- data.tar.gz: c921971c0356563f72efb1625e7bacba6a00751199758d8a5e69e0dc0d3c1f7c
3
+ metadata.gz: c675b7217702e13f10c5bb1b4b0a12d8c190b02fa4a25c72c8b86ccc4c1b2924
4
+ data.tar.gz: 7515cc6b87e32a49c0c859be13e07519e74099ef493db8001d372d5f858915af
5
5
  SHA512:
6
- metadata.gz: 4bb0215f0d3862bc5a745e37d5ec8032f61a212fccf1206653837929cb6d95f6fc3edf1f3629e6f4798f89903b783497852c23e65d59373f674519af1c02f77b
7
- data.tar.gz: 731472a6b2d16537b7c527e1d118d1449310e37fe72a5840e719db891d4b3c7142bbad61078ff4518cce3a25646357a1cef2a1c3c41e0cda3eeea38fb3338ff5
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
- def trace(name, parent: nil, **attributes, &block)
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
- yield
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
@@ -26,7 +26,22 @@ module Trace
26
26
  module Backend
27
27
  private
28
28
 
29
- def trace(name, parent: nil, **attributes, &block)
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
@@ -21,5 +21,5 @@
21
21
  # THE SOFTWARE.
22
22
 
23
23
  module Trace
24
- VERSION = "0.3.0"
24
+ VERSION = "0.3.1"
25
25
  end
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: trace
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.3.0
4
+ version: 0.3.1
5
5
  platform: ruby
6
6
  authors:
7
7
  - Samuel Williams