trace 0.3.1 → 0.5.0

Sign up to get free protection for your applications and to get access to all the features.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA256:
3
- metadata.gz: c675b7217702e13f10c5bb1b4b0a12d8c190b02fa4a25c72c8b86ccc4c1b2924
4
- data.tar.gz: 7515cc6b87e32a49c0c859be13e07519e74099ef493db8001d372d5f858915af
3
+ metadata.gz: 656cd18803b101a7b5277c741de308ea0060f185e77968992f103a00349ce781
4
+ data.tar.gz: 3490984da2c202c2f7043c68a94f9a48d9a20a930c7f1c638d10d6ec9d526800
5
5
  SHA512:
6
- metadata.gz: c83f8843932c0d9f84356b4fa45dd14252e920752ea271ba367cf5d57041ee92762e8b2a221fb11315aee1c5708264852c73361a85e555702e3064ef5f977e42
7
- data.tar.gz: 2e890163ef6241ab39376689e6cd1c909e662609c5a2fcd21fabb950f1329c76a6b8053616a768c02062545d48132ea3ed9e32987e55d942722750583d3b8547
6
+ metadata.gz: d78d14f24fdfae8d32ca7c606ed737f7ff81d2ec096ae0f8d35dd81828b938fd43bbb993e385763f2447f0abab0f960b04f9fc7d3b21cb4c05eb43ba43b29524
7
+ data.tar.gz: e4b6988c6dc61ab8fa2733a55f7bba1473812558032c7ab3c0d59b7e1626b44b7475f36cd974cf96f729cb10149ed9f1ca41c756500474c9fcd0f7865e870443
@@ -26,33 +26,9 @@ 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
- def trace(name, parent = nil, **attributes, &block)
49
- Console.logger.measure(self, name, parent: parent, **attributes) do
50
- begin
51
- yield
52
- rescue Exception => error
53
- Console.logger.error(self, error)
54
- raise
55
- end
29
+ def trace(name, parent = nil, attributes: nil, &block)
30
+ Console.logger.measure(self, name, **attributes) do
31
+ yield
56
32
  end
57
33
  end
58
34
  end
@@ -0,0 +1,70 @@
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_relative '../context'
24
+
25
+ require 'ddtrace'
26
+
27
+ module Trace
28
+ module Backend
29
+ private
30
+
31
+ def trace(name, parent = nil, attributes: nil, &block)
32
+ if parent
33
+ parent = ::Datadog::Context.new(
34
+ trace_id: parent.trace_id,
35
+ span_id: parent.span_id,
36
+ sampled: parent.sampled?,
37
+ )
38
+ end
39
+
40
+ ::Datadog.tracer.trace(name, child_of: parent, tags: attributes) do |span|
41
+ begin
42
+ if block.arity.zero?
43
+ yield
44
+ else
45
+ yield trace_span_context(span)
46
+ end
47
+ rescue Exception => error
48
+ Console.logger.error(self, error)
49
+ raise
50
+ end
51
+ end
52
+ end
53
+
54
+ def trace_span_context(span)
55
+ flags = 0
56
+
57
+ if span.sampled
58
+ flags |= Context::SAMPLED
59
+ end
60
+
61
+ return Context.new(
62
+ span.trace_id,
63
+ span.span_id,
64
+ flags,
65
+ nil,
66
+ remote: false
67
+ )
68
+ end
69
+ end
70
+ end
@@ -20,32 +20,19 @@
20
20
  # OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
21
21
  # THE SOFTWARE.
22
22
 
23
+ require_relative '../context'
24
+
23
25
  require 'opentelemetry/sdk'
24
26
 
25
27
  module Trace
26
28
  module Backend
27
29
  private
28
30
 
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
31
  # Provides a backend that writes data to OpenTelemetry.
45
32
  # See <https://github.com/open-telemetry/opentelemetry-ruby> for more details.
46
33
  TRACER = ::OpenTelemetry.tracer_provider.tracer(Trace, Trace::VERSION)
47
34
 
48
- def trace(name, parent = nil, **attributes, &block)
35
+ def trace(name, parent = nil, attributes: nil, &block)
49
36
  if parent
50
37
  # Convert it to the required object:
51
38
  parent = ::OpenTelemetry::Trace::SpanContext.new(
@@ -26,22 +26,7 @@ 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
- def trace(name, parent = nil, **attributes, &block)
29
+ def trace(name, parent = nil, attributes: nil, &block)
45
30
  yield
46
31
  end
47
32
  end
@@ -0,0 +1,32 @@
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
+ module Trace
24
+ def self.require_backend(env = ENV)
25
+ if backend = env['TRACE_BACKEND']
26
+ path = File.join('backend', backend)
27
+ require_relative(path)
28
+ end
29
+ end
30
+ end
31
+
32
+ Trace.require_backend
@@ -20,6 +20,8 @@
20
20
  # OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
21
21
  # THE SOFTWARE.
22
22
 
23
+ require_relative 'backend'
24
+
23
25
  module Trace
24
26
  module Provider
25
27
  def trace_provider
@@ -42,7 +44,7 @@ module Trace
42
44
  end
43
45
  else
44
46
  def self.Provider(klass, &block)
45
- # No-op.
47
+ # Tracing disabled.
46
48
  end
47
49
  end
48
50
  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.1"
24
+ VERSION = "0.5.0"
25
25
  end
data/lib/trace.rb CHANGED
@@ -20,7 +20,5 @@
20
20
  # OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
21
21
  # THE SOFTWARE.
22
22
 
23
- require_relative 'trace/backend/console'
24
-
25
23
  require_relative 'trace/version'
26
24
  require_relative 'trace/provider'
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.5.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-04 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: rspec
@@ -31,7 +31,9 @@ extensions: []
31
31
  extra_rdoc_files: []
32
32
  files:
33
33
  - lib/trace.rb
34
+ - lib/trace/backend.rb
34
35
  - lib/trace/backend/console.rb
36
+ - lib/trace/backend/datadog.rb
35
37
  - lib/trace/backend/open_telemetry.rb
36
38
  - lib/trace/backend/test.rb
37
39
  - lib/trace/context.rb