Class: Foam::Otel::Instance

Inherits:
Object
  • Object
show all
Defined in:
lib/foam/otel/init.rb

Overview

Handle returned by init(). Providers are global — this mostly carries the resolved config and shutdown.

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(service_name, config) ⇒ Instance

Returns a new instance of Instance.



23
24
25
26
27
# File 'lib/foam/otel/init.rb', line 23

def initialize(service_name, config)
  @service_name = service_name
  @config = config
  @providers = []
end

Instance Attribute Details

#configObject (readonly)

Returns the value of attribute config.



20
21
22
# File 'lib/foam/otel/init.rb', line 20

def config
  @config
end

#providersObject

Returns the value of attribute providers.



21
22
23
# File 'lib/foam/otel/init.rb', line 21

def providers
  @providers
end

#service_nameObject (readonly)

Returns the value of attribute service_name.



20
21
22
# File 'lib/foam/otel/init.rb', line 20

def service_name
  @service_name
end

Instance Method Details

#shutdownObject



29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
# File 'lib/foam/otel/init.rb', line 29

def shutdown
  if @providers.empty?
    # This instance owns no providers (inert, or a later init whose
    # signals were already wired). It must not tear down the owner's
    # pipelines, but — flush parity — it still best-effort flushes
    # foam's live pipelines so buffered telemetry isn't dropped.
    Foam::Otel.flush_foam_pipelines
    return
  end
  @providers.each do |provider|
    begin
      provider.shutdown
    rescue StandardError
      nil
    end
    Foam::Otel.forget_provider(provider)
  end
  Foam::Otel.clear_fallback_meter_provider_if_in(@providers)
  @providers = []
end