trace 0.3.0 → 0.4.2

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: fb527822327842c5c6b73e6d3b7b1f0aa34eec02f0c2e359bd518ed0244b3661
4
+ data.tar.gz: 4b3b5b346e92d79f869b02ab044bdd40829d7c66e0f912ed6ec7ee86e655114a
5
5
  SHA512:
6
- metadata.gz: 4bb0215f0d3862bc5a745e37d5ec8032f61a212fccf1206653837929cb6d95f6fc3edf1f3629e6f4798f89903b783497852c23e65d59373f674519af1c02f77b
7
- data.tar.gz: 731472a6b2d16537b7c527e1d118d1449310e37fe72a5840e719db891d4b3c7142bbad61078ff4518cce3a25646357a1cef2a1c3c41e0cda3eeea38fb3338ff5
6
+ metadata.gz: '086f6ae2a662b67e12081ca4e6c74ed885bafdd6c74be44ea70c21c7d75bae70a6879ece9a63395643644b54c7a54c61cf53a56b23a77dc574dfdf28b516db53'
7
+ data.tar.gz: 26aea73d38d0bed8bc0fb7e6775e22dbb23d0a2a087e7a9faa02e99a47ea36ea8c41bcca137385f3f209fadcfa6f0ea344ca479a1706b97d03f0af3b8572b026
@@ -26,7 +26,7 @@ module Trace
26
26
  module Backend
27
27
  private
28
28
 
29
- def trace(name, parent: nil, **attributes, &block)
29
+ def trace(name, parent = nil, **attributes, &block)
30
30
  Console.logger.measure(self, name, parent: parent, **attributes) do
31
31
  begin
32
32
  yield
@@ -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 'ddtrace'
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
@@ -45,7 +45,11 @@ module Trace
45
45
  span = TRACER.start_span(name, with_parent: parent, attributes: attributes)
46
46
 
47
47
  begin
48
- yield
48
+ if block.arity.zero?
49
+ yield
50
+ else
51
+ yield trace_span_context(span)
52
+ end
49
53
  rescue Exception => error
50
54
  span&.record_exception(error)
51
55
  span&.status = ::OpenTelemetry::Trace::Status.error("Unhandled exception of type: #{error.class}")
@@ -54,5 +58,17 @@ module Trace
54
58
  span&.finish
55
59
  end
56
60
  end
61
+
62
+ def trace_span_context(span)
63
+ context = span.context
64
+
65
+ return Context.new(
66
+ context.trace_id,
67
+ context.span_id,
68
+ context.trace_flags,
69
+ context.tracestate,
70
+ remote: context.remote?
71
+ )
72
+ end
57
73
  end
58
74
  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
@@ -0,0 +1,36 @@
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
+ begin
27
+ path = File.join('backend', backend)
28
+ require_relative(path)
29
+ rescue LoadError
30
+ require(backend)
31
+ end
32
+ end
33
+ end
34
+ end
35
+
36
+ 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.0"
24
+ VERSION = "0.4.2"
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.0
4
+ version: 0.4.2
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
@@ -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