Skip to content

Commit 607e059

Browse files
committed
Add filter, pipeline output, results to instrument payload
1 parent 7ba4458 commit 607e059

File tree

2 files changed

+11
-7
lines changed

2 files changed

+11
-7
lines changed

lib/html/pipeline.rb

Lines changed: 9 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -94,11 +94,12 @@ def call(html, context = {}, result = nil)
9494
context = @default_context.merge(context)
9595
context = context.freeze
9696
result ||= @result_class.new
97-
instrument "call_pipeline.html_pipeline", :filters => @filters.map(&:name) do
97+
instrument "call_pipeline.html_pipeline", :filters => @filters.map(&:name) do |payload|
9898
result[:output] =
9999
@filters.inject(html) do |doc, filter|
100100
perform_filter(filter, doc, context, result)
101101
end
102+
payload[:result] = result
102103
end
103104
result
104105
end
@@ -109,8 +110,9 @@ def call(html, context = {}, result = nil)
109110
#
110111
# Returns the result of the filter.
111112
def perform_filter(filter, doc, context, result)
112-
instrument "call_filter.html_pipeline", :filter => filter.name do
113-
filter.call(doc, context, result)
113+
instrument "call_filter.html_pipeline", :filter => filter.name do |payload|
114+
payload[:result] = result
115+
payload[:output] = filter.call(doc, context, result)
114116
end
115117
end
116118

@@ -119,9 +121,10 @@ def perform_filter(filter, doc, context, result)
119121
#
120122
# Returns the result of the provided block.
121123
def instrument(event, payload = nil)
122-
return yield unless instrumentation_service
123-
instrumentation_service.instrument event, payload do
124-
yield
124+
return yield(payload) unless instrumentation_service
125+
payload ||= {}
126+
instrumentation_service.instrument event, payload do |payload|
127+
yield payload
125128
end
126129
end
127130

test/helpers/mocked_instrumentation_service.rb

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,8 @@ def initialize(event = nil, events = [])
55
subscribe event
66
end
77
def instrument(event, payload = nil)
8-
res = yield
8+
payload ||= {}
9+
res = yield payload
910
events << [event, payload, res] if @subscribe == event
1011
res
1112
end

0 commit comments

Comments
 (0)