Module: ScoutApm::Logging::Loggers::OpenTelemetry

Defined in:
lib/scout_apm/logging/loggers/opentelemetry/api/logs.rb,
lib/scout_apm/logging/loggers/opentelemetry/sdk/logs.rb,
lib/scout_apm/logging/loggers/opentelemetry/opentelemetry.rb,
lib/scout_apm/logging/loggers/opentelemetry/api/logs/logger.rb,
lib/scout_apm/logging/loggers/opentelemetry/sdk/logs/export.rb,
lib/scout_apm/logging/loggers/opentelemetry/sdk/logs/logger.rb,
lib/scout_apm/logging/loggers/opentelemetry/api/logs/version.rb,
lib/scout_apm/logging/loggers/opentelemetry/sdk/logs/version.rb,
lib/scout_apm/logging/loggers/opentelemetry/api/logs/log_record.rb,
lib/scout_apm/logging/loggers/opentelemetry/sdk/logs/log_record.rb,
lib/scout_apm/logging/loggers/opentelemetry/api/logs/logger_provider.rb,
lib/scout_apm/logging/loggers/opentelemetry/api/logs/severity_number.rb,
lib/scout_apm/logging/loggers/opentelemetry/sdk/logs/log_record_data.rb,
lib/scout_apm/logging/loggers/opentelemetry/sdk/logs/logger_provider.rb,
lib/scout_apm/logging/loggers/opentelemetry/sdk/logs/log_record_processor.rb,
lib/scout_apm/logging/loggers/opentelemetry/exporter/exporter/otlp/version.rb,
lib/scout_apm/logging/loggers/opentelemetry/sdk/logs/export/log_record_exporter.rb,
lib/scout_apm/logging/loggers/opentelemetry/exporter/exporter/otlp/logs_exporter.rb,
lib/scout_apm/logging/loggers/opentelemetry/sdk/logs/export/batch_log_record_processor.rb

Defined Under Namespace

Modules: Exporter, Logs, SDK

Class Method Summary collapse

Class Method Details

.error_handlerCallable

Returns configured error handler or a default that logs the exception and message at ERROR level.

Returns:

  • (Callable)

    configured error handler or a default that logs the exception and message at ERROR level.



24
25
26
# File 'lib/scout_apm/logging/loggers/opentelemetry/opentelemetry.rb', line 24

def error_handler
  @error_handler ||= ->(exception: nil, message: nil) { logger.error("OpenTelemetry error: #{[message, exception&.message, exception&.backtrace&.first].compact.join(' - ')}") }
end

.handle_error(exception: nil, message: nil) ⇒ Object

Handles an error by calling the configured error_handler.

Parameters:

  • exception (optional Exception) (defaults to: nil)

    The exception to be handled

  • message (optional String) (defaults to: nil)

    An error message.



32
33
34
# File 'lib/scout_apm/logging/loggers/opentelemetry/opentelemetry.rb', line 32

def handle_error(exception: nil, message: nil)
  error_handler.call(exception: exception, message: message)
end

.loggerObject, Logger

Overwritten on setup to be the internal logger.

Returns:

  • (Object, Logger)

    configured Logger or a default STDOUT Logger.



18
19
20
# File 'lib/scout_apm/logging/loggers/opentelemetry/opentelemetry.rb', line 18

def logger
  @logger ||= ::Logger.new($stdout, level: ENV['OTEL_LOG_LEVEL'] || ::Logger::INFO)
end

.logger_providerObject



40
41
42
# File 'lib/scout_apm/logging/loggers/opentelemetry/opentelemetry.rb', line 40

def logger_provider
  @logger_provider
end

.logger_provider=(logger_provider) ⇒ Object



36
37
38
# File 'lib/scout_apm/logging/loggers/opentelemetry/opentelemetry.rb', line 36

def logger_provider=(logger_provider)
  @logger_provider = logger_provider
end

.scout_resource(context) ⇒ Object



54
55
56
57
58
# File 'lib/scout_apm/logging/loggers/opentelemetry/opentelemetry.rb', line 54

def self.scout_resource(context)
  our_resources = ::OpenTelemetry::SDK::Resources::Resource.create({'telemetryhub.key' => context.config.value('logs_ingest_key')})
  default_resources = ::OpenTelemetry::SDK::Resources::Resource.default
  default_resources.merge(our_resources)
end

.setup(context) ⇒ Object



45
46
47
48
49
50
51
52
# File 'lib/scout_apm/logging/loggers/opentelemetry/opentelemetry.rb', line 45

def self.setup(context)
  @logger = context.logger

  exporter = OpenTelemetry::Exporter::OTLP::LogsExporter.new(endpoint: context.config.value('logs_reporting_endpoint_http'))
  processor = OpenTelemetry::SDK::Logs::Export::BatchLogRecordProcessor.new(exporter)
  ScoutApm::Logging::Loggers::OpenTelemetry.logger_provider = OpenTelemetry::SDK::Logs::LoggerProvider.new(resource: scout_resource(context))
  ScoutApm::Logging::Loggers::OpenTelemetry.logger_provider.add_log_record_processor(processor)
end