rspec-otel 0.0.3 → 0.0.4

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: ea44639a383fcb72b5c235528dc72363e0f3b431198e97c7d0c740bd5032bcd1
4
- data.tar.gz: ed21a83d381fc8441ac7e09aa6e06d48582bbb256eaf0f5830c02363d4308f7d
3
+ metadata.gz: '081125f70f4963d1a9f414811abbbe65e0113a14131a0cc982a2ce9247b447c5'
4
+ data.tar.gz: ab28a32cc178212a05e0216ad84a6300eb4509c17537d4499df6d0b2dfa4fd30
5
5
  SHA512:
6
- metadata.gz: b59d5eb23c4e42a7fb8489ca49a68aed7adf095da7277ea7e372648f678e39851dc5d4bc31e4ecaf8d3fef9d55ff5129168898bbde7430a0fde4feb851a746ee
7
- data.tar.gz: 5270c5b5dd720e89e5243cfddeb26ac3aac76d44ff4ef42b75b79fe13667825b1633db676323c573a5d7154a3470e311aaae39f7c4ca1e640b0e323833c450aa
6
+ metadata.gz: d867cbc82ace4ea550c9c14024dc91db343964d749a13075f9a947f4193cdfbbba434270ba85d6de01ae7cdfc919a5ad388a13d7dc903f9dbd06ed1ea4bde0f3
7
+ data.tar.gz: ff369cb3a9390130bdd354cc5ac99e7b0136525f8d39bb9c5fe793d2142843edc48a9556efe232b2b6397554561d1a17dfb2e39ae36fa6b2494a54af0ab23323
data/README.md CHANGED
@@ -44,10 +44,14 @@ 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.
@@ -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.3'
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.3
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-06-20 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