class AwsLambdaRuntimeInterfaceClient::TelemetryLoggingHelper

Helper class to for mutating std logger with TelemetryLog

Constants

ENV_VAR_TELEMETRY_LOG_FD

Attributes

telemetry_log_fd_file[RW]
telemetry_log_sink[RW]

Public Class Methods

close() click to toggle source
# File lib/aws_lambda_ric.rb, line 131
def close
  telemetry_log_fd_file&.close
end
new(telemetry_log_fd, path_to_fd='/proc/self/fd/') click to toggle source
# File lib/aws_lambda_ric.rb, line 136
def initialize(telemetry_log_fd, path_to_fd='/proc/self/fd/')
  fd = "#{path_to_fd}#{telemetry_log_fd}"
  AwsLambdaRuntimeInterfaceClient::TelemetryLoggingHelper.telemetry_log_fd_file = File.open(fd, 'wb')
  AwsLambdaRuntimeInterfaceClient::TelemetryLoggingHelper.telemetry_log_fd_file.sync = true

  AwsLambdaRuntimeInterfaceClient::TelemetryLoggingHelper.telemetry_log_sink = TelemetryLogSink.new(file: AwsLambdaRuntimeInterfaceClient::TelemetryLoggingHelper.telemetry_log_fd_file)

  mutate_std_logger
  mutate_kernel_puts
rescue Errno::ENOENT
  # If File.open() fails, then the mutation won't happen and the default behaviour (print to stdout) will prevail
end

Private Instance Methods

mutate_kernel_puts() click to toggle source
# File lib/aws_lambda_ric.rb, line 157
def mutate_kernel_puts
  Kernel.module_eval do
    def puts(*arg)
      msg = arg.flatten.collect { |a| a.to_s.encode('UTF-8') }.join("\n")
      AwsLambdaRuntimeInterfaceClient::TelemetryLoggingHelper.telemetry_log_sink.write(msg)
    end
  end
end
mutate_std_logger() click to toggle source
# File lib/aws_lambda_ric.rb, line 151
def mutate_std_logger
  Logger.class_eval do
    prepend LoggerPatch
  end
end
puts(*arg) click to toggle source
# File lib/aws_lambda_ric.rb, line 159
def puts(*arg)
  msg = arg.flatten.collect { |a| a.to_s.encode('UTF-8') }.join("\n")
  AwsLambdaRuntimeInterfaceClient::TelemetryLoggingHelper.telemetry_log_sink.write(msg)
end