Class: Minato::Trace::Configuration
- Inherits:
-
Object
- Object
- Minato::Trace::Configuration
- Defined in:
- lib/minato/trace/configuration.rb
Instance Attribute Summary collapse
-
#enabled ⇒ Object
Indicates whether the trace functionality is enabled.
-
#excluded_routes ⇒ Object
A list of routes that should be excluded from tracing.
-
#otlp_endpoint ⇒ Object
This is the endpoint where traces will be sent.
-
#project_id ⇒ Object
The ID of the project on Google Cloud It’s used to generate official links betewwn the Cloud Trace and the Cloud Logging Example: “meu-gcp-project-id”.
-
#runtime_environment ⇒ Object
readonly
The runtime environment in which the application is running.
-
#service_name ⇒ Object
The name of the service to be used in Google Cloud Trace.
Instance Method Summary collapse
- #console_exporter ⇒ Object
- #disable! ⇒ Object
- #enable! ⇒ Object
- #enabled? ⇒ Boolean
- #exporter ⇒ Object
-
#initialize ⇒ Configuration
constructor
A new instance of Configuration.
- #noop_exporter ⇒ Object
- #ot_resources ⇒ Object
- #otlp_exporter ⇒ Object
Constructor Details
#initialize ⇒ Configuration
Returns a new instance of Configuration.
47 48 49 50 51 52 53 54 |
# File 'lib/minato/trace/configuration.rb', line 47 def initialize @enabled = ENV["MINATO_TRACE_DISABLED"] != "true" @service_name = nil @otlp_endpoint = ENV["OTEL_EXPORTER_OTLP_ENDPOINT"] || nil @excluded_routes = ["/health/alive", "/health/ready"] @runtime_environment = ENV["RUNTIME_ENV"] || ENV["RAILS_ENV"] || nil @project_id = ENV["GOOGLE_CLOUD_PROJECT"] || ENV["GCP_PROJECT"] || nil end |
Instance Attribute Details
#enabled ⇒ Object
Indicates whether the trace functionality is enabled. This can be controlled via the ‘MINATO_TRACE_DISABLED` environment variable. If set to “true”, tracing will be disabled. Default is true, meaning tracing is enabled unless explicitly disabled. Example: `ENV = “true”` will disable tracing
14 15 16 |
# File 'lib/minato/trace/configuration.rb', line 14 def enabled @enabled end |
#excluded_routes ⇒ Object
A list of routes that should be excluded from tracing. These routes will not be traced, which is useful for health check endpoints or other endpoints that do not require tracing. Default is [“/health/alive”, “/health/ready”]. You can modify this list to include any other routes you want to exclude.
33 34 35 |
# File 'lib/minato/trace/configuration.rb', line 33 def excluded_routes @excluded_routes end |
#otlp_endpoint ⇒ Object
This is the endpoint where traces will be sent. Default is google’s Cloud Trace endpoint. You can modify this endpoint if you are using a different trace service. Example: “cloudtrace.googleapis.com/v1/projects/my-gcp-project-id/traces”
26 27 28 |
# File 'lib/minato/trace/configuration.rb', line 26 def otlp_endpoint @otlp_endpoint end |
#project_id ⇒ Object
The ID of the project on Google Cloud It’s used to generate official links betewwn the Cloud Trace and the Cloud Logging Example: “meu-gcp-project-id”
45 46 47 |
# File 'lib/minato/trace/configuration.rb', line 45 def project_id @project_id end |
#runtime_environment ⇒ Object (readonly)
The runtime environment in which the application is running. It can be used to differentiate between environments for logging or tracing purposes. Default is the value of the ‘RUNTIME_ENV` environment variable or Rails environment. If `RUNTIME_ENV` is not set, it will default to `Rails.env Example: “production”
40 41 42 |
# File 'lib/minato/trace/configuration.rb', line 40 def runtime_environment @runtime_environment end |
#service_name ⇒ Object
The name of the service to be used in Google Cloud Trace. This is used to identify the service in the Google Cloud Console. It should be a unique name that represents your application. Example: “my-rails-app”
20 21 22 |
# File 'lib/minato/trace/configuration.rb', line 20 def service_name @service_name end |
Instance Method Details
#console_exporter ⇒ Object
83 84 85 86 87 |
# File 'lib/minato/trace/configuration.rb', line 83 def console_exporter OpenTelemetry::SDK::Trace::Export::SimpleSpanProcessor.new( OpenTelemetry::SDK::Trace::Export::ConsoleSpanExporter.new ) end |
#disable! ⇒ Object
64 65 66 |
# File 'lib/minato/trace/configuration.rb', line 64 def disable! @enabled = false end |
#enable! ⇒ Object
68 69 70 |
# File 'lib/minato/trace/configuration.rb', line 68 def enable! @enabled = true end |
#enabled? ⇒ Boolean
60 61 62 |
# File 'lib/minato/trace/configuration.rb', line 60 def enabled? @enabled end |
#exporter ⇒ Object
95 96 97 98 99 |
# File 'lib/minato/trace/configuration.rb', line 95 def exporter return noop_exporter if runtime_environment == "test" otlp_endpoint.nil? ? console_exporter : otlp_exporter end |
#noop_exporter ⇒ Object
89 90 91 92 93 |
# File 'lib/minato/trace/configuration.rb', line 89 def noop_exporter OpenTelemetry::SDK::Trace::Export::SimpleSpanProcessor.new( OpenTelemetry::SDK::Trace::Export::InMemorySpanExporter.new ) end |
#ot_resources ⇒ Object
101 102 103 104 105 106 107 |
# File 'lib/minato/trace/configuration.rb', line 101 def ot_resources resources = { OpenTelemetry::SemanticConventions::Resource::SERVICE_NAME => service_name, OpenTelemetry::SemanticConventions::Resource::DEPLOYMENT_ENVIRONMENT => runtime_environment } OpenTelemetry::SDK::Resources::Resource.create(resources) end |
#otlp_exporter ⇒ Object
72 73 74 75 76 77 78 79 80 81 |
# File 'lib/minato/trace/configuration.rb', line 72 def otlp_exporter OpenTelemetry::SDK::Trace::Export::BatchSpanProcessor.new( OpenTelemetry::Exporter::OTLP::Exporter.new( endpoint: otlp_endpoint ), max_queue_size: 1000, schedule_delay: 1000, max_export_batch_size: 100 ) end |