traces 0.7.0 → 0.9.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: b772ba31eff5f29bc6ac7c854709194783ea4005ce12f6d7030fa02ad3f8f281
4
- data.tar.gz: e080e451e146d7d660b4f2f4b0be503bc3c9e087759ec85e303164d0170991b3
3
+ metadata.gz: cd200edfec93129f39eebd5392882e8ca951912af2b9b356c292b6c74fcdc6d1
4
+ data.tar.gz: a19278327e308d97e1ae78687997c5422bf4d6ac1ed4dd9936dd64d3af5ac237
5
5
  SHA512:
6
- metadata.gz: c850a6dc1ec23c2bf6fc8a320fbe00f65837e0931f34ee8b9b86a8d9e492b44b9aebd7e402e5b05637ddb5750d7ef5c5a72346b426efcc9a15fba753828c6778
7
- data.tar.gz: f1f906387a4de0a53ae71a5ec72a6951cce247e1cd31376a5b0532a5ba0c7a9d95cff94fedf60f468370b8db018b23566a3a81287c3e6b466f17e56dd1baeea8
6
+ metadata.gz: 27db1c0d2d4b346fb67a0127d31676be0808d84885a814ccb0ac373abde8c369efb5cbe048e15a0404c3bb1885fe799f0c35665df632eb00a5e7775ad78a3860
7
+ data.tar.gz: e7403e3bfb11718dbc4793e82d916b703605b996016d6885f2ec15d2a115886a73f075a6fcc1692289e872f260574f4badbae6f390616dd07a39dbb54e4b1bae
checksums.yaml.gz.sig CHANGED
Binary file
@@ -0,0 +1,87 @@
1
+ # frozen_string_literal: true
2
+
3
+ # Released under the MIT License.
4
+ # Copyright, 2023, by Samuel Williams.
5
+
6
+ require_relative '../context'
7
+
8
+ require 'fiber'
9
+
10
+ class Fiber
11
+ attr_accessor :traces_backend_context
12
+ end
13
+
14
+ module Traces
15
+ module Backend
16
+ # A backend which logs all spans to the Capture logger output.
17
+ module Capture
18
+ # A span which validates tag assignment.
19
+ class Span
20
+ def initialize(context, instance, name, resource, attributes)
21
+ @context = context
22
+ @instance = instance
23
+ @name = name
24
+ @resource = resource
25
+ @attributes = attributes
26
+ end
27
+
28
+ attr :context
29
+ attr :instance
30
+ attr :name
31
+ attr :resource
32
+ attr :attributes
33
+
34
+ # Assign some metadata to the span.
35
+ # @parameter key [String] The metadata key.
36
+ # @parameter value [Object] The metadata value. Should be coercable to a string.
37
+ def []= key, value
38
+ @attributes[key] = value
39
+ end
40
+
41
+ def as_json
42
+ {
43
+ name: @name,
44
+ resource: @resource,
45
+ attributes: @attributes,
46
+ context: @context.as_json
47
+ }
48
+ end
49
+
50
+ def to_json(...)
51
+ as_json.to_json(...)
52
+ end
53
+ end
54
+
55
+ def self.spans
56
+ @spans ||= []
57
+ end
58
+
59
+ module Interface
60
+ # Trace the given block of code and log the execution.
61
+ # @parameter name [String] A useful name/annotation for the recorded span.
62
+ # @parameter attributes [Hash] Metadata for the recorded span.
63
+ def trace(name, resource: self, attributes: {}, &block)
64
+ context = Context.nested(Fiber.current.traces_backend_context)
65
+ Fiber.current.traces_backend_context = context
66
+
67
+ span = Span.new(context, self, name, resource, attributes)
68
+ Capture.spans << span
69
+
70
+ yield span
71
+ end
72
+
73
+ # Assign a trace context to the current execution scope.
74
+ def trace_context= context
75
+ Fiber.current.traces_backend_context = context
76
+ end
77
+
78
+ # Get a trace context from the current execution scope.
79
+ def trace_context
80
+ Fiber.current.traces_backend_context
81
+ end
82
+ end
83
+ end
84
+
85
+ Interface = Capture::Interface
86
+ end
87
+ end
@@ -1,24 +1,7 @@
1
1
  # frozen_string_literal: true
