Commit c8bfbfaa authored by Matt Todd's avatar Matt Todd

Instrument the pipeline call, too

parent 61101ca7
......@@ -197,9 +197,9 @@ Pipeline.new [ RootRelativeFilter ], { :base_url => 'http://somehost.com' }
## Instrumenting
To instrument each filter, set an [ActiveSupport::Notifications]
(http://api.rubyonrails.org/classes/ActiveSupport/Notifications.html) service
object on a pipeline object. New pipeline objects will default to the
To instrument each filter and a full pipeline call, set an
[ActiveSupport::Notifications](http://api.rubyonrails.org/classes/ActiveSupport/Notifications.html)
service object on a pipeline object. New pipeline objects will default to the
`HTML::Pipeline.default_instrumentation_service` object.
``` ruby
......@@ -225,6 +225,14 @@ service.subscribe "call_filter.html_pipeline" do |event, start, ending, transact
end
```
The full pipeline is also instrumented:
``` ruby
service.subscribe "call_pipeline.html_pipeline" do |event, start, ending, transaction_id, payload|
payload[:filters] #=> ["MarkdownFilter"]
end
```
## Development
To see what has changed in recent versions, see the [CHANGELOG](https://github.com/jch/html-pipeline/blob/master/CHANGELOG.md).
......
......@@ -94,10 +94,12 @@ module HTML
context = @default_context.merge(context)
context = context.freeze
result ||= @result_class.new
result[:output] =
@filters.inject(html) do |doc, filter|
perform_filter(filter, doc, context, result)
end
instrument "call_pipeline.html_pipeline", :filters => @filters.map(&:name) do
result[:output] =
@filters.inject(html) do |doc, filter|
perform_filter(filter, doc, context, result)
end
end
result
end
......
class MockedInstrumentationService
attr_reader :events
def initialize(events = [])
def initialize(event = nil, events = [])
@events = events
subscribe event
end
def instrument(event, payload = nil)
res = yield
events << [event, payload, res]
events << [event, payload, res] if @subscribe == event
res
end
def subscribe(event)
@subscribe = event
end
end
......@@ -17,6 +17,7 @@ class HTML::PipelineTest < Test::Unit::TestCase
def test_filter_instrumentation
service = MockedInstrumentationService.new
service.subscribe "call_filter.html_pipeline"
@pipeline.instrumentation_service = service
filter("hello")
event, payload, res = service.events.pop
......@@ -25,6 +26,17 @@ class HTML::PipelineTest < Test::Unit::TestCase
assert_equal TestFilter.name, payload[:filter]
end
def test_pipeline_instrumentation
service = MockedInstrumentationService.new
service.subscribe "call_pipeline.html_pipeline"
@pipeline.instrumentation_service = service
filter("hello")
event, payload, res = service.events.pop
assert event, "event expected"
assert_equal "call_pipeline.html_pipeline", event
assert_equal @pipeline.filters.map(&:name), payload[:filters]
end
def test_default_instrumentation_service
service = 'default'
Pipeline.default_instrumentation_service = service
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment