trace 0.3.1 → 0.4.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 CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA256:
3
- metadata.gz: c675b7217702e13f10c5bb1b4b0a12d8c190b02fa4a25c72c8b86ccc4c1b2924
4
- data.tar.gz: 7515cc6b87e32a49c0c859be13e07519e74099ef493db8001d372d5f858915af
3
+ metadata.gz: 54c4527ca062f533a6c0e085d4dba7b9c484e23791d43e0401462e87c40cce31
4
+ data.tar.gz: 9861c09eae777671040e08ee5dcc2465381bb83566f9e3f69b08a1ffe68cb2a2
5
5
  SHA512:
6
- metadata.gz: c83f8843932c0d9f84356b4fa45dd14252e920752ea271ba367cf5d57041ee92762e8b2a221fb11315aee1c5708264852c73361a85e555702e3064ef5f977e42
7
- data.tar.gz: 2e890163ef6241ab39376689e6cd1c909e662609c5a2fcd21fabb950f1329c76a6b8053616a768c02062545d48132ea3ed9e32987e55d942722750583d3b8547
6
+ metadata.gz: b5bbf6b42a4236f7fa548be739b9f697d69974509a1f7f6e497f7c023cf2283934b9b07a97c8509f095c5ef6b523656278c6fcd2022bd3dd5005da1e941bc845
7
+ data.tar.gz: 9df11d2f2bc4ddfe1694622b38db3cfa54005ad276d25ceedea52600290f3fe0b7c602de1502b4ade12039ad7f08377dcfede944b2db27339171aaf648c288aa
@@ -26,25 +26,6 @@ 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
- 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
29
  def trace(name, parent = nil, **attributes, &block)
49
30
  Console.logger.measure(self, name, parent: parent, **attributes) do
50
31
  begin
@@ -0,0 +1,68 @@
1
+ # frozen_string_literal: true
2
+
3
+ # Copyright, 2021, by Samuel G. D. Williams. <http://www.codeotaku.com>
4
+ #
5
+ # Permission is hereby granted, free of charge, to any person obtaining a copy
6
+ # of this software and associated documentation files (the "Software"), to deal
7
+ # in the Software without restriction, including without limitation the rights
8
+ # to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
9
+ # copies of the Software, and to permit persons to whom the Software is
10
+ # furnished to do so, subject to the following conditions:
11
+ #
12
+ # The above copyright notice and this permission notice shall be included in
13
+ # all copies or substantial portions of the Software.
14
+ #
15
+ # THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
16
+ # IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
17
+ # FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
18
+ # AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
19
+ # LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
20
+ # OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
21
+ # THE SOFTWARE.
22
+
23
+ require 'console'
24
+
25
+ module Trace
26
+ module Backend
27
+ private
28
+
29
+ def trace(name, parent = nil, **attributes, &block)
30
+ if parent
31
+ parent = Datadog::Context.new(
32
+ trace_id: parent.trace_id,
33
+ span_id: parent.span_id,
34
+ sampled: parent.sampled?,
35
+ )
36
+ end
37
+
38
+ Datadog.tracer.trace(name, child_of: parent, tags: attributes) do |span|
39
+ begin
40
+ if block.arity.zero?
41
+ yield
42
+ else
43
+ yield trace_span_context(span)
44
+ end
45
+ rescue Exception => error
46
+ Console.logger.error(self, error)
47
+ raise
48
+ end
49
+ end
50
+ end
51
+
52
+ def trace_span_context(span)
53
+ flags = 0
54
+
55
+ if span.sampled
56
+ flags |= Context::SAMPLED
57
+ end
58
+
59
+ return Context.new(
60
+ span.trace_id,
61
+ span.span_id,
62
+ flags,
63
+ nil,
64
+ remote: false
65
+ )
66
+ end
67
+ end
68
+ end
@@ -26,21 +26,6 @@ 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
-
44
29
  # Provides a backend that writes data to OpenTelemetry.
45
30
  # See <https://github.com/open-telemetry/opentelemetry-ruby> for more details.
46
31
  TRACER = ::OpenTelemetry.tracer_provider.tracer(Trace, Trace::VERSION)
data/lib/trace/version.rb CHANGED
@@ -21,5 +21,5 @@
21
21
  # THE SOFTWARE.
22
22
 
23
23
  module Trace
24
- VERSION = "0.3.1"
24
+ VERSION = "0.4.0"
25
25
  end
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: trace
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.3.1
4
+ version: 0.4.0
5
5
  platform: ruby
6
6
  authors:
7
7
  - Samuel Williams
8
8
  autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
- date: 2021-09-02 00:00:00.000000000 Z
11
+ date: 2021-09-03 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: rspec
@@ -32,6 +32,7 @@ extra_rdoc_files: []
32
32
  files:
33
33
  - lib/trace.rb
34
34
  - lib/trace/backend/console.rb
35
+ - lib/trace/backend/datadog.rb
35
36
  - lib/trace/backend/open_telemetry.rb
36
37
  - lib/trace/backend/test.rb
37
38
  - lib/trace/context.rb