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

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initializeConfiguration

Returns a new instance of Configuration.



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

def initialize
  @enabled = !ENV["OTEL_EXPORTER_OTLP_ENDPOINT"].to_s.empty?
  @sink = :otel
  @resolved_sink = 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.



21
22
23
# File 'lib/wide_event/configuration.rb', line 21

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.



21
22
23
# File 'lib/wide_event/configuration.rb', line 21

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

#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



58
59
60
61
# File 'lib/wide_event/configuration.rb', line 58

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

#resolved_sinkObject



45
46
47
48
49
50
51
# File 'lib/wide_event/configuration.rb', line 45

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