Class: Ask::Observability::Configuration

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

Overview

Configuration for ask-observability. Set before the railtie runs (config/initializers/ask_observability.rb) so the metrics are created with their final label set — prometheus-client fixes a metric's label keys at creation time.

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initializeConfiguration

Returns a new instance of Configuration.



38
39
40
41
42
43
44
45
# File 'lib/ask/observability/configuration.rb', line 38

def initialize
  @enabled = true
  @service_name = nil
  @otlp_endpoint = ENV.fetch('OTEL_EXPORTER_OTLP_ENDPOINT', 'http://localhost:4318/v1/traces')
  @json_logging = true
  @metrics_path = '/metrics'
  @label_metadata = []
end

Instance Attribute Details

#enabledObject

Master switch: when false, the subscriber, the OpenTelemetry bootstrap, and the /metrics mount all no-op. Set in tests/CI to keep output clean.



13
14
15
# File 'lib/ask/observability/configuration.rb', line 13

def enabled
  @enabled
end

#json_loggingObject

Structured JSON logs on stdout via rails_semantic_logger (applied when that gem is present and the app hasn't configured appenders).



25
26
27
# File 'lib/ask/observability/configuration.rb', line 25

def json_logging
  @json_logging
end

#label_metadataObject

Metadata keys from Ask::Instrumentation.with_metadata to expose as metric labels. WARNING: every distinct value creates a new series — only use low-cardinality keys (workspace_id, org, tenant), never per-request ids.



36
37
38
# File 'lib/ask/observability/configuration.rb', line 36

def 
  @label_metadata
end

#metrics_pathObject

Mount path for the /metrics Rack endpoint; nil disables the mount (a host app that serves its own /metrics can point this elsewhere or nil and serve Ask::Observability.registry itself).



30
31
32
# File 'lib/ask/observability/configuration.rb', line 30

def metrics_path
  @metrics_path
end

#otlp_endpointObject

OTLP/HTTP endpoint spans are exported to. Defaults to the local collector (OpenObserve reference stack).



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

def otlp_endpoint
  @otlp_endpoint
end

#service_nameObject

service.name for OpenTelemetry spans and logs. Defaults to the Rails app name when running under Rails, else "ask-app".



17
18
19
# File 'lib/ask/observability/configuration.rb', line 17

def service_name
  @service_name
end

Instance Method Details

#metadata_label_keysArray<Symbol>

The configured metadata keys, normalized to symbols.

Returns:

  • (Array<Symbol>)


50
51
52
# File 'lib/ask/observability/configuration.rb', line 50

def 
  @label_metadata.map(&:to_sym)
end