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.
- #validate! ⇒ Object
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.
48 49 50 51 52 |
# File 'lib/tracelit/configuration.rb', line 48 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 |
#validate! ⇒ Object
41 42 43 44 45 |
# File 'lib/tracelit/configuration.rb', line 41 def validate! raise ArgumentError, "Tracelit.config.api_key is required" if api_key.nil? || api_key.empty? raise ArgumentError, "Tracelit.config.service_name is required" if service_name.nil? || service_name.empty? raise ArgumentError, "sample_rate must be between 0.0 and 1.0" unless sample_rate.between?(0.0, 1.0) end |