posthog-ruby 3.31.0 → 3.32.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/posthog/exception_capture.rb +20 -1
- data/lib/posthog/mcp/constants.rb +3 -1
- data/lib/posthog/mcp/event_builder.rb +5 -1
- data/lib/posthog/mcp/instrumentation.rb +27 -0
- data/lib/posthog/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: 6f3617315bd23ae3b6cbce6213b21cbc10cb83db1dfc6a0c111d5f94404088cc
|
|
4
|
+
data.tar.gz: 47b81c9ce5aef958562908d9687d7ef95d89ae675692f3e8f3f1583857298959
|
|
5
5
|
SHA512:
|
|
6
|
-
metadata.gz:
|
|
7
|
-
data.tar.gz:
|
|
6
|
+
metadata.gz: 493420b17402e4d2bbdd0cbc9dea605cd23921f07b89e15e5c048c724a184b86f3c1b43c6989b60e9875801fd598c264523ed46d8a5a1710af53dacbef5c52e2
|
|
7
|
+
data.tar.gz: 6a9efff5883c666fcb1df41163eee04af68f1b5c69e03c551b262d0fec0fbede69fdc3f5f0af703f72043b5e259c214535b72d1ebaefaeb015f1202aeb29c7cf
|
|
@@ -119,7 +119,7 @@ module PostHog
|
|
|
119
119
|
|
|
120
120
|
file = match[1]
|
|
121
121
|
lineno = match[2].to_i
|
|
122
|
-
method_name = match[5]
|
|
122
|
+
method_name = normalize_rails_template_method(match[5], file)
|
|
123
123
|
|
|
124
124
|
frame = {
|
|
125
125
|
'filename' => frame_filename(file, project_root),
|
|
@@ -135,6 +135,25 @@ module PostHog
|
|
|
135
135
|
frame
|
|
136
136
|
end
|
|
137
137
|
|
|
138
|
+
def self.normalize_rails_template_method(method_name, file)
|
|
139
|
+
return method_name unless defined?(::Rails) && method_name
|
|
140
|
+
|
|
141
|
+
return method_name unless method_name.match?(/___?\d+__?\d+\z/)
|
|
142
|
+
|
|
143
|
+
# Action View encodes the template identifier, then appends its hash and
|
|
144
|
+
# object ID, replacing minus signs with underscores. Its short identifier
|
|
145
|
+
# strips "/" when Rails.root is nil, unlike the project_root fallback.
|
|
146
|
+
relative_path = defined?(::Rails.root) ? file.delete_prefix("#{::Rails.root}/") : file
|
|
147
|
+
[file, relative_path].uniq.each do |path|
|
|
148
|
+
identifier = Regexp.escape("_#{path.tr('^a-z_', '_')}")
|
|
149
|
+
normalized = method_name.sub(/(\A(?:block(?: \(\d+ levels\))? in )?#{identifier})___?\d+__?\d+\z/, '\1')
|
|
150
|
+
return normalized unless normalized == method_name
|
|
151
|
+
end
|
|
152
|
+
|
|
153
|
+
method_name
|
|
154
|
+
end
|
|
155
|
+
private_class_method :normalize_rails_template_method
|
|
156
|
+
|
|
138
157
|
# Root directory the application runs from, used to derive stable
|
|
139
158
|
# project-relative filenames from per-host deploy paths
|
|
140
159
|
# (e.g. `/app/releases/20240101/...`).
|
|
@@ -89,6 +89,7 @@ module PostHog
|
|
|
89
89
|
MCP_RESOURCES_READ = 'mcp:resources/read'
|
|
90
90
|
MCP_TOOLS_CALL = 'mcp:tools/call'
|
|
91
91
|
MCP_TOOLS_LIST = 'mcp:tools/list'
|
|
92
|
+
MCP_UNKNOWN_TOOL = 'mcp:unknown_tool'
|
|
92
93
|
|
|
93
94
|
EVENT_NAME_BY_TYPE = {
|
|
94
95
|
CUSTOM => Event::CUSTOM,
|
|
@@ -100,7 +101,8 @@ module PostHog
|
|
|
100
101
|
MCP_RESOURCES_LIST => Event::RESOURCES_LIST,
|
|
101
102
|
MCP_RESOURCES_READ => Event::RESOURCE_READ,
|
|
102
103
|
MCP_TOOLS_CALL => Event::TOOL_CALL,
|
|
103
|
-
MCP_TOOLS_LIST => Event::TOOLS_LIST
|
|
104
|
+
MCP_TOOLS_LIST => Event::TOOLS_LIST,
|
|
105
|
+
MCP_UNKNOWN_TOOL => '$mcp_unknown_tool'
|
|
104
106
|
}.freeze
|
|
105
107
|
end
|
|
106
108
|
end
|
|
@@ -66,10 +66,14 @@ module PostHog
|
|
|
66
66
|
event['event_type'] == EventType::MCP_TOOLS_CALL
|
|
67
67
|
end
|
|
68
68
|
|
|
69
|
+
def unknown_tool?(event)
|
|
70
|
+
event['event_type'] == EventType::MCP_UNKNOWN_TOOL
|
|
71
|
+
end
|
|
72
|
+
|
|
69
73
|
def add_common_properties(event, properties)
|
|
70
74
|
if present(event['resource_name'])
|
|
71
75
|
properties[Property::RESOURCE_NAME] = event['resource_name']
|
|
72
|
-
properties[Property::TOOL_NAME] = event['resource_name'] if tool_call?(event)
|
|
76
|
+
properties[Property::TOOL_NAME] = event['resource_name'] if tool_call?(event) || unknown_tool?(event)
|
|
73
77
|
end
|
|
74
78
|
if present(event['tool_description']) && tool_call?(event)
|
|
75
79
|
properties[Property::TOOL_DESCRIPTION] =
|
|
@@ -163,6 +163,15 @@ module PostHog
|
|
|
163
163
|
return result
|
|
164
164
|
end
|
|
165
165
|
|
|
166
|
+
if unregistered_tool?(name)
|
|
167
|
+
begin
|
|
168
|
+
result = yield
|
|
169
|
+
ensure
|
|
170
|
+
safely { record_unknown_tool(name, request, minted ? nil : conversation_id) }
|
|
171
|
+
end
|
|
172
|
+
return result
|
|
173
|
+
end
|
|
174
|
+
|
|
166
175
|
safely { prime_session(request, minted ? nil : conversation_id) }
|
|
167
176
|
begin
|
|
168
177
|
result = yield
|
|
@@ -336,6 +345,15 @@ module PostHog
|
|
|
336
345
|
finish_event(event, request)
|
|
337
346
|
end
|
|
338
347
|
|
|
348
|
+
def record_unknown_tool(name, request, conversation_id)
|
|
349
|
+
session_id = prepare_request(request, conversation_id: conversation_id)
|
|
350
|
+
event = base_event(EventType::MCP_UNKNOWN_TOOL, session_id, request)
|
|
351
|
+
event['conversation_id'] = conversation_id
|
|
352
|
+
event.delete('duration')
|
|
353
|
+
event['resource_name'] = Sanitization.redact_pii(Sanitization.sanitize_captured_value(name))
|
|
354
|
+
finish_event(event, request)
|
|
355
|
+
end
|
|
356
|
+
|
|
339
357
|
# The virtual tool declares `llm_model` itself, so the argument is never
|
|
340
358
|
# stripped and is read straight off the call.
|
|
341
359
|
def self_reported_model(arguments)
|
|
@@ -605,6 +623,15 @@ module PostHog
|
|
|
605
623
|
tools.is_a?(Hash) && tools[name].equal?(@data.virtual_tool)
|
|
606
624
|
end
|
|
607
625
|
|
|
626
|
+
# True when the server's registry is readable and has no tool by this name.
|
|
627
|
+
# A server whose registry cannot be read stays a failed call.
|
|
628
|
+
def unregistered_tool?(name)
|
|
629
|
+
return false unless name.is_a?(String) && !name.empty?
|
|
630
|
+
|
|
631
|
+
tools = @server.respond_to?(:tools) ? @server.tools : nil
|
|
632
|
+
tools.is_a?(Hash) && !tools.key?(name)
|
|
633
|
+
end
|
|
634
|
+
|
|
608
635
|
# Injected argument names the analytics layer owns for this tool: the ones
|
|
609
636
|
# it injected at tools/list, or (never listed) the ones the tool's own
|
|
610
637
|
# schema does not declare. A composed or referenced schema is never
|
data/lib/posthog/version.rb
CHANGED