traces 0.8.0 → 0.9.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 +87 -0
- data/lib/traces/context.rb +15 -1
- data/lib/traces/version.rb +1 -1
- data/license.md +1 -1
- data.tar.gz.sig +0 -0
- metadata +4 -3
- 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: cd200edfec93129f39eebd5392882e8ca951912af2b9b356c292b6c74fcdc6d1
|
4
|
+
data.tar.gz: a19278327e308d97e1ae78687997c5422bf4d6ac1ed4dd9936dd64d3af5ac237
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
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
|
data/lib/traces/context.rb
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
# frozen_string_literal: true
|
2
2
|
|
3
3
|
# Released under the MIT License.
|
4
|
-
# Copyright, 2021-
|
4
|
+
# Copyright, 2021-2023, by Samuel Williams.
|
5
5
|
|
6
6
|
require 'securerandom'
|
7
7
|
|
@@ -86,5 +86,19 @@ module Traces
|
|
86
86
|
def to_s
|
87
87
|
"00-#{@trace_id}-#{@parent_id}-#{@flags.to_s(16)}"
|
88
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
|
89
103
|
end
|
90
104
|
end
|
data/lib/traces/version.rb
CHANGED
data/license.md
CHANGED
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.9.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:
|
41
|
+
date: 2023-03-04 00:00:00.000000000 Z
|
42
42
|
dependencies:
|
43
43
|
- !ruby/object:Gem::Dependency
|
44
44
|
name: bake-test
|
@@ -104,6 +104,7 @@ extra_rdoc_files: []
|
|
104
104
|
files:
|
105
105
|
- lib/traces.rb
|
106
106
|
- lib/traces/backend.rb
|
107
|
+
- lib/traces/backend/capture.rb
|
107
108
|
- lib/traces/backend/console.rb
|
108
109
|
- lib/traces/backend/test.rb
|
109
110
|
- lib/traces/context.rb
|
@@ -130,7 +131,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
|
|
130
131
|
- !ruby/object:Gem::Version
|
131
132
|
version: '0'
|
132
133
|
requirements: []
|
133
|
-
rubygems_version: 3.
|
134
|
+
rubygems_version: 3.4.6
|
134
135
|
signing_key:
|
135
136
|
specification_version: 4
|
136
137
|
summary: Application instrumentation and tracing.
|
metadata.gz.sig
CHANGED
Binary file
|