Service-level interceptors for business logic operations.
This namespace provides interceptor pipelines specifically designed for service layer operations, eliminating manual observability calls and providing consistent error handling, logging, metrics, and error reporting across all service methods.
Key Benefits:
Usage: (execute-service-operation :register-user {:user-data user-data :tenant-id tenant-id} service-impl-fn {:system system})
Architecture:
Service-level interceptors for business logic operations.
This namespace provides interceptor pipelines specifically designed for service layer operations,
eliminating manual observability calls and providing consistent error handling, logging, metrics,
and error reporting across all service methods.
Key Benefits:
- Eliminates 50+ manual observability calls from service methods
- Provides consistent error handling and reporting patterns
- Automatic timing, logging, and metrics collection
- Single point of control for service-level cross-cutting concerns
Usage:
(execute-service-operation
:register-user
{:user-data user-data :tenant-id tenant-id}
service-impl-fn
{:system system})
Architecture:
- Service interceptors wrap pure business logic functions
- Context carries operation metadata and observability services
- Interceptors handle all cross-cutting concerns automaticallyBase interceptor pipeline for all service operations.
Base interceptor pipeline for all service operations.
(create-service-context operation params system & [metadata])Creates a service interceptor context for business logic operations.
Args: operation: Keyword identifying the service operation (e.g., :register-user) params: Map of operation parameters system: Map containing observability services {:logger :metrics-emitter :error-reporter} metadata: Optional additional metadata
Returns: Service context map with operation details and observability services
Creates a service interceptor context for business logic operations.
Args:
operation: Keyword identifying the service operation (e.g., :register-user)
params: Map of operation parameters
system: Map containing observability services {:logger :metrics-emitter :error-reporter}
metadata: Optional additional metadata
Returns:
Service context map with operation details and observability services(create-service-pipeline business-logic-fn & custom-interceptors)Creates a service interceptor pipeline with business logic.
Args: business-logic-fn: Function that implements the actual business logic custom-interceptors: Optional additional interceptors to include
Returns: Complete interceptor pipeline for service operation
Creates a service interceptor pipeline with business logic. Args: business-logic-fn: Function that implements the actual business logic custom-interceptors: Optional additional interceptors to include Returns: Complete interceptor pipeline for service operation
(defservice name args context-map & body)Defines a service method with automatic interceptor pipeline.
Example: (defservice register-user [this user-data] {:operation :register-user :params {:user-data user-data :tenant-id (:tenant-id user-data)} :system (extract-system this)} ;; Business logic here (let [prepared-user (user-core/prepare-user-for-creation user-data)] (.create-user (:user-repository this) prepared-user)))
Defines a service method with automatic interceptor pipeline.
Example:
(defservice register-user [this user-data]
{:operation :register-user
:params {:user-data user-data :tenant-id (:tenant-id user-data)}
:system (extract-system this)}
;; Business logic here
(let [prepared-user (user-core/prepare-user-for-creation user-data)]
(.create-user (:user-repository this) prepared-user)))(execute-service-operation operation
params
business-logic-fn
system
&
[options])Executes a service operation using interceptor pipeline with automatic observability.
This is the single method to use for all service operations. It automatically handles:
Args: operation: Keyword identifying the operation (e.g., :register-user) params: Map of operation parameters business-logic-fn: Function implementing the pure business logic system: Map with observability services {:logger :metrics-emitter :error-reporter} options: Optional map with {:custom-interceptors [...] :metadata {...}}
Returns: Result of the business logic function
Example: (execute-service-operation :register-user {:user-data user-data :tenant-id tenant-id} (fn [{:keys [params]}] ;; Pure business logic here (let [user-data (:user-data params)] ;; ... implement registration logic created-user)) {:logger logger :metrics-emitter metrics :error-reporter error-reporter})
Executes a service operation using interceptor pipeline with automatic observability.
This is the single method to use for all service operations. It automatically handles:
- Error reporting and breadcrumbs
- Logging (info, error, audit, business events)
- Metrics (timing, counters, success/failure tracking)
- Exception handling and re-throwing
Args:
operation: Keyword identifying the operation (e.g., :register-user)
params: Map of operation parameters
business-logic-fn: Function implementing the pure business logic
system: Map with observability services {:logger :metrics-emitter :error-reporter}
options: Optional map with {:custom-interceptors [...] :metadata {...}}
Returns:
Result of the business logic function
Example:
(execute-service-operation
:register-user
{:user-data user-data :tenant-id tenant-id}
(fn [{:keys [params]}]
;; Pure business logic here
(let [user-data (:user-data params)]
;; ... implement registration logic
created-user))
{:logger logger :metrics-emitter metrics :error-reporter error-reporter})Handles service operation audit logging for compliance.
Handles service operation audit logging for compliance.
Handles service operation error reporting and recovery.
Handles service operation error reporting and recovery.
Handles service operation logging throughout the lifecycle.
Handles service operation logging throughout the lifecycle.
Handles service operation metrics collection.
Handles service operation metrics collection.
Initializes service operation with observability setup.
Initializes service operation with observability setup.
Adds success breadcrumb for successful operations.
Adds success breadcrumb for successful operations.
cljdoc builds & hosts documentation for Clojure/Script libraries
| Ctrl+k | Jump to recent docs |
| ← | Move to previous article |
| → | Move to next article |
| Ctrl+/ | Jump to the search field |