2
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.
3
+ # Released under the MIT License.
4
+ # Copyright, 2021-2022, by Samuel Williams.
22
5
 
23
6
  require_relative '../context'
24
7
 
@@ -1,24 +1,7 @@
1
1
  # frozen_string_literal: true
2
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.
3
+ # Released under the MIT License.
4
+ # Copyright, 2021-2022, by Samuel Williams.
22
5
 
23
6
  require_relative '../context'
24
7
  require 'fiber'
@@ -1,24 +1,7 @@
1
1
  # frozen_string_literal: true
2
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.
3
+ # Released under the MIT License.
4
+ # Copyright, 2021-2022, by Samuel Williams.
22
5
 
23
6
  module Traces
24
7
  # Require a specific trace backend.
@@ -1,24 +1,7 @@
1
1
  # frozen_string_literal: true
2
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.
3
+ # Released under the MIT License.
4
+ # Copyright, 2021-2023, by Samuel Williams.
22
5
 
23
6
  require 'securerandom'
24
7
 
@@ -103,5 +86,19 @@ module Traces
103
86
  def to_s
104
87
  "00-#{@trace_id}-#{@parent_id}-#{@flags.to_s(16)}"
105
88
  end
89
+
90
+ def as_json
91
+ {
92
+ trace_id: @trace_id,
93
+ parent_id: @parent_id,
94
+ flags: @flags,
95
+ state: @state,
96
+ remote: @remote
97
+ }
98
+ end
99
+
100
+ def to_json(...)
101
+ as_json.to_json(...)
102
+ end
106
103
  end
107
104
  end
@@ -1,24 +1,7 @@
1
1
  # frozen_string_literal: true
2
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.
3
+ # Released under the MIT License.
4
+ # Copyright, 2021-2022, by Samuel Williams.
22
5
 
23
6
  require_relative 'backend'
24
7
 
@@ -51,7 +34,9 @@ module Traces
51
34
 
52
35
  klass.prepend(provider)
53
36
 
54
- provider.module_exec(&block)
37
+ provider.module_exec(&block) if block_given?
38
+
39
+ return provider
55
40
  end
56
41
  else
57
42
  def self.Provider(klass, &block)
@@ -1,25 +1,8 @@
1
1
  # frozen_string_literal: true
2
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.
3
+ # Released under the MIT License.
4
+ # Copyright, 2021-2022, by Samuel Williams.
22
5
 
23
6
  module Traces
24
- VERSION = "0.7.0"
7
+ VERSION = "0.9.0"
25
8
  end
data/lib/traces.rb CHANGED
@@ -1,24 +1,7 @@
1
1
  # frozen_string_literal: true
2
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.
3
+ # Released under the MIT License.
4
+ # Copyright, 2021-2022, by Samuel Williams.
22
5
 
23
6
  require_relative 'traces/version'
24
7
  require_relative 'traces/provider'
