Module: Dash0::OpenTelemetry::Lifecycle

Defined in:
lib/dash0/opentelemetry/lifecycle.rb

Overview

Process-lifecycle concerns: an optional bootstrap span at startup, and graceful flushing of pending telemetry on shutdown.

Constant Summary collapse

BOOTSTRAP_SPAN_ENV =
'DASH0_BOOTSTRAP_SPAN'
FLUSH_ON_SIGNALS_ENV =
'DASH0_FLUSH_ON_SIGTERM_SIGINT'
FLUSH_ON_EXIT_ENV =
'DASH0_FLUSH_ON_EXIT'
BOOTSTRAP_TRACER =

Name of the tracer used for the bootstrap span.

'dash0-ruby-distribution'
SHUTDOWN_TIMEOUT_SECONDS =

Per-provider shutdown timeout (seconds). Bounds how long process exit can block flushing telemetry to a slow or unreachable collector.

2.0
FLUSH_SIGNALS =

Signals whose default action would otherwise terminate the process without running at_exit, so we flush explicitly before re-raising.

%w[TERM INT].freeze

Class Method Summary collapse

Class Method Details

.installObject

Installs the configured lifecycle behaviors. Called once, after the SDK has been configured.



32
33
34
35
36
37
# File 'lib/dash0/opentelemetry/lifecycle.rb', line 32

def install
  name = bootstrap_span_name
  create_bootstrap_span(name) if name
  install_signal_handlers if flush_on_signals?
  install_exit_handler if flush_on_exit?
end

.reset_for_testing!Object

Resets the one-time shutdown guard. Intended for tests only.



60
61
62
# File 'lib/dash0/opentelemetry/lifecycle.rb', line 60

def reset_for_testing!
  @shutdown_done = false
end

.shutdownObject

Gracefully shuts down the tracer, meter, and logger providers, flushing pending telemetry. Idempotent: only the first call performs the shutdown.



41
42
43
44
45
46
47
48
49
50
51
52
53
# File 'lib/dash0/opentelemetry/lifecycle.rb', line 41

def shutdown
  @shutdown_mutex.synchronize do
    return if @shutdown_done

    @shutdown_done = true
  end

  providers.each do |provider|
    provider.shutdown(timeout: SHUTDOWN_TIMEOUT_SECONDS)
  rescue StandardError => e
    Dash0::OpenTelemetry.log_debug("Error during provider shutdown: #{e.message}")
  end
end

.shutdown?Boolean

Returns:

  • (Boolean)


55
56
57
# File 'lib/dash0/opentelemetry/lifecycle.rb', line 55

def shutdown?
  @shutdown_done
end