Class: CDC::Core::Observer

Inherits:
Object
  • Object
show all
Defined in:
lib/cdc/core/observer.rb

Overview

Observer interface for CDC runtime instrumentation.

Observers receive lifecycle and result notifications from core runtime objects. The default implementation is a no-op so callers can opt in without taking a dependency on a metrics backend.

Direct Known Subclasses

NullObserver

Constant Summary collapse

METRIC_NAMES =

Canonical metric names emitted by core runtime hooks.

Ractor.make_shareable({
  dispatch_started: 'cdc_core.dispatch.started',
  dispatch_succeeded: 'cdc_core.dispatch.succeeded',
  dispatch_failed: 'cdc_core.dispatch.failed',
  dispatch_skipped: 'cdc_core.dispatch.skipped'
}.freeze)

Class Method Summary collapse

Instance Method Summary collapse

Class Method Details

.failed_metric_nameString

Canonical metric name for the failure hook.

Returns:

  • (String)


54
# File 'lib/cdc/core/observer.rb', line 54

def self.failed_metric_name = METRIC_NAMES.fetch(:dispatch_failed)

.metric_tags(payload) ⇒ Hash{String=>Object}

Build a canonical metric tag set for a CDC work item or result.

Parameters:

Returns:

  • (Hash{String=>Object})


23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
# File 'lib/cdc/core/observer.rb', line 23

def self.metric_tags(payload)
  tags = {} # : Hash[String, untyped]
  case payload
  when ChangeEvent
    tags.merge!(change_event_metric_tags(payload))
  when TransactionEnvelope
    tags.merge!(transaction_envelope_metric_tags(payload))
  when ProcessorResult
    tags.merge!(processor_result_metric_tags(payload))
  when Array
    tags.merge!(batch_metric_tags(payload))
  else
    tags['kind'] = payload.class.name
  end

  Ractor.make_shareable(tags.freeze)
end

.skipped_metric_nameString

Canonical metric name for the skip hook.

Returns:

  • (String)


59
# File 'lib/cdc/core/observer.rb', line 59

def self.skipped_metric_name = METRIC_NAMES.fetch(:dispatch_skipped)

.started_metric_nameString

Canonical metric name for the start hook.

Returns:

  • (String)


44
# File 'lib/cdc/core/observer.rb', line 44

def self.started_metric_name = METRIC_NAMES.fetch(:dispatch_started)

.succeeded_metric_nameString

Canonical metric name for the success hook.

Returns:

  • (String)


49
# File 'lib/cdc/core/observer.rb', line 49

def self.succeeded_metric_name = METRIC_NAMES.fetch(:dispatch_succeeded)

Instance Method Details

#dispatch_failed(_result) ⇒ void

This method returns an undefined value.

Called after a work item fails.

Parameters:



77
# File 'lib/cdc/core/observer.rb', line 77

def dispatch_failed(_result); end

#dispatch_skipped(_result) ⇒ void

This method returns an undefined value.

Called when a work item is filtered or skipped.

Parameters:



83
# File 'lib/cdc/core/observer.rb', line 83

def dispatch_skipped(_result); end

#dispatch_started(_event) ⇒ void

This method returns an undefined value.

Called before a work item is dispatched.

Parameters:



65
# File 'lib/cdc/core/observer.rb', line 65

def dispatch_started(_event); end

#dispatch_succeeded(_result) ⇒ void

This method returns an undefined value.

Called after a work item is processed successfully.

Parameters:



71
# File 'lib/cdc/core/observer.rb', line 71

def dispatch_succeeded(_result); end