-
Notifications
You must be signed in to change notification settings - Fork 239
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge branch 'main' into rubocop_on_metrics
- Loading branch information
Showing
16 changed files
with
323 additions
and
16 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -6,5 +6,5 @@ | |
|
||
module OpenTelemetry | ||
## Current OpenTelemetry version | ||
VERSION = '1.3.0' | ||
VERSION = '1.4.0' | ||
end |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1 +1,5 @@ | ||
# Release History: opentelemetry-exporter-otlp-metrics | ||
|
||
### v0.1.0 / 2024-08-27 | ||
|
||
Initial release. |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
39 changes: 39 additions & 0 deletions
39
logs_sdk/lib/opentelemetry/sdk/logs/export/console_log_record_exporter.rb
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,39 @@ | ||
# frozen_string_literal: true | ||
|
||
# Copyright The OpenTelemetry Authors | ||
# | ||
# SPDX-License-Identifier: Apache-2.0 | ||
|
||
module OpenTelemetry | ||
module SDK | ||
module Logs | ||
module Export | ||
# Outputs {LogRecordData} to the console. | ||
# | ||
# Potentially useful for exploratory purposes. | ||
class ConsoleLogRecordExporter | ||
def initialize | ||
@stopped = false | ||
end | ||
|
||
def export(log_records, timeout: nil) | ||
return FAILURE if @stopped | ||
|
||
Array(log_records).each { |s| pp s } | ||
|
||
SUCCESS | ||
end | ||
|
||
def force_flush(timeout: nil) | ||
SUCCESS | ||
end | ||
|
||
def shutdown(timeout: nil) | ||
@stopped = true | ||
SUCCESS | ||
end | ||
end | ||
end | ||
end | ||
end | ||
end |
104 changes: 104 additions & 0 deletions
104
logs_sdk/lib/opentelemetry/sdk/logs/export/in_memory_log_record_exporter.rb
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,104 @@ | ||
# frozen_string_literal: true | ||
|
||
# Copyright The OpenTelemetry Authors | ||
# | ||
# SPDX-License-Identifier: Apache-2.0 | ||
|
||
module OpenTelemetry | ||
module SDK | ||
module Logs | ||
module Export | ||
# A LogRecordExporter implementation that can be used to test OpenTelemetry integration. | ||
# | ||
# @example Usage in a test suite: | ||
# class MyClassTest | ||
# def setup | ||
# @logger_provider = LoggerProvider.new | ||
# @exporter = InMemoryLogRecordExporter.new | ||
# @logger_provider.add_log_record_processor(SimpleLogRecordProcessor.new(@exporter)) | ||
# end | ||
# | ||
# def test_emitted_log_records | ||
# log_record = OpenTelemetry::SDK::Logs::LogRecord.new(body: 'log') | ||
# @logger_provider.logger.on_emit(log_record, context) | ||
# | ||
# log_records = @exporter.emitted_log_records | ||
|
||
# refute_nil(log_records) | ||
# assert_equal(1, log_records.size) | ||
# assert_equal(log_records[0].body, 'log') | ||
# end | ||
# end | ||
class InMemoryLogRecordExporter | ||
# Returns a new instance of the {InMemoryLogRecordExporter}. | ||
# | ||
# @return a new instance of the {InMemoryLogRecordExporter}. | ||
def initialize | ||
@emitted_log_records = [] | ||
@stopped = false | ||
@mutex = Mutex.new | ||
end | ||
|
||
# Returns a frozen array of the emitted {LogRecordData}s, represented by | ||
# {io.opentelemetry.proto.trace.v1.LogRecord}. | ||
# | ||
# @return [Array<LogRecordData>] a frozen array of the emitted {LogRecordData}s. | ||
def emitted_log_records | ||
@mutex.synchronize do | ||
@emitted_log_records.clone.freeze | ||
end | ||
end | ||
|
||
# Clears the internal collection of emitted {LogRecord}s. | ||
# | ||
# Does not reset the state of this exporter if already shutdown. | ||
def reset | ||
@mutex.synchronize do | ||
@emitted_log_records.clear | ||
end | ||
end | ||
|
||
# Called to export {LogRecordData}s. | ||
# | ||
# @param [Enumerable<LogRecordData>] log_record_datas the list of {LogRecordData}s to be | ||
# exported. | ||
# @param [optional Numeric] timeout An optional timeout in seconds. | ||
# @return [Integer] the result of the export, SUCCESS or | ||
# FAILURE | ||
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 | ||
|
||
# Called when {LoggerProvider#force_flush} is called, if this exporter is | ||
# registered to a {LoggerProvider} object. | ||
# | ||
# @param [optional Numeric] timeout An optional timeout in seconds. | ||
# @return [Integer] SUCCESS if no error occurred, FAILURE if a | ||
# non-specific failure occurred, TIMEOUT if a timeout occurred. | ||
def force_flush(timeout: nil) | ||
SUCCESS | ||
end | ||
|
||
# Called when {LoggerProvider#shutdown} is called, if this exporter is | ||
# registered to a {LoggerProvider} object. | ||
# | ||
# @param [optional Numeric] timeout An optional timeout in seconds. | ||
# @return [Integer] SUCCESS if no error occurred, FAILURE if a | ||
# non-specific failure occurred, TIMEOUT if a timeout occurred. | ||
def shutdown(timeout: nil) | ||
@mutex.synchronize do | ||
@emitted_log_records.clear | ||
@stopped = true | ||
end | ||
SUCCESS | ||
end | ||
end | ||
end | ||
end | ||
end | ||
end |
56 changes: 56 additions & 0 deletions
56
logs_sdk/test/opentelemetry/sdk/logs/export/console_log_record_exporter_test.rb
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,56 @@ | ||
# frozen_string_literal: true | ||
|
||
# Copyright The OpenTelemetry Authors | ||
# | ||
# SPDX-License-Identifier: Apache-2.0 | ||
|
||
require 'test_helper' | ||
|
||
describe OpenTelemetry::SDK::Logs::Export::ConsoleLogRecordExporter do | ||
export = OpenTelemetry::SDK::Logs::Export | ||
|
||
let(:captured_stdout) { StringIO.new } | ||
let(:log_record_data1) { Logs::LogRecordData.new } | ||
let(:log_record_data2) { Logs::LogRecordData.new } | ||
let(:log_records) { [log_record_data1, log_record_data2] } | ||
let(:exporter) { export::ConsoleLogRecordExporter.new } | ||
|
||
before do | ||
@original_stdout = $stdout | ||
$stdout = captured_stdout | ||
end | ||
|
||
after do | ||
$stdout = @original_stdout | ||
end | ||
|
||
it 'accepts an Array of LogRecordData as arg to #export and succeeds' do | ||
assert_equal(export::SUCCESS, exporter.export(log_records)) | ||
end | ||
|
||
it 'accepts an Enumerable of LogRecordData as arg to #export and succeeds' do | ||
enumerable = Struct.new(:log_record0, :log_record1).new(log_records[0], log_records[1]) | ||
|
||
assert_equal(export::SUCCESS, exporter.export(enumerable)) | ||
end | ||
|
||
it 'outputs to console (stdout)' do | ||
exporter.export(log_records) | ||
|
||
assert_match(/#<struct OpenTelemetry::SDK::Logs::LogRecordData/, captured_stdout.string) | ||
end | ||
|
||
it 'accepts calls to #force_flush' do | ||
exporter.force_flush | ||
end | ||
|
||
it 'accepts calls to #shutdown' do | ||
exporter.shutdown | ||
end | ||
|
||
it 'fails to export after shutdown' do | ||
exporter.shutdown | ||
|
||
assert_equal(export::FAILURE, exporter.export(log_records)) | ||
end | ||
end |
Oops, something went wrong.