bitfab 0.33.3 → 0.33.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 +4 -4
- data/lib/bitfab/client.rb +17 -3
- data/lib/bitfab/traceable.rb +17 -4
- 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: 12cae09488f9200115e768e31661e55be850acc2dbcf2b53eece9c4ab4d59ca2
|
|
4
|
+
data.tar.gz: 3242cb27cbd71d15094bc4024cb914a494eefa2eeee317e1d45c8ba77c77f4a0
|
|
5
5
|
SHA512:
|
|
6
|
-
metadata.gz:
|
|
7
|
-
data.tar.gz:
|
|
6
|
+
metadata.gz: 11f4111de6c94527b2f4b14757b50ccaddea211d3366bf1a5241e8e7e0ffa065138a84fa7f6db84baaec926cfeb9754fe7024a090b297ecb35e7916a1fc517f1
|
|
7
|
+
data.tar.gz: 880b440e2610064045ff1e753d65167c46be2a7220897aa0631b739e24affec2e99cd05de12acf2d39f162474d8fbec6ff13b614f60c6390529395ad2478e4ab
|
data/lib/bitfab/client.rb
CHANGED
|
@@ -243,12 +243,23 @@ module Bitfab
|
|
|
243
243
|
# Execute a block inside a span context, sending trace data on completion.
|
|
244
244
|
# Called by Traceable, not intended for direct use.
|
|
245
245
|
def execute_span(trace_function_key:, span_name:, span_type:, function_name:, args:, kwargs:,
|
|
246
|
-
mock_on_replay: false)
|
|
246
|
+
capture_when: "always", mock_on_replay: false)
|
|
247
247
|
# Decide at CALL time, not construction. The key may be set after the
|
|
248
248
|
# client is built (env loaded later), so re-checking per call lets a
|
|
249
249
|
# late-resolved key take effect.
|
|
250
250
|
return yield unless tracing_enabled?
|
|
251
251
|
|
|
252
|
+
resolved_capture_when = capture_when.to_s
|
|
253
|
+
unless %w[always nested].include?(resolved_capture_when)
|
|
254
|
+
Bitfab.warn_once(
|
|
255
|
+
"invalid-capture-when:#{trace_function_key}",
|
|
256
|
+
"unknown capture_when value #{capture_when.inspect}; defaulting to \"always\". " \
|
|
257
|
+
"Valid values: \"always\", \"nested\"."
|
|
258
|
+
)
|
|
259
|
+
resolved_capture_when = "always"
|
|
260
|
+
end
|
|
261
|
+
return yield if resolved_capture_when == "nested" && SpanContext.current.nil?
|
|
262
|
+
|
|
252
263
|
# Span setup runs before the user's block. Tracing is a side-channel, so
|
|
253
264
|
# if anything here raises (id generation, trace-state bookkeeping, a
|
|
254
265
|
# malformed replay mock tree) the user's method must still run. On failure
|
|
@@ -892,12 +903,15 @@ module Bitfab
|
|
|
892
903
|
# @param method_name [Symbol] the method to wrap
|
|
893
904
|
# @param name [String, nil] explicit span name (defaults to method name)
|
|
894
905
|
# @param type [String] span type
|
|
906
|
+
# @param capture_when [String, Symbol] "always" to allow a root trace, or
|
|
907
|
+
# "nested" to capture only when another Bitfab span is active. Unknown
|
|
908
|
+
# values warn once and default to "always"
|
|
895
909
|
# @param mock_on_replay [Boolean] mark this span for the default "marked" mock strategy
|
|
896
|
-
def wrap(klass, method_name, name: nil, type: "custom", mock_on_replay: false)
|
|
910
|
+
def wrap(klass, method_name, name: nil, type: "custom", capture_when: "always", mock_on_replay: false)
|
|
897
911
|
Bitfab::Traceable.wrap(
|
|
898
912
|
klass, method_name,
|
|
899
913
|
trace_function_key: @trace_function_key,
|
|
900
|
-
name:, type:, mock_on_replay:,
|
|
914
|
+
name:, type:, capture_when:, mock_on_replay:,
|
|
901
915
|
client: @client
|
|
902
916
|
)
|
|
903
917
|
end
|
data/lib/bitfab/traceable.rb
CHANGED
|
@@ -38,6 +38,9 @@ module Bitfab
|
|
|
38
38
|
# @param trace_function_key [String] the trace function key
|
|
39
39
|
# @param name [String, nil] explicit span name (defaults to method name)
|
|
40
40
|
# @param type [String] span type: llm, agent, function, guardrail, handoff, custom
|
|
41
|
+
# @param capture_when [String, Symbol] "always" to allow a root trace, or
|
|
42
|
+
# "nested" to capture only when another Bitfab span is active. Unknown
|
|
43
|
+
# values warn once and default to "always"
|
|
41
44
|
# @param mock_on_replay [Boolean] mark this span for the default "marked" mock strategy.
|
|
42
45
|
# When true, `client.replay(...)` returns this span's
|
|
43
46
|
# historical output instead of executing the wrapped method.
|
|
@@ -48,7 +51,7 @@ module Bitfab
|
|
|
48
51
|
# preserve the bound client through the fluent wrapper, matching Python's
|
|
49
52
|
# `BitfabFunction.span()` and TypeScript's `BitfabFunction.withSpan()`.
|
|
50
53
|
def self.wrap(klass, method_name, trace_function_key:, name: nil, type: "custom",
|
|
51
|
-
mock_on_replay: false, client: nil)
|
|
54
|
+
capture_when: "always", mock_on_replay: false, client: nil)
|
|
52
55
|
span_name = name || method_name.to_s
|
|
53
56
|
method_name_str = method_name.to_s
|
|
54
57
|
bound_client = client
|
|
@@ -63,6 +66,7 @@ module Bitfab
|
|
|
63
66
|
function_name: method_name_str,
|
|
64
67
|
args:,
|
|
65
68
|
kwargs:,
|
|
69
|
+
capture_when:,
|
|
66
70
|
mock_on_replay:) do
|
|
67
71
|
super(*args, **kwargs, &block)
|
|
68
72
|
end
|
|
@@ -132,10 +136,14 @@ module Bitfab
|
|
|
132
136
|
# @param trace_function_key [String, nil] trace function key (overrides class-level bitfab_function)
|
|
133
137
|
# @param name [String, nil] explicit span name (defaults to method name)
|
|
134
138
|
# @param type [String] span type: llm, agent, function, guardrail, handoff, custom
|
|
139
|
+
# @param capture_when [String, Symbol] "always" to allow a root trace, or
|
|
140
|
+
# "nested" to capture only when another Bitfab span is active. Unknown
|
|
141
|
+
# values warn once and default to "always"
|
|
135
142
|
# @param mock_on_replay [Boolean] mark this span for the default "marked" mock strategy.
|
|
136
143
|
# When true, `client.replay(...)` returns this span's
|
|
137
144
|
# historical output instead of executing the wrapped method.
|
|
138
|
-
def bitfab_span(method_name, trace_function_key: nil, name: nil, type: "custom",
|
|
145
|
+
def bitfab_span(method_name, trace_function_key: nil, name: nil, type: "custom",
|
|
146
|
+
capture_when: "always", mock_on_replay: false)
|
|
139
147
|
trace_function_key ||= @bitfab_function_key
|
|
140
148
|
unless trace_function_key
|
|
141
149
|
raise "No trace function key provided. Pass `trace_function_key:` to `bitfab_span` " \
|
|
@@ -144,7 +152,9 @@ module Bitfab
|
|
|
144
152
|
|
|
145
153
|
# If the method already exists (inline or after-method style), wrap it immediately
|
|
146
154
|
if method_defined?(method_name) || private_method_defined?(method_name)
|
|
147
|
-
_bitfab_wrap_method(
|
|
155
|
+
_bitfab_wrap_method(
|
|
156
|
+
method_name, trace_function_key:, name:, type:, capture_when:, mock_on_replay:
|
|
157
|
+
)
|
|
148
158
|
else
|
|
149
159
|
# Method doesn't exist yet (before-method style) - register for method_added hook
|
|
150
160
|
@_bitfab_pending_spans ||= {}
|
|
@@ -152,6 +162,7 @@ module Bitfab
|
|
|
152
162
|
trace_function_key:,
|
|
153
163
|
name:,
|
|
154
164
|
type:,
|
|
165
|
+
capture_when:,
|
|
155
166
|
mock_on_replay:
|
|
156
167
|
}
|
|
157
168
|
end
|
|
@@ -167,7 +178,8 @@ module Bitfab
|
|
|
167
178
|
_bitfab_wrap_method(method_name, **config)
|
|
168
179
|
end
|
|
169
180
|
|
|
170
|
-
def _bitfab_wrap_method(method_name, trace_function_key:, name: nil, type: "custom",
|
|
181
|
+
def _bitfab_wrap_method(method_name, trace_function_key:, name: nil, type: "custom",
|
|
182
|
+
capture_when: "always", mock_on_replay: false)
|
|
171
183
|
span_name = name || method_name.to_s
|
|
172
184
|
method_name_str = method_name.to_s
|
|
173
185
|
|
|
@@ -185,6 +197,7 @@ module Bitfab
|
|
|
185
197
|
function_name: method_name_str,
|
|
186
198
|
args:,
|
|
187
199
|
kwargs:,
|
|
200
|
+
capture_when:,
|
|
188
201
|
mock_on_replay:) do
|
|
189
202
|
super(*args, **kwargs, &block)
|
|
190
203
|
end
|
data/lib/bitfab/version.rb
CHANGED