Class: Tracebook::Config

Inherits:
Object
  • Object
show all
Defined in:
lib/tracebook/config.rb

Overview

Configuration object for TraceBook.

Contains all configurable options for the TraceBook engine. Configuration is frozen after the configure block executes to prevent runtime modifications.

Examples:

Basic configuration

TraceBook.configure do |config|
  config.project_name = "Support Console"
  config.persist_async = Rails.env.production?
  config.default_currency = "USD"
end

With custom redactors

TraceBook.configure do |config|
  config.custom_redactors += [
    ->(payload) { payload.gsub(/api_key=\w+/, "api_key=[REDACTED]") }
  ]
end

See Also:

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initializeConfig

Creates a new configuration with default values.



84
85
86
87
88
89
90
91
92
93
94
95
# File 'lib/tracebook/config.rb', line 84

def initialize
  @project_name = nil
  @persist_async = true
  @inline_payload_bytes = 64 * 1024
  @default_currency = "USD"
  @export_formats = [ :csv, :ndjson ]
  @redactors = default_redactors
  @custom_redactors = []
  @auto_subscribe_ruby_llm = false
  @auto_subscribe_active_agent = false
  @per_page = 100
end

Instance Attribute Details

#auto_subscribe_active_agentBoolean

Returns Auto-enable ActiveAgent adapter on boot (default: false).

Returns:

  • (Boolean)

    Auto-enable ActiveAgent adapter on boot (default: false)



75
76
77
# File 'lib/tracebook/config.rb', line 75

def auto_subscribe_active_agent
  @auto_subscribe_active_agent
end

#auto_subscribe_ruby_llmBoolean

Returns Auto-enable RubyLLM adapter on boot (default: false).

Returns:

  • (Boolean)

    Auto-enable RubyLLM adapter on boot (default: false)



71
72
73
# File 'lib/tracebook/config.rb', line 71

def auto_subscribe_ruby_llm
  @auto_subscribe_ruby_llm
end

#custom_redactorsArray<Proc>

Additional user-defined redactors that receive the payload string and return a redacted version.

Examples:

config.custom_redactors += [
  ->(payload) { payload.gsub(/secret=\w+/, "secret=[REDACTED]") }
]

Returns:

  • (Array<Proc>)

    Custom redaction lambdas



67
68
69
# File 'lib/tracebook/config.rb', line 67

def custom_redactors
  @custom_redactors
end

#default_currencyString

Used in PricingRule cost tracking

Returns:

  • (String)

    Currency code for cost calculations (default: "USD")



46
47
48
# File 'lib/tracebook/config.rb', line 46

def default_currency
  @default_currency
end

#export_formatsArray<Symbol>

Supported formats for ExportJob

Returns:

  • (Array<Symbol>)

    Available export formats (default: [:csv, :ndjson])



51
52
53
# File 'lib/tracebook/config.rb', line 51

def export_formats
  @export_formats
end

#inline_payload_bytesInteger

Payloads larger than this threshold are stored as ActiveStorage blobs instead of inline JSONB columns.

Returns:

  • (Integer)

    Maximum payload size before spilling to ActiveStorage (default: 64KB)



41
42
43
# File 'lib/tracebook/config.rb', line 41

def inline_payload_bytes
  @inline_payload_bytes
end

#per_pageInteger

Returns Number of interactions per page in dashboard (default: 100).

Returns:

  • (Integer)

    Number of interactions per page in dashboard (default: 100)



79
80
81
# File 'lib/tracebook/config.rb', line 79

def per_page
  @per_page
end

#persist_asyncBoolean

When true, Tracebook.record! enqueues PersistInteractionJob. When false, interactions are persisted inline.

Returns:

  • (Boolean)

    Whether to persist interactions asynchronously (default: true)



35
36
37
# File 'lib/tracebook/config.rb', line 35

def persist_async
  @persist_async
end

#project_nameString?

Used to filter interactions by project in the dashboard

Returns:

  • (String, nil)

    Project identifier for this application (optional)



29
30
31
# File 'lib/tracebook/config.rb', line 29

def project_name
  @project_name
end

#redactorsArray<Redactor>

Default redactors for email, phone, credit card numbers. See Redactors::Email, Redactors::Phone, Redactors::CardPAN

Returns:

  • (Array<Redactor>)

    Built-in PII redactors



57
58
59
# File 'lib/tracebook/config.rb', line 57

def redactors
  @redactors
end

Instance Method Details

#default_redactorsObject (private)



119
120
121
122
123
124
125
# File 'lib/tracebook/config.rb', line 119

def default_redactors
  [
    Tracebook::Redactors::Email.new,
    Tracebook::Redactors::Phone.new,
    Tracebook::Redactors::CardPAN.new
  ]
end

#finalize!void

This method returns an undefined value.

Freezes the configuration to prevent further changes.

Called automatically by Tracebook.configure after the block executes.



109
110
111
112
113
114
115
# File 'lib/tracebook/config.rb', line 109

def finalize!
  return if finalized?

  @finalized = true
  freeze_collections!
  freeze
end

#finalized?Boolean

Returns true if configuration has been finalized.

Returns:

  • (Boolean)


100
101
102
# File 'lib/tracebook/config.rb', line 100

def finalized?
  @finalized == true
end

#freeze_collections!Object (private)



127
128
129
130
131
# File 'lib/tracebook/config.rb', line 127

def freeze_collections!
  @redactors = @redactors.map { |redactor| redactor }.freeze
  @custom_redactors = @custom_redactors.map { |callable| callable }.freeze
  @export_formats = @export_formats.map(&:to_sym).freeze
end