Module: BetterService::Concerns

Defined in:
lib/better_service/concerns/instrumentation.rb,
lib/better_service/concerns/serviceable.rb,
lib/better_service/concerns/workflowable.rb,
lib/better_service/concerns/serviceable/cacheable.rb,
lib/better_service/concerns/workflowable/callbacks.rb,
lib/better_service/concerns/serviceable/messageable.rb,
lib/better_service/concerns/serviceable/presentable.rb,
lib/better_service/concerns/serviceable/validatable.rb,
lib/better_service/concerns/serviceable/authorizable.rb,
lib/better_service/concerns/serviceable/transactional.rb,
lib/better_service/concerns/serviceable/repository_aware.rb

Overview

Instrumentation - Provides automatic event publishing for service execution

This concern automatically publishes ActiveSupport::Notifications events during the service lifecycle, enabling monitoring, metrics, and observability.

Events published:

  • service.started - When service execution begins

  • service.completed - When service completes successfully

  • service.failed - When service raises an exception

  • cache.hit - When cache lookup returns cached data

  • cache.miss - When cache lookup requires fresh computation

Examples:

Subscribe to all service events

ActiveSupport::Notifications.subscribe("service.completed") do |name, start, finish, id, payload|
  puts "#{payload[:service_name]} took #{payload[:duration]}ms"
end

Subscribe to specific service

ActiveSupport::Notifications.subscribe("service.completed") do |name, start, finish, id, payload|
  if payload[:service_name] == "ProductsIndexService"
    DataDog.histogram("products.index.duration", payload[:duration])
  end
end

Defined Under Namespace

Modules: Instrumentation, Serviceable, Workflowable