Sha256: 178a9f2483f08da09afa513d3a5fc3c2bd49c41407bfc55538703a3e8dfbb80a

Contents?: true

Size: 1.77 KB

Versions: 7

Compression:

Stored size: 1.77 KB

Contents

# frozen_string_literal: true

module Datadog
  module Core
    module Telemetry
      # === INTERNAL USAGE ONLY ===
      #
      # Report telemetry logs via delegating to the telemetry component instance via mutex.
      #
      # IMPORTANT: Invoking this method during the lifecycle of component initialization will
      # be no-op instead.
      #
      # For developer using this module:
      #   read: lib/datadog/core/telemetry/logging.rb
      module Logger
        class << self
          def report(exception, level: :error, description: nil)
            instance&.report(exception, level: level, description: description)
          end

          def error(description)
            instance&.error(description)
          end

          private

          def instance
            # Component initialization uses a mutex to avoid having concurrent initialization.
            # Trying to access the telemetry component during initialization (specifically:
            # from the thread that's actually doing the initialization) would cause a deadlock,
            # since accessing the components would try to recursively lock the mutex.
            #
            # To work around this, we use allow_initialization: false to avoid triggering this issue.
            #
            # The downside is: this leaves us unable to report telemetry during component initialization.
            components = Datadog.send(:components, allow_initialization: false)

            if components && components.telemetry
              components.telemetry
            else
              Datadog.logger.warn(
                'Failed to send telemetry before components initialization or within components lifecycle'
              )
              nil
            end
          end
        end
      end
    end
  end
end

Version data entries

7 entries across 7 versions & 1 rubygems

Version Path
datadog-2.9.0 lib/datadog/core/telemetry/logger.rb
datadog-2.8.0 lib/datadog/core/telemetry/logger.rb
datadog-2.7.1 lib/datadog/core/telemetry/logger.rb
datadog-2.7.0 lib/datadog/core/telemetry/logger.rb
datadog-2.6.0 lib/datadog/core/telemetry/logger.rb
datadog-2.5.0 lib/datadog/core/telemetry/logger.rb
datadog-2.4.0 lib/datadog/core/telemetry/logger.rb