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 CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA256:
3
- metadata.gz: 5607b84ea305909814070a3f676a482f8bcba4e5cdd9c02a596c2ff5b3339581
4
- data.tar.gz: 77dd122a80f5076fd4e756fd1c1b552d39e3933590e5d9e4eabc6cfaf99a2029
3
+ metadata.gz: cd200edfec93129f39eebd5392882e8ca951912af2b9b356c292b6c74fcdc6d1
4
+ data.tar.gz: a19278327e308d97e1ae78687997c5422bf4d6ac1ed4dd9936dd64d3af5ac237
5
5
  SHA512:
6
- metadata.gz: cd270af76e74ef101e0aa96fd4c12a8447ee816915f0396242908124b4b32257a6c13fc8121c1aa7cd3c8afccdbaf9ce8fb20a5808c2e4180a5899f51f51a9d1
7
- data.tar.gz: 7198fdcbfc650f41cc3bdc6487481d9aa1a3e1e180bda5ae851ea116d0eff9bb2c11688b5b72483d88362dfefcb7dcd16be9777d80b58ac7386bf585bbddd488
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,7 +1,7 @@
1
1
  # frozen_string_literal: true
2
2
 
3
3
  # Released under the MIT License.
4
- # Copyright, 2021-2022, by Samuel Williams.
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
@@ -4,5 +4,5 @@
4
4
  # Copyright, 2021-2022, by Samuel Williams.
5
5
 
6
6
  module Traces
7
- VERSION = "0.8.0"
7
+ VERSION = "0.9.0"
8
8
  end
data/license.md CHANGED
@@ -1,6 +1,6 @@
1
1
  # MIT License
2
2
 
3
- Copyright, 2021-2022, by Samuel Williams.
3
+ Copyright, 2021-2023, by Samuel Williams.
4
4
  Copyright, 2022, by Felix Yan.
5
5
 
6
6
  Permission is hereby granted, free of charge, to any person obtaining a copy
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.8.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: 2022-11-10 00:00:00.000000000 Z
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.3.7
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