data/license.md ADDED
@@ -0,0 +1,22 @@
1
+ # MIT License
2
+
3
+ Copyright, 2021-2023, by Samuel Williams.
4
+ Copyright, 2022, by Felix Yan.
5
+
6
+ Permission is hereby granted, free of charge, to any person obtaining a copy
7
+ of this software and associated documentation files (the "Software"), to deal
8
+ in the Software without restriction, including without limitation the rights
9
+ to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
10
+ copies of the Software, and to permit persons to whom the Software is
11
+ furnished to do so, subject to the following conditions:
12
+
13
+ The above copyright notice and this permission notice shall be included in all
14
+ copies or substantial portions of the Software.
15
+
16
+ THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
17
+ IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
18
+ FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
19
+ AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
20
+ LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
21
+ OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
22
+ SOFTWARE.
data/readme.md ADDED
@@ -0,0 +1,30 @@
1
+ # Traces
2
+
3
+ Capture nested traces during code execution in a vendor agnostic way.
4
+
5
+ [![Development Status](https://github.com/socketry/traces/workflows/Test/badge.svg)](https://github.com/socketry/traces/actions?workflow=Test)
6
+
7
+ ## Features
8
+
9
+ - Zero-overhead if tracing is disabled and minimal overhead if enabled.
10
+ - Small opinionated interface with standardised semantics, consistent with the [W3C Trace Context Specification](https://github.com/w3c/trace-context).
11
+
12
+ ## Usage
13
+
14
+ Please see the [project documentation](https://socketry.github.io/traces).
15
+
16
+ ## Contributing
17
+
18
+ We welcome contributions to this project.
19
+
20
+ 1. Fork it
21
+ 2. Create your feature branch (`git checkout -b my-new-feature`)
22
+ 3. Commit your changes (`git commit -am 'Add some feature'`)
23
+ 4. Push to the branch (`git push origin my-new-feature`)
24
+ 5. Create new Pull Request
25
+
26
+ ## See Also
27
+
28
+ - [traces-backend-open\_telemetry](https://github.com/socketry/traces-backend-open_telemetry) — A backend for submitting traces to [OpenTelemetry](https://github.com/open-telemetry/opentelemetry-ruby), including [ScoutAPM](https://github.com/scoutapp/scout_apm_ruby).
29
+ - [traces-backend-datadog](https://github.com/socketry/traces-backend-datadog) — A backend for submitting traces to [Datadog](https://github.com/DataDog/dd-trace-rb).
30
+ - [metrics](https://github.com/socketry/metrics) — A metrics interface which follows a similar pattern.
data.tar.gz.sig CHANGED
Binary file
metadata CHANGED
@@ -1,10 +1,11 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: traces
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.7.0
4
+ version: 0.9.0
5
5
  platform: ruby
6
6
  authors:
7
7
  - Samuel Williams
8
+ - Felix Yan
8
9
  autorequire:
9
10
  bindir: bin
10
11
  cert_chain:
@@ -37,7 +38,7 @@ cert_chain:
37
38
  Q2K9NVun/S785AP05vKkXZEFYxqG6EW012U4oLcFl5MySFajYXRYbuUpH6AY+HP8
38
39
  voD0MPg1DssDLKwXyt1eKD/+Fq0bFWhwVM/1XiAXL7lyYUyOq24KHgQ2Csg=
39
40
  -----END CERTIFICATE-----
40
- date: 2022-09-05 00:00:00.000000000 Z
41
+ date: 2023-03-04 00:00:00.000000000 Z
41
42
  dependencies:
42
43
  - !ruby/object:Gem::Dependency
43
44
  name: bake-test
@@ -103,11 +104,14 @@ extra_rdoc_files: []
103
104
  files:
104
105
  - lib/traces.rb
105
106
  - lib/traces/backend.rb
107
+ - lib/traces/backend/capture.rb
106
108
  - lib/traces/backend/console.rb
107
109
  - lib/traces/backend/test.rb
108
110
  - lib/traces/context.rb
109
111
  - lib/traces/provider.rb
110
112
  - lib/traces/version.rb
113
+ - license.md
114
+ - readme.md
111
115
  homepage: https://github.com/socketry/traces
112
116
  licenses:
113
117
  - MIT
@@ -127,7 +131,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
127
131
  - !ruby/object:Gem::Version
128
132
  version: '0'
129
133
  requirements: []
130
- rubygems_version: 3.3.7
134
+ rubygems_version: 3.4.6
131
135
  signing_key:
132
136
  specification_version: 4
133
137
  summary: Application instrumentation and tracing.
metadata.gz.sig CHANGED
Binary file