bitfab 0.20.0 → 0.20.1
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 +4 -4
- data/lib/bitfab/replay.rb +16 -0
- data/lib/bitfab/traceable.rb +36 -0
- data/lib/bitfab/version.rb +1 -1
- metadata +1 -1
checksums.yaml
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
---
|
|
2
2
|
SHA256:
|
|
3
|
-
metadata.gz:
|
|
4
|
-
data.tar.gz:
|
|
3
|
+
metadata.gz: cd571926bd40dc39f337e87f9977bfb0fe3219c21532dc1cf7be382c175a4559
|
|
4
|
+
data.tar.gz: 17ff724ae1a42f97fa6eae82c97404de8dc9cef738a18674d76da48ba9ea762d
|
|
5
5
|
SHA512:
|
|
6
|
-
metadata.gz:
|
|
7
|
-
data.tar.gz:
|
|
6
|
+
metadata.gz: 012d3433d2d59200c812557a95b4f2b7cb8d93d7885d9495f59b7e21d89a892ffcc3c0bb83200f4c9f324320d5a1153f4c59bd2facac2dc1924174a7f184d81f
|
|
7
|
+
data.tar.gz: 69aaffc897238560ebecf6fedbd81509eda58fd082126107585a913cc74a025456a32111356902251a0c5b3439ff2b84ef7ea5aac4325a10e531c93a5d460334
|
data/lib/bitfab/replay.rb
CHANGED
|
@@ -2,6 +2,7 @@
|
|
|
2
2
|
|
|
3
3
|
require_relative "constants"
|
|
4
4
|
require_relative "serialize"
|
|
5
|
+
require_relative "traceable"
|
|
5
6
|
|
|
6
7
|
module Bitfab
|
|
7
8
|
# Replay mock strategies. Mirrors the Python and TypeScript SDKs.
|
|
@@ -117,6 +118,21 @@ module Bitfab
|
|
|
117
118
|
"determines how many traces replay."
|
|
118
119
|
end
|
|
119
120
|
|
|
121
|
+
# Reject a trace_function_key that contradicts the method's declared key.
|
|
122
|
+
# replay() fetches historical traces by trace_function_key but records the
|
|
123
|
+
# replayed spans under the method's own bitfab_span key (via send below),
|
|
124
|
+
# so a mismatch produces an incoherent test run (traces fetched for one
|
|
125
|
+
# function, recorded under another). Only fires when the method's key is
|
|
126
|
+
# introspectable; an untraced method falls through to the persistence
|
|
127
|
+
# check in complete_replay. Mirrors the TypeScript/Python SDKs.
|
|
128
|
+
declared_key = Traceable.trace_function_key_for(receiver, method_name)
|
|
129
|
+
if declared_key && declared_key != trace_function_key
|
|
130
|
+
raise ArgumentError,
|
|
131
|
+
"Method #{method_name} is traced under trace function key '#{declared_key}' but replay was " \
|
|
132
|
+
"called with '#{trace_function_key}'. Pass trace_function_key: '#{declared_key}' to replay it, " \
|
|
133
|
+
"or point at the method traced under '#{trace_function_key}'."
|
|
134
|
+
end
|
|
135
|
+
|
|
120
136
|
http_client = client.instance_variable_get(:@http_client)
|
|
121
137
|
|
|
122
138
|
# limit is meaningless with explicit trace_ids (the ID list determines
|
data/lib/bitfab/traceable.rb
CHANGED
|
@@ -69,9 +69,43 @@ module Bitfab
|
|
|
69
69
|
end
|
|
70
70
|
end
|
|
71
71
|
|
|
72
|
+
wrapper.instance_variable_set(:@bitfab_span_method, method_name_str)
|
|
73
|
+
wrapper.instance_variable_set(:@bitfab_span_key, trace_function_key)
|
|
72
74
|
klass.prepend(wrapper)
|
|
73
75
|
end
|
|
74
76
|
|
|
77
|
+
# Resolve the trace function key a traced method records spans under, or
|
|
78
|
+
# nil if the method carries no Bitfab span wrapper. Walks the receiver's
|
|
79
|
+
# ancestor chain for the wrapper module that bitfab_span / Traceable.wrap
|
|
80
|
+
# prepended. Instances resolve via the class. A Class/Module receiver
|
|
81
|
+
# resolves either way: singleton-class ancestors first (class/module
|
|
82
|
+
# methods wrapped on the singleton class), then the class's own ancestors
|
|
83
|
+
# (methods whose wrapper was prepended onto the class itself), so a
|
|
84
|
+
# class-method replay is guarded regardless of which surface carries the
|
|
85
|
+
# wrapper. Singleton-first keeps the method actually dispatched by
|
|
86
|
+
# `receiver.send` (a class method shadows a same-named instance wrapper).
|
|
87
|
+
#
|
|
88
|
+
# replay() uses this to reject a trace_function_key that contradicts the
|
|
89
|
+
# method's declared key: a mismatch fetches one function's historical
|
|
90
|
+
# traces but re-records the replay under the method's own key, producing
|
|
91
|
+
# an incoherent test run. Mirrors the TypeScript and Python SDKs, which
|
|
92
|
+
# throw on the same key mismatch.
|
|
93
|
+
def self.trace_function_key_for(receiver, method_name)
|
|
94
|
+
name = method_name.to_s
|
|
95
|
+
ancestors = if receiver.is_a?(Module)
|
|
96
|
+
receiver.singleton_class.ancestors + receiver.ancestors
|
|
97
|
+
else
|
|
98
|
+
receiver.class.ancestors
|
|
99
|
+
end
|
|
100
|
+
ancestors.each do |mod|
|
|
101
|
+
next unless mod.instance_variable_defined?(:@bitfab_span_method)
|
|
102
|
+
next unless mod.instance_variable_get(:@bitfab_span_method) == name
|
|
103
|
+
|
|
104
|
+
return mod.instance_variable_get(:@bitfab_span_key)
|
|
105
|
+
end
|
|
106
|
+
nil
|
|
107
|
+
end
|
|
108
|
+
|
|
75
109
|
module ClassMethods
|
|
76
110
|
# Set the trace function key for this class.
|
|
77
111
|
# All spans declared in this class will be grouped under this key.
|
|
@@ -152,6 +186,8 @@ module Bitfab
|
|
|
152
186
|
end
|
|
153
187
|
end
|
|
154
188
|
|
|
189
|
+
wrapper.instance_variable_set(:@bitfab_span_method, method_name_str)
|
|
190
|
+
wrapper.instance_variable_set(:@bitfab_span_key, trace_function_key)
|
|
155
191
|
prepend(wrapper)
|
|
156
192
|
end
|
|
157
193
|
end
|
data/lib/bitfab/version.rb
CHANGED