Class: OpenTelemetry::SDK::Logs::Export::InMemoryLogRecordExporter

Inherits:
Object
  • Object
show all
Defined in:
lib/opentelemetry/sdk/logs/export/in_memory_log_record_exporter.rb

Overview

refute_nil(log_records) assert_equal(1, log_records.size) assert_equal(log_records.body, 'log') end end

Instance Method Summary collapse

Constructor Details

#initializeObject



36
37
38
39
40
# File 'lib/opentelemetry/sdk/logs/export/in_memory_log_record_exporter.rb', line 36

def initialize
  @emitted_log_records = []
  @stopped = false
  @mutex = Mutex.new
end

Instance Method Details

#emitted_log_recordsArray<LogRecordData>

Returns a frozen array of the emitted LogRecordDatas, represented by OpenTelemetry::SDK::Logs::Export::InMemoryLogRecordExporter.ioio.opentelemetryio.opentelemetry.protoio.opentelemetry.proto.traceio.opentelemetry.proto.trace.v1io.opentelemetry.proto.trace.v1.LogRecord.

Returns:



46
47
48
49
50
# File 'lib/opentelemetry/sdk/logs/export/in_memory_log_record_exporter.rb', line 46

def emitted_log_records
  @mutex.synchronize do
    @emitted_log_records.clone.freeze
  end
end

#export(log_record_datas, timeout: nil) ⇒ Integer

Called to export LogRecordDatas.

Parameters:

  • log_record_datas (Enumerable<LogRecordData>)

    the list of LogRecordDatas to be exported.

  • timeout (optional Numeric) (defaults to: nil)

    An optional timeout in seconds.

Returns:

  • (Integer)

    the result of the export, SUCCESS or FAILURE



68
69
70
71
72
73
74
75
# File 'lib/opentelemetry/sdk/logs/export/in_memory_log_record_exporter.rb', line 68

def export(log_record_datas, timeout: nil)
  @mutex.synchronize do
    return FAILURE if @stopped

    @emitted_log_records.concat(log_record_datas.to_a)
  end
  SUCCESS
end

#force_flush(timeout: nil) ⇒ Integer

Called when LoggerProvider#force_flush is called, if this exporter is registered to a LoggerProvider object.

Parameters:

  • timeout (optional Numeric) (defaults to: nil)

    An optional timeout in seconds.

Returns:

  • (Integer)

    SUCCESS if no error occurred, FAILURE if a non-specific failure occurred, TIMEOUT if a timeout occurred.



83
84
85
# File 'lib/opentelemetry/sdk/logs/export/in_memory_log_record_exporter.rb', line 83

def force_flush(timeout: nil)
  SUCCESS
end

#resetObject

Clears the internal collection of emitted LogRecords.

Does not reset the state of this exporter if already shutdown.



55
56
57
58
59
# File 'lib/opentelemetry/sdk/logs/export/in_memory_log_record_exporter.rb', line 55

def reset
  @mutex.synchronize do
    @emitted_log_records.clear
  end
end

#shutdown(timeout: nil) ⇒ Integer

Called when LoggerProvider#shutdown is called, if this exporter is registered to a LoggerProvider object.

Parameters:

  • timeout (optional Numeric) (defaults to: nil)

    An optional timeout in seconds.

Returns:

  • (Integer)

    SUCCESS if no error occurred, FAILURE if a non-specific failure occurred, TIMEOUT if a timeout occurred.



93
94
95
96
97
98
99
# File 'lib/opentelemetry/sdk/logs/export/in_memory_log_record_exporter.rb', line 93

def shutdown(timeout: nil)
  @mutex.synchronize do
    @emitted_log_records.clear
    @stopped = true
  end
  SUCCESS
end