rspec-otel 0.0.2 → 0.0.4

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: 2157d604dda12e0b5a3a31d5f43659ef015578f772cb0bd93ac61fafdc8946ee
4
- data.tar.gz: 5b41c471c61f4fdb603585c52855c350f4e67de3776d7eb5718252b5bc0e875f
3
+ metadata.gz: '081125f70f4963d1a9f414811abbbe65e0113a14131a0cc982a2ce9247b447c5'
4
+ data.tar.gz: ab28a32cc178212a05e0216ad84a6300eb4509c17537d4499df6d0b2dfa4fd30
5
5
  SHA512:
6
- metadata.gz: bf5b6711af8c60e5cd9d2e46c580b6fe59aa87438154b585c77cc55ad4cf12933f1bf7bb9db4f686cadc124e397805fb8a028fb7f7744c86d44d297f5ec46e2d
7
- data.tar.gz: 4ee5c3e4deed68810dca54d594d7cc6002b9ef4d15133aeb37e5f77deebbd2a0b952308dfd50df60d1ec62c4a68b52ffca8c7e5e97c3de74b885d53f72007cca
6
+ metadata.gz: d867cbc82ace4ea550c9c14024dc91db343964d749a13075f9a947f4193cdfbbba434270ba85d6de01ae7cdfc919a5ad388a13d7dc903f9dbd06ed1ea4bde0f3
7
+ data.tar.gz: ff369cb3a9390130bdd354cc5ac99e7b0136525f8d39bb9c5fe793d2142843edc48a9556efe232b2b6397554561d1a17dfb2e39ae36fa6b2494a54af0ab23323
data/README.md CHANGED
@@ -44,12 +44,21 @@ end
44
44
 
45
45
  Several conditions can be added to the matcher:
46
46
 
47
+ * `as_root` - Will match spans that are the root of a trace.
48
+ * `as_child` - Will match spans that are not the root of a trace
47
49
  * `with_attributes` - Will match only the spans with the specified attributes.
48
50
  * `without_attributes` - Will only match the spans that do not have the specified attributes
49
51
  * `with_event` - Will match only the spans with the specified event.
50
52
  * `without_event` - Will only match the spans that do not have the specified event
53
+ * `with_link` - Will match only the spans with the specified link.
54
+ * `without_link` - Will only match the spans that do not have the specified link
51
55
  * `with_status` - Will match only the spans that have the proper status.
52
56
  * `with_exception` - Will match only the spans that have the specified exception event.
53
57
  * `without_exception` - Will match only the spans that do not have the specified exception event.
54
58
 
55
59
  The `*_event` condition can be called multiple times with different events.
60
+
61
+ ## Compatibility
62
+
63
+ RSpec Otel ensures compatibility with the currently supported versions of the
64
+ [Ruby Language](https://www.ruby-lang.org/en/downloads/branches/).
@@ -2,7 +2,7 @@
2
2
 
3
3
  module RspecOtel
4
4
  module Matchers
5
- class EmitSpan
5
+ class EmitSpan # rubocop:disable Metrics/ClassLength
6
6
  attr_reader :name
7
7
 
8
8
  def initialize(name = nil)
@@ -26,6 +26,22 @@ module RspecOtel
26
26
  false
27
27
  end
28
28
 
29
+ def as_child
30
+ @filters << lambda do |span|
31
+ span.parent_span_id && span.parent_span_id != OpenTelemetry::Trace::INVALID_SPAN_ID
32
+ end
33
+
34
+ self
35
+ end
36
+
37
+ def as_root
38
+ @filters << lambda do |span|
39
+ span.parent_span_id == OpenTelemetry::Trace::INVALID_SPAN_ID
40
+ end
41
+
42
+ self
43
+ end
44
+
29
45
  def with_attributes(attributes)
30
46
  @filters << lambda do |span|
31
47
  attributes_match?(span.attributes, attributes)
@@ -42,17 +58,39 @@ module RspecOtel
42
58
  self
43
59
  end
44
60
 
61
+ def with_link(attributes = {})
62
+ @filters << lambda do |span|
63
+ span.links &&
64
+ link_match?(span.links, attributes)
65
+ end
66
+
67
+ self
68
+ end
69
+
70
+ def without_link(attributes = {})
71
+ @filters << lambda do |span|
72
+ span.links.nil? ||
73
+ !link_match?(span.links, attributes)
74
+ end
75
+
76
+ self
77
+ end
78
+
45
79
  def with_event(name, attributes = {})
46
80
  @filters << lambda do |span|
47
- event_match?(span.events, OpenTelemetry::SDK::Trace::Event.new(name, attributes))
81
+ span.events &&
82
+ event_match?(span.events, OpenTelemetry::SDK::Trace::Event.new(name, attributes))
48
83
  end
84
+
49
85
  self
50
86
  end
51
87
 
52
88
  def without_event(name, attributes = {})
53
89
  @filters << lambda do |span|
54
- !event_match?(span.events, OpenTelemetry::SDK::Trace::Event.new(name, attributes))
90
+ span.events.nil? ||
91
+ !event_match?(span.events, OpenTelemetry::SDK::Trace::Event.new(name, attributes))
55
92
  end
93
+
56
94
  self
57
95
  end
58
96
 
@@ -112,8 +150,6 @@ module RspecOtel
112
150
  end
113
151
 
114
152
  def event_match?(span_events, event)
115
- return true if span_events.nil?
116
-
117
153
  se = span_events.select do |s|
118
154
  s.name == event.name &&
119
155
  attributes_match?(s.attributes, event.attributes || {})
@@ -121,6 +157,14 @@ module RspecOtel
121
157
 
122
158
  !se.empty?
123
159
  end
160
+
161
+ def link_match?(links, attributes)
162
+ link = links.select do |l|
163
+ attributes_match?(l.attributes, attributes || {})
164
+ end
165
+
166
+ !link.empty?
167
+ end
124
168
  end
125
169
  end
126
170
  end
@@ -1,5 +1,5 @@
1
1
  # frozen_string_literal: true
2
2
 
3
3
  module RspecOtel
4
- VERSION = '0.0.2'
4
+ VERSION = '0.0.4'
5
5
  end
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: rspec-otel
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.0.2
4
+ version: 0.0.4
5
5
  platform: ruby
6
6
  authors:
7
7
  - Damien MATHIEU
8
8
  autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
- date: 2024-02-14 00:00:00.000000000 Z
11
+ date: 2024-08-23 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: opentelemetry-api
@@ -86,7 +86,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
86
86
  - !ruby/object:Gem::Version
87
87
  version: '0'
88
88
  requirements: []
89
- rubygems_version: 3.5.3
89
+ rubygems_version: 3.5.6
90
90
  signing_key:
91
91
  specification_version: 4
92
92
  summary: RSpec matchers for the OpenTelemetry framework