Class: Tracelit::Configuration
- Inherits:
-
Object
- Object
- Tracelit::Configuration
- Defined in:
- lib/tracelit/configuration.rb
Instance Attribute Summary collapse
-
#api_key ⇒ Object
Required.
-
#enabled ⇒ Object
Set false to disable all telemetry without removing the gem.
-
#endpoint ⇒ Object
Full URL of the Tracelit ingest endpoint.
-
#environment ⇒ Object
Environment tag — production, staging, development, etc.
-
#resource_attributes ⇒ Object
Additional resource attributes appended to every span and log.
-
#sample_rate ⇒ Object
Head-based sampling rate (0.0–1.0).
-
#service_name ⇒ Object
The name of this service as it will appear in Tracelit.
Instance Method Summary collapse
-
#initialize ⇒ Configuration
constructor
A new instance of Configuration.
-
#resolved_service_name ⇒ Object
Infer service name from Rails application if not explicitly set.
-
#valid? ⇒ Boolean
Returns an array of human-readable error strings.
-
#validate! ⇒ Object
Kept for backwards compatibility.
Constructor Details
#initialize ⇒ Configuration
Returns a new instance of Configuration.
31 32 33 34 35 36 37 38 39 |
# File 'lib/tracelit/configuration.rb', line 31 def initialize @api_key = ENV["TRACELIT_API_KEY"] @service_name = ENV["TRACELIT_SERVICE_NAME"] @environment = ENV["TRACELIT_ENVIRONMENT"] || "production" @endpoint = ENV["TRACELIT_ENDPOINT"] || "https://ingest.tracelit.app" @sample_rate = (ENV["TRACELIT_SAMPLE_RATE"] || "1.0").to_f @enabled = ENV["TRACELIT_ENABLED"] != "false" @resource_attributes = {} end |
Instance Attribute Details
#api_key ⇒ Object
Required
6 7 8 |
# File 'lib/tracelit/configuration.rb', line 6 def api_key @api_key end |
#enabled ⇒ Object
Set false to disable all telemetry without removing the gem. Useful for test environments.
25 26 27 |
# File 'lib/tracelit/configuration.rb', line 25 def enabled @enabled end |
#endpoint ⇒ Object
Full URL of the Tracelit ingest endpoint. Override only if self-hosting.
17 18 19 |
# File 'lib/tracelit/configuration.rb', line 17 def endpoint @endpoint end |
#environment ⇒ Object
Environment tag — production, staging, development, etc.
13 14 15 |
# File 'lib/tracelit/configuration.rb', line 13 def environment @environment end |
#resource_attributes ⇒ Object
Additional resource attributes appended to every span and log. Hash of string keys and string values.
29 30 31 |
# File 'lib/tracelit/configuration.rb', line 29 def resource_attributes @resource_attributes end |
#sample_rate ⇒ Object
Head-based sampling rate (0.0–1.0). Default: 1.0 (keep all traces). Set to 0.1 to keep 10% of traces. Errors are always kept regardless.
21 22 23 |
# File 'lib/tracelit/configuration.rb', line 21 def sample_rate @sample_rate end |
#service_name ⇒ Object
The name of this service as it will appear in Tracelit. Defaults to the Rails app name if Rails is present.
10 11 12 |
# File 'lib/tracelit/configuration.rb', line 10 def service_name @service_name end |
Instance Method Details
#resolved_service_name ⇒ Object
Infer service name from Rails application if not explicitly set.
69 70 71 72 73 |
# File 'lib/tracelit/configuration.rb', line 69 def resolved_service_name return service_name if service_name && !service_name.empty? return ::Rails.application.class.module_parent_name.underscore if defined?(::Rails) "unknown-service" end |
#valid? ⇒ Boolean
Returns an array of human-readable error strings. Empty array means the configuration is valid. Never raises — callers decide whether to warn or abort.
44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 |
# File 'lib/tracelit/configuration.rb', line 44 def valid? errors = [] errors << "api_key is required" if api_key.nil? || api_key.to_s.empty? # Fix 3: check resolved_service_name so Rails apps that rely on automatic # name inference (module_parent_name) are not incorrectly flagged. if resolved_service_name == "unknown-service" errors << "service_name is required (set config.service_name or TRACELIT_SERVICE_NAME)" end unless sample_rate.between?(0.0, 1.0) errors << "sample_rate must be between 0.0 and 1.0 (got #{sample_rate})" end errors end |
#validate! ⇒ Object
Kept for backwards compatibility. Previously raised ArgumentError; now a no-op because an observability SDK must never crash the host app. Use valid? to check for configuration errors programmatically.
64 65 66 |
# File 'lib/tracelit/configuration.rb', line 64 def validate! # no-op — see valid? for soft validation end |