simforge 0.5.0 → 0.5.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/simforge/traceable.rb +33 -0
- data/lib/simforge/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: 712b471d28942f55c0ac0a78d05507f1060396de60c584173d3824f1e8c6d9b7
|
|
4
|
+
data.tar.gz: efa9dfc4e4173382d853327ee4edeafa54114482e04d97c86a3933465ee24285
|
|
5
5
|
SHA512:
|
|
6
|
-
metadata.gz:
|
|
7
|
-
data.tar.gz:
|
|
6
|
+
metadata.gz: 1ca7cb706679154120fc89cac714b7d2eaa45017389f33f726afee7a77a0a0d1203dd7e14da32c8aa042d828381654bb87fe42fcb75c276edf61c52a27ba83e8
|
|
7
|
+
data.tar.gz: b9d9f5e70bf640447f046f9e272054c5f27f2aba849f42df20c6424c7a11c923c3403f89b23d0eb6b9eb50d53c39d0292b99213a5c4e2b745c7580948613a7d9
|
data/lib/simforge/traceable.rb
CHANGED
|
@@ -26,6 +26,39 @@ module Simforge
|
|
|
26
26
|
base.extend(ClassMethods)
|
|
27
27
|
end
|
|
28
28
|
|
|
29
|
+
# Wrap an existing method on an external class with span tracing.
|
|
30
|
+
# Use this to trace third-party library calls without modifying their source.
|
|
31
|
+
#
|
|
32
|
+
# @example
|
|
33
|
+
# Simforge::Traceable.wrap(OpenAI::Client, :chat,
|
|
34
|
+
# trace_function_key: "openai", name: "Chat", type: "llm")
|
|
35
|
+
#
|
|
36
|
+
# @param klass [Class, Module] the class to wrap
|
|
37
|
+
# @param method_name [Symbol] the method to wrap
|
|
38
|
+
# @param trace_function_key [String] the trace function key
|
|
39
|
+
# @param name [String, nil] explicit span name (defaults to method name)
|
|
40
|
+
# @param type [String] span type: llm, agent, function, guardrail, handoff, custom
|
|
41
|
+
def self.wrap(klass, method_name, trace_function_key:, name: nil, type: "custom")
|
|
42
|
+
span_name = name || method_name.to_s
|
|
43
|
+
method_name_str = method_name.to_s
|
|
44
|
+
|
|
45
|
+
wrapper = Module.new do
|
|
46
|
+
define_method(method_name) do |*args, **kwargs, &block|
|
|
47
|
+
Simforge.client.send(:execute_span,
|
|
48
|
+
trace_function_key:,
|
|
49
|
+
span_name:,
|
|
50
|
+
span_type: type,
|
|
51
|
+
function_name: method_name_str,
|
|
52
|
+
args:,
|
|
53
|
+
kwargs:) do
|
|
54
|
+
super(*args, **kwargs, &block)
|
|
55
|
+
end
|
|
56
|
+
end
|
|
57
|
+
end
|
|
58
|
+
|
|
59
|
+
klass.prepend(wrapper)
|
|
60
|
+
end
|
|
61
|
+
|
|
29
62
|
module ClassMethods
|
|
30
63
|
# Set the trace function key for this class.
|
|
31
64
|
# All spans declared in this class will be grouped under this key.
|
data/lib/simforge/version.rb
CHANGED