Class: WideEvent::Configuration

Inherits:
Object
  • Object
show all
Defined in:
lib/wide_event/configuration.rb

Constant Summary collapse

DEFAULT_ERROR_HANDLER =

Reports through OTel's error handler when it's loaded; silent otherwise.

lambda do |exception, message|
  if defined?(OpenTelemetry) && OpenTelemetry.respond_to?(:handle_error)
    OpenTelemetry.handle_error(exception: exception, message: "wide_event #{message}")
  end
end
SOLID_QUEUE_DETECTOR =

Recurring (scheduled) Solid Queue executions have a RecurringExecution row pointing at the underlying job. One indexed query per execution.

lambda do |job|
  return false unless defined?(SolidQueue::RecurringExecution)
  job.provider_job_id.present? && SolidQueue::RecurringExecution.exists?(job_id: job.provider_job_id)
rescue StandardError
  false
end
NOOP_STORE_SINK =

A resolved store sink is unusable until its configuration (url/service/environment/ingest token) is valid; falls back to this silent no-op so a misconfigured store never raises into a flush.

Object.new.tap { |sink| sink.define_singleton_method(:flush) { |_attrs| nil } }.freeze

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initializeConfiguration

Returns a new instance of Configuration.



30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
# File 'lib/wide_event/configuration.rb', line 30

def initialize
  @store_url = ENV["WIDE_EVENTS_URL"]
  @enabled = @store_url.present? || ENV["OTEL_EXPORTER_OTLP_ENDPOINT"].present?
  @sink = @store_url.present? ? :store : :otel
  @resolved_sink = nil
  @store_service = ENV["WIDE_EVENTS_SERVICE"]
  @store_environment = ENV["WIDE_EVENTS_ENVIRONMENT"]
  @store_ingest_token = ENV["WIDE_EVENTS_INGEST_TOKEN"]
  @store_query_token = ENV["WIDE_EVENTS_QUERY_TOKEN"]
  @store_sender = nil
  @max_cache_attrs = 10
  @span_scopes = {
    "OpenTelemetry::Instrumentation::PG" => "postgres_query",
    "OpenTelemetry::Instrumentation::Net::HTTP" => "http_call"
  }
  @strict = false
  @registry_path = nil
  @registry = nil
  @logger = nil
  @error_handler = DEFAULT_ERROR_HANDLER
  @scheduled_job_detector = SOLID_QUEUE_DETECTOR
end

Instance Attribute Details

#enabledObject

Returns the value of attribute enabled.



19
20
21
# File 'lib/wide_event/configuration.rb', line 19

def enabled
  @enabled
end

#error_handlerObject

Returns the value of attribute error_handler.



19
20
21
# File 'lib/wide_event/configuration.rb', line 19

def error_handler
  @error_handler
end

#loggerObject

Returns the value of attribute logger.



19
20
21
# File 'lib/wide_event/configuration.rb', line 19

def logger
  @logger
end

#max_cache_attrsObject

Returns the value of attribute max_cache_attrs.



19
20
21
# File 'lib/wide_event/configuration.rb', line 19

def max_cache_attrs
  @max_cache_attrs
end

#registry_pathObject

Returns the value of attribute registry_path.



23
24
25
# File 'lib/wide_event/configuration.rb', line 23

def registry_path
  @registry_path
end

#scheduled_job_detectorObject

Returns the value of attribute scheduled_job_detector.



19
20
21
# File 'lib/wide_event/configuration.rb', line 19

def scheduled_job_detector
  @scheduled_job_detector
end

#sinkObject

Returns the value of attribute sink.



23
24
25
# File 'lib/wide_event/configuration.rb', line 23

def sink
  @sink
end

#span_scopesObject

Returns the value of attribute span_scopes.



19
20
21
# File 'lib/wide_event/configuration.rb', line 19

def span_scopes
  @span_scopes
end

#store_environmentObject

Returns the value of attribute store_environment.



19
20
21
# File 'lib/wide_event/configuration.rb', line 19

def store_environment
  @store_environment
end

#store_ingest_tokenObject

Returns the value of attribute store_ingest_token.



19
20
21
# File 'lib/wide_event/configuration.rb', line 19

def store_ingest_token
  @store_ingest_token
end

#store_query_tokenObject

Returns the value of attribute store_query_token.



19
20
21
# File 'lib/wide_event/configuration.rb', line 19

def store_query_token
  @store_query_token
end

#store_serviceObject

Returns the value of attribute store_service.



19
20
21
# File 'lib/wide_event/configuration.rb', line 19

def store_service
  @store_service
end

#store_urlObject

Returns the value of attribute store_url.



19
20
21
# File 'lib/wide_event/configuration.rb', line 19

def store_url
  @store_url
end

#strictObject

Returns the value of attribute strict.



19
20
21
# File 'lib/wide_event/configuration.rb', line 19

def strict
  @strict
end

Instance Method Details

#registryObject



79
80
81
82
# File 'lib/wide_event/configuration.rb', line 79

def registry
  return nil if @registry_path.nil?
  @registry ||= Registry.load(resolved_registry_path)
end

#resolved?Boolean

True once #resolved_sink has actually built (or attempted to build) a sink; lets WideEvent.shutdown! avoid constructing one from scratch just to shut it down.

Returns:

  • (Boolean)


70
71
72
# File 'lib/wide_event/configuration.rb', line 70

def resolved?
  !@resolved_sink.nil?
end

#resolved_sinkObject



58
59
60
61
62
63
64
65
# File 'lib/wide_event/configuration.rb', line 58

def resolved_sink
  @resolved_sink ||= case @sink
  when :otel then Sinks::OtelSpan.new
  when :log then Sinks::LogLine.new(logger)
  when :store then build_store_sink
  else @sink
  end
end

#shutdown_store_sender!(timeout: WideEvent::Store::Sender::SHUTDOWN_TIMEOUT) ⇒ Object

Stops the store sender's worker thread (if one was ever built) so tests and process shutdown never leak the background thread.



86
87
88
89
# File 'lib/wide_event/configuration.rb', line 86

def shutdown_store_sender!(timeout: WideEvent::Store::Sender::SHUTDOWN_TIMEOUT)
  @store_sender&.shutdown(timeout: timeout)
  @store_sender = nil
end