ask-instrumentation 0.1.0 → 0.2.0
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/CHANGELOG.md +7 -2
- data/lib/ask/instrumentation/tool.rb +69 -4
- data/lib/ask/instrumentation/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: 6e9b0882ee2f248d7e5deb2822691d23ffddbaedfae0550754cff592871af03e
|
|
4
|
+
data.tar.gz: afc34f57d8046c40b8e410378e5af14e29faca6f3beea80e67dd162d04633075
|
|
5
5
|
SHA512:
|
|
6
|
-
metadata.gz:
|
|
7
|
-
data.tar.gz:
|
|
6
|
+
metadata.gz: 90c1ac1b5fd3771322283d15226d4c9874c6520a3ba5acec454c5305fb86ce8b74b2c8d43c565333182c2ff8e95588530649281a255702dfe1ab5e266f655a2a
|
|
7
|
+
data.tar.gz: aacb928965b780aaabec0ad37dbde4e3d5a8b93d7bbe1079a96f3c56c914ea6afe8d47cc40bcb3b507d46ae64befdf022b3aefdd6562f7b79cbd31bf95260ec6
|
data/CHANGELOG.md
CHANGED
|
@@ -1,6 +1,11 @@
|
|
|
1
1
|
# Changelog
|
|
2
2
|
|
|
3
|
-
##
|
|
3
|
+
## 0.2.0 (2026-06-21)
|
|
4
|
+
|
|
5
|
+
- Fleshed out `Ask::Instrumentation::Tool` module with `instrument` helper
|
|
6
|
+
- Emits `tool_call.ask` and `tool_result.ask` events via ActiveSupport::Notifications
|
|
7
|
+
- Added structured trace logging to `log/tools/trace.jsonl`
|
|
8
|
+
|
|
9
|
+
## 0.1.0
|
|
4
10
|
|
|
5
|
-
### Added
|
|
6
11
|
- Initial release
|
|
@@ -1,10 +1,75 @@
|
|
|
1
|
+
# frozen_string_literal: true
|
|
2
|
+
|
|
3
|
+
require "json"
|
|
4
|
+
require "fileutils"
|
|
5
|
+
|
|
1
6
|
module Ask
|
|
2
7
|
module Instrumentation
|
|
3
|
-
# Placeholder for Tool-specific instrumentation helpers.
|
|
4
|
-
#
|
|
5
|
-
# This module will be loaded automatically when
|
|
6
|
-
# +Ask::Instrumentation::Tool+ is referenced (via +autoload+).
|
|
7
8
|
module Tool
|
|
9
|
+
TRACE_LOG_DIR = File.expand_path("log/tools", Dir.pwd)
|
|
10
|
+
|
|
11
|
+
class << self
|
|
12
|
+
def instrument(name:, arguments:, tool_call_id:, metadata: {}, &block)
|
|
13
|
+
arg_size = arguments.to_s.length
|
|
14
|
+
payload = {
|
|
15
|
+
name: name,
|
|
16
|
+
arguments: arguments,
|
|
17
|
+
argument_size: arg_size,
|
|
18
|
+
tool_call_id: tool_call_id
|
|
19
|
+
}.merge(metadata)
|
|
20
|
+
|
|
21
|
+
Ask::Instrumentation.instrument("tool_call.ask", payload)
|
|
22
|
+
|
|
23
|
+
start_time = Process.clock_gettime(Process::CLOCK_MONOTONIC)
|
|
24
|
+
begin
|
|
25
|
+
result = block.call
|
|
26
|
+
duration_ms = ((Process.clock_gettime(Process::CLOCK_MONOTONIC) - start_time) * 1000).round(1)
|
|
27
|
+
result_size = result.to_s.length
|
|
28
|
+
|
|
29
|
+
result_payload = {
|
|
30
|
+
name: name,
|
|
31
|
+
duration_ms: duration_ms,
|
|
32
|
+
result_size: result_size,
|
|
33
|
+
success: true,
|
|
34
|
+
tool_call_id: tool_call_id
|
|
35
|
+
}.merge(metadata)
|
|
36
|
+
|
|
37
|
+
Ask::Instrumentation.instrument("tool_result.ask", result_payload)
|
|
38
|
+
write_trace_log(name: name, duration_ms: duration_ms, success: true,
|
|
39
|
+
argument_size: arg_size, result_size: result_size,
|
|
40
|
+
tool_call_id: tool_call_id)
|
|
41
|
+
result
|
|
42
|
+
rescue => e
|
|
43
|
+
duration_ms = ((Process.clock_gettime(Process::CLOCK_MONOTONIC) - start_time) * 1000).round(1)
|
|
44
|
+
|
|
45
|
+
error_payload = {
|
|
46
|
+
name: name,
|
|
47
|
+
duration_ms: duration_ms,
|
|
48
|
+
error: e.class.name,
|
|
49
|
+
error_message: e.message,
|
|
50
|
+
success: false,
|
|
51
|
+
tool_call_id: tool_call_id
|
|
52
|
+
}.merge(metadata)
|
|
53
|
+
|
|
54
|
+
Ask::Instrumentation.instrument("tool_result.ask", error_payload)
|
|
55
|
+
write_trace_log(name: name, duration_ms: duration_ms, success: false,
|
|
56
|
+
error: "#{e.class.name}: #{e.message}",
|
|
57
|
+
tool_call_id: tool_call_id)
|
|
58
|
+
raise
|
|
59
|
+
end
|
|
60
|
+
end
|
|
61
|
+
|
|
62
|
+
def write_trace_log(**payload)
|
|
63
|
+
entry = payload.merge(timestamp: Time.now.utc.iso8601(3))
|
|
64
|
+
dir = TRACE_LOG_DIR
|
|
65
|
+
FileUtils.mkdir_p(dir)
|
|
66
|
+
File.open(File.join(dir, "trace.jsonl"), "a") do |f|
|
|
67
|
+
f.puts(JSON.generate(entry))
|
|
68
|
+
end
|
|
69
|
+
rescue => e
|
|
70
|
+
$stderr.puts "[ask-instrumentation] Failed to write trace log: #{e.message}"
|
|
71
|
+
end
|
|
72
|
+
end
|
|
8
73
|
end
|
|
9
74
|
end
|
|
10
75
|
end
|