Skip to content

Instrumentation ​

Servus sends an ActiveSupport notification around every service call, every call_async and every event emit. Subscribe to them to trace, log or measure services.

call.servus and enqueue.servus do no work until something subscribes to them, so they cost nothing when unused.

Notifications ​

NameSent around
call.servusService.call, including rescue_from handling
enqueue.servusService.call_async
emit.servusServus::Events::Bus.emit, so every event emit

call.servus ​

KeyValue
serviceThe service class
argsThe arguments, filtered with log_filter_parameters when it is set
responseThe Servus::Support::Response, when the call returns one
outcomeOne symbol for how the call ended (see below)
exception, exception_objectSet by ActiveSupport when the call raises

Outcomes ​

OutcomeWhen
:successThe response is a success
:failureA failure response that is not a guard: failure, failure!, or an exception that rescue_from handles
:guardA guard failed
:exceptionAn exception raised out of the call, or a throw through it

When a schema check fails, the outcome is :exception and exception_object tells you which check failed:

ErrorWhen
Servus::Support::Errors::InvalidArgumentsErrorThe arguments failed their schema
Servus::Support::Errors::InvalidResultErrorThe result (or failure data) failed its schema
Servus::Support::Errors::InvalidEventErrorAn emitted event's payload failed its schema

All three are subclasses of ValidationError, so rescue ValidationError and rescue_from ValidationError still catch them.

enqueue.servus ​

KeyValue
serviceThe service class
argsThe service arguments
jobWhat perform_later returned

emit.servus ​

KeyValue
eventThe event name, a symbol
payloadThe event payload

An event a service emits is sent inside that service's call.servus, so a tracer nests the emit span under the call span.

Subscribing ​

ruby
ActiveSupport::Notifications.subscribe('call.servus') do |event|
  Rails.logger.info(
    "#{event.payload[:service].name} #{event.payload[:outcome]} in #{event.duration.round(1)}ms"
  )
end

Developed at and used extensively by ZAR