traces 0.13.1 → 0.14.0
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- checksums.yaml.gz.sig +0 -0
- data/lib/traces/backend/capture.rb +10 -3
- data/lib/traces/backend/console.rb +6 -3
- data/lib/traces/backend/test.rb +6 -3
- data/lib/traces/backend.rb +4 -19
- data/lib/traces/config.rb +56 -0
- data/lib/traces/context.rb +10 -2
- data/lib/traces/provider.rb +1 -0
- data/lib/traces/version.rb +1 -1
- data/lib/traces.rb +4 -0
- data/readme.md +15 -1
- data/releases.md +18 -0
- data.tar.gz.sig +0 -0
- metadata +4 -2
- metadata.gz.sig +0 -0
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA256:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 618c28f794dbd7fa30d3d211b50bb81a4bf785d8877f4512379d1f9bfc588032
|
4
|
+
data.tar.gz: 0e7dcc6c4e0f88a1721a06cf4225093d9375a15cfc2bf09ec3aa67e16448453b
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 8cf0fe5b427eca45083760ea6e5428f6b9a36ec00019ca55e4b505cd0edddd72c10c5d52fdca990a8e7676652cd72529f2f25a29298351625210702a9eb6111d
|
7
|
+
data.tar.gz: fe0a03d14440673a637843065cb48ff9a54be1c315e5c08b0117875e0b42642e268b6b087d2cb4d5f541abc6085aaf589fb23650eacffdd5f137abd90cf9c321
|
checksums.yaml.gz.sig
CHANGED
Binary file
|
@@ -7,9 +7,7 @@ require_relative '../context'
|
|
7
7
|
|
8
8
|
require 'fiber'
|
9
9
|
|
10
|
-
|
11
|
-
attr_accessor :traces_backend_context
|
12
|
-
end
|
10
|
+
Fiber.attr_accessor :traces_backend_context
|
13
11
|
|
14
12
|
module Traces
|
15
13
|
module Backend
|
@@ -17,6 +15,11 @@ module Traces
|
|
17
15
|
module Capture
|
18
16
|
# A span which validates tag assignment.
|
19
17
|
class Span
|
18
|
+
# Initialize a new span.
|
19
|
+
# @parameter context [Context] The context in which the span is recorded.
|
20
|
+
# @parameter name [String] A useful name/annotation for the recorded span.
|
21
|
+
# @parameter resource [String] The "resource" that the span is associated with.
|
22
|
+
# @parameter attributes [Hash] Metadata for the recorded span.
|
20
23
|
def initialize(context, name, resource, attributes)
|
21
24
|
@context = context
|
22
25
|
@name = name
|
@@ -36,6 +39,7 @@ module Traces
|
|
36
39
|
@attributes[key] = value
|
37
40
|
end
|
38
41
|
|
42
|
+
# Convert the span to a JSON representation.
|
39
43
|
def as_json
|
40
44
|
{
|
41
45
|
name: @name,
|
@@ -45,15 +49,18 @@ module Traces
|
|
45
49
|
}
|
46
50
|
end
|
47
51
|
|
52
|
+
# Convert the span to a JSON string.
|
48
53
|
def to_json(...)
|
49
54
|
as_json.to_json(...)
|
50
55
|
end
|
51
56
|
end
|
52
57
|
|
58
|
+
# All captured spans.
|
53
59
|
def self.spans
|
54
60
|
@spans ||= []
|
55
61
|
end
|
56
62
|
|
63
|
+
# The capture backend interface.
|
57
64
|
module Interface
|
58
65
|
# Trace the given block of code and log the execution.
|
59
66
|
# @parameter name [String] A useful name/annotation for the recorded span.
|
@@ -8,9 +8,7 @@ require_relative '../context'
|
|
8
8
|
require 'console'
|
9
9
|
require 'fiber'
|
10
10
|
|
11
|
-
|
12
|
-
attr_accessor :traces_backend_context
|
13
|
-
end
|
11
|
+
Fiber.attr_accessor :traces_backend_context
|
14
12
|
|
15
13
|
module Traces
|
16
14
|
module Backend
|
@@ -18,11 +16,15 @@ module Traces
|
|
18
16
|
module Console
|
19
17
|
# A span which validates tag assignment.
|
20
18
|
class Span
|
19
|
+
# Initialize a new span.
|
20
|
+
# @parameter context [Context] The context in which the span is recorded.
|
21
|
+
# @parameter name [String] A useful name/annotation for the recorded span.
|
21
22
|
def initialize(context, name)
|
22
23
|
@context = context
|
23
24
|
@name = name
|
24
25
|
end
|
25
26
|
|
27
|
+
# @attribute [Context] The context in which the span is recorded.
|
26
28
|
attr :context
|
27
29
|
|
28
30
|
# Assign some metadata to the span.
|
@@ -33,6 +35,7 @@ module Traces
|
|
33
35
|
end
|
34
36
|
end
|
35
37
|
|
38
|
+
# The console backend interface.
|
36
39
|
module Interface
|
37
40
|
# Trace the given block of code and log the execution.
|
38
41
|
# @parameter name [String] A useful name/annotation for the recorded span.
|
data/lib/traces/backend/test.rb
CHANGED
@@ -4,11 +4,10 @@
|
|
4
4
|
# Copyright, 2021-2023, by Samuel Williams.
|
5
5
|
|
6
6
|
require_relative '../context'
|
7
|
+
|
7
8
|
require 'fiber'
|
8
9
|
|
9
|
-
|
10
|
-
attr_accessor :traces_backend_context
|
11
|
-
end
|
10
|
+
Fiber.attr_accessor :traces_backend_context
|
12
11
|
|
13
12
|
module Traces
|
14
13
|
module Backend
|
@@ -16,10 +15,13 @@ module Traces
|
|
16
15
|
module Test
|
17
16
|
# A span which validates tag assignment.
|
18
17
|
class Span
|
18
|
+
# Initialize a new span.
|
19
|
+
# @parameter context [Context] The context in which the span is recorded.
|
19
20
|
def initialize(context)
|
20
21
|
@context = context
|
21
22
|
end
|
22
23
|
|
24
|
+
# @attribute [Context] The context in which the span is recorded.
|
23
25
|
attr :context
|
24
26
|
|
25
27
|
# Assign some metadata to the span.
|
@@ -38,6 +40,7 @@ module Traces
|
|
38
40
|
end
|
39
41
|
end
|
40
42
|
|
43
|
+
# The test backend interface.
|
41
44
|
module Interface
|
42
45
|
# Trace the given block of code and validate the interface usage.
|
43
46
|
# @parameter name [String] A useful name/annotation for the recorded span.
|
data/lib/traces/backend.rb
CHANGED
@@ -3,27 +3,12 @@
|
|
3
3
|
# Released under the MIT License.
|
4
4
|
# Copyright, 2021-2023, by Samuel Williams.
|
5
5
|
|
6
|
-
|
6
|
+
require_relative 'config'
|
7
7
|
|
8
8
|
module Traces
|
9
|
+
# The backend implementation is responsible for recording and reporting traces.
|
9
10
|
module Backend
|
10
|
-
# Require a specific trace backend.
|
11
|
-
def self.require_backend(env = ENV)
|
12
|
-
if backend = env['TRACES_BACKEND']
|
13
|
-
begin
|
14
|
-
require(backend)
|
15
|
-
rescue LoadError => error
|
16
|
-
::Console::Event::Failure.for(error).emit(self, "Unable to load traces backend!", backend: backend, severity: :warn)
|
17
|
-
|
18
|
-
return false
|
19
|
-
end
|
20
|
-
|
21
|
-
Traces.extend(Backend::Interface)
|
22
|
-
|
23
|
-
return true
|
24
|
-
end
|
25
|
-
end
|
26
11
|
end
|
12
|
+
|
13
|
+
Config::DEFAULT.require_backend
|
27
14
|
end
|
28
|
-
|
29
|
-
Traces::Backend.require_backend
|
@@ -0,0 +1,56 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
3
|
+
# Released under the MIT License.
|
4
|
+
# Copyright, 2024, by Samuel Williams.
|
5
|
+
|
6
|
+
module Traces
|
7
|
+
# Represents a configuration for the traces library.
|
8
|
+
class Config
|
9
|
+
DEFAULT_PATH = ENV.fetch("TRACES_CONFIG_DEFAULT_PATH", "config/traces.rb")
|
10
|
+
|
11
|
+
# Load the configuration from the given path.
|
12
|
+
# @parameter path [String] The path to the configuration file.
|
13
|
+
# @returns [Config] The loaded configuration.
|
14
|
+
def self.load(path)
|
15
|
+
config = self.new
|
16
|
+
|
17
|
+
if File.exist?(path)
|
18
|
+
config.instance_eval(File.read(path), path)
|
19
|
+
end
|
20
|
+
|
21
|
+
return config
|
22
|
+
end
|
23
|
+
|
24
|
+
# Load the default configuration.
|
25
|
+
# @returns [Config] The default configuration.
|
26
|
+
def self.default
|
27
|
+
@default ||= self.load(DEFAULT_PATH)
|
28
|
+
end
|
29
|
+
|
30
|
+
# Prepare the backend, e.g. by loading additional libraries or instrumentation.
|
31
|
+
def prepare
|
32
|
+
end
|
33
|
+
|
34
|
+
# Require a specific traces backend implementation.
|
35
|
+
def require_backend(env = ENV)
|
36
|
+
if backend = env['TRACES_BACKEND']
|
37
|
+
begin
|
38
|
+
if require(backend)
|
39
|
+
Traces.extend(Backend::Interface)
|
40
|
+
|
41
|
+
self.prepare
|
42
|
+
|
43
|
+
return true
|
44
|
+
end
|
45
|
+
rescue LoadError => error
|
46
|
+
::Console::Event::Failure.for(error).emit(self, "Unable to load traces backend!", backend: backend, severity: :warn)
|
47
|
+
end
|
48
|
+
end
|
49
|
+
|
50
|
+
return false
|
51
|
+
end
|
52
|
+
|
53
|
+
# Load the default configuration.
|
54
|
+
DEFAULT = self.default
|
55
|
+
end
|
56
|
+
end
|
data/lib/traces/context.rb
CHANGED
@@ -47,6 +47,12 @@ module Traces
|
|
47
47
|
|
48
48
|
SAMPLED = 0x01
|
49
49
|
|
50
|
+
# Initialize the trace context.
|
51
|
+
# @parameter trace_id [String] The ID of the whole trace forest.
|
52
|
+
# @parameter parent_id [String] The ID of this operation as known by the caller (sometimes referred to as the span ID).
|
53
|
+
# @parameter flags [Integer] An 8-bit field that controls tracing flags such as sampling, trace level, etc.
|
54
|
+
# @parameter state [Hash] Additional vendor-specific trace identification information.
|
55
|
+
# @parameter remote [Boolean] Whether this context was created from a distributed trace header.
|
50
56
|
def initialize(trace_id, parent_id, flags, state = nil, remote: false)
|
51
57
|
@trace_id = trace_id
|
52
58
|
@parent_id = parent_id
|
@@ -63,13 +69,13 @@ module Traces
|
|
63
69
|
# The ID of the whole trace forest and is used to uniquely identify a distributed trace through a system. It is represented as a 16-byte array, for example, 4bf92f3577b34da6a3ce929d0e0e4736. All bytes as zero (00000000000000000000000000000000) is considered an invalid value.
|
64
70
|
attr :trace_id
|
65
71
|
|
66
|
-
# The ID of this
|
72
|
+
# The ID of this operation as known by the caller (in some tracing systems, this is known as the span-id, where a span is the execution of a client operation). It is represented as an 8-byte array, for example, 00f067aa0ba902b7. All bytes as zero (0000000000000000) is considered an invalid value.
|
67
73
|
attr :parent_id
|
68
74
|
|
69
75
|
# An 8-bit field that controls tracing flags such as sampling, trace level, etc. These flags are recommendations given by the caller rather than strict rules.
|
70
76
|
attr :flags
|
71
77
|
|
72
|
-
# Provides additional vendor-specific trace identification information across different distributed tracing systems. Conveys information about the
|
78
|
+
# Provides additional vendor-specific trace identification information across different distributed tracing systems. Conveys information about the operation's position in multiple distributed tracing graphs.
|
73
79
|
attr :state
|
74
80
|
|
75
81
|
# Denotes that the caller may have recorded trace data. When unset, the caller did not record trace data out-of-band.
|
@@ -87,6 +93,7 @@ module Traces
|
|
87
93
|
"00-#{@trace_id}-#{@parent_id}-#{@flags.to_s(16)}"
|
88
94
|
end
|
89
95
|
|
96
|
+
# Convert the trace context to a JSON representation, including trace state.
|
90
97
|
def as_json
|
91
98
|
{
|
92
99
|
trace_id: @trace_id,
|
@@ -97,6 +104,7 @@ module Traces
|
|
97
104
|
}
|
98
105
|
end
|
99
106
|
|
107
|
+
# Convert the trace context to a JSON string.
|
100
108
|
def to_json(...)
|
101
109
|
as_json.to_json(...)
|
102
110
|
end
|
data/lib/traces/provider.rb
CHANGED
data/lib/traces/version.rb
CHANGED
data/lib/traces.rb
CHANGED
data/readme.md
CHANGED
@@ -11,7 +11,21 @@ Capture nested traces during code execution in a vendor agnostic way.
|
|
11
11
|
|
12
12
|
## Usage
|
13
13
|
|
14
|
-
Please see the [project documentation](https://socketry.github.io/traces).
|
14
|
+
Please see the [project documentation](https://socketry.github.io/traces/) for more details.
|
15
|
+
|
16
|
+
- [Getting Started](https://socketry.github.io/traces/guides/getting-started/index) - This guide explains how to use `traces` for tracing code execution.
|
17
|
+
|
18
|
+
- [Testing](https://socketry.github.io/traces/guides/testing/index) - This guide explains how to test traces in your code.
|
19
|
+
|
20
|
+
- [Capture](https://socketry.github.io/traces/guides/capture/index) - This guide explains how to use `traces` for exporting traces from your application. This can be used to document all possible traces.
|
21
|
+
|
22
|
+
## Releases
|
23
|
+
|
24
|
+
Please see the [project releases](https://socketry.github.io/traces/releases/index) for all releases.
|
25
|
+
|
26
|
+
### v0.14.0
|
27
|
+
|
28
|
+
- [Introduce `Traces::Config` to control tracing behavior](https://socketry.github.io/traces/releases/index#introduce-traces::config-to-control-tracing-behavior)
|
15
29
|
|
16
30
|
## Contributing
|
17
31
|
|
data/releases.md
ADDED
@@ -0,0 +1,18 @@
|
|
1
|
+
# Releases
|
2
|
+
|
3
|
+
## v0.14.0
|
4
|
+
|
5
|
+
### Introduce `Traces::Config` to control tracing behavior
|
6
|
+
|
7
|
+
There are some reasonable defaults for tracing, but sometimes you want to change them. Adding a `config/traces.rb` file to your project will allow you to do that.
|
8
|
+
|
9
|
+
``` ruby
|
10
|
+
# config/traces.rb
|
11
|
+
|
12
|
+
def prepare
|
13
|
+
require 'traces/provider/async'
|
14
|
+
require 'traces/provider/async/http'
|
15
|
+
end
|
16
|
+
```
|
17
|
+
|
18
|
+
The `prepare` method is called before the tracing is started but after the backend is required. You can require any provider you want in this file, or even add your own custom providers.
|
data.tar.gz.sig
CHANGED
Binary file
|
metadata
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: traces
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.
|
4
|
+
version: 0.14.0
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Samuel Williams
|
@@ -38,7 +38,7 @@ cert_chain:
|
|
38
38
|
Q2K9NVun/S785AP05vKkXZEFYxqG6EW012U4oLcFl5MySFajYXRYbuUpH6AY+HP8
|
39
39
|
voD0MPg1DssDLKwXyt1eKD/+Fq0bFWhwVM/1XiAXL7lyYUyOq24KHgQ2Csg=
|
40
40
|
-----END CERTIFICATE-----
|
41
|
-
date: 2024-
|
41
|
+
date: 2024-11-05 00:00:00.000000000 Z
|
42
42
|
dependencies: []
|
43
43
|
description:
|
44
44
|
email:
|
@@ -51,11 +51,13 @@ files:
|
|
51
51
|
- lib/traces/backend/capture.rb
|
52
52
|
- lib/traces/backend/console.rb
|
53
53
|
- lib/traces/backend/test.rb
|
54
|
+
- lib/traces/config.rb
|
54
55
|
- lib/traces/context.rb
|
55
56
|
- lib/traces/provider.rb
|
56
57
|
- lib/traces/version.rb
|
57
58
|
- license.md
|
58
59
|
- readme.md
|
60
|
+
- releases.md
|
59
61
|
homepage: https://github.com/socketry/traces
|
60
62
|
licenses:
|
61
63
|
- MIT
|
metadata.gz.sig
CHANGED
Binary file
|