Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

test: Misc logs fixes #1697

Merged
merged 11 commits into from
Sep 4, 2024
2 changes: 1 addition & 1 deletion logs_api/test/opentelemetry/logs/logger_test.rb
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@
describe OpenTelemetry::Logs::Logger do
let(:logger) { OpenTelemetry::Logs::Logger.new }

describe '#emit' do
describe '#on_emit' do
it 'returns nil, as it is a no-op method' do
assert_nil(logger.on_emit)
end
Expand Down
7 changes: 6 additions & 1 deletion logs_api/test/test_helper.rb
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,12 @@
# SPDX-License-Identifier: Apache-2.0

require 'simplecov'
SimpleCov.start { enable_coverage :branch }

SimpleCov.start do
enable_coverage :branch
add_filter '/test/'
end

SimpleCov.minimum_coverage 85

require 'opentelemetry-logs-api'
Expand Down
2 changes: 1 addition & 1 deletion logs_sdk/lib/opentelemetry/sdk/logs/log_record_data.rb
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@ module Logs
:severity_text, # optional String
:severity_number, # optional Integer
:body, # optional String, Numeric, Boolean, Array<String, Numeric, Boolean>, Hash{String => String, Numeric, Boolean, Array<String, Numeric, Boolean>}
:attributes, # optional Hash{String => String, Numeric, Boolean, Array<String, Numeric, Boolean>}
:attributes, # optional Hash{String => String, Numeric, Boolean, Array<String, Numeric, Boolean>}
:trace_id, # optional String (16-byte binary)
:span_id, # optional String (8-byte binary)
:trace_flags, # optional Integer (8-bit byte of bit flags)
Expand Down
4 changes: 2 additions & 2 deletions logs_sdk/lib/opentelemetry/sdk/logs/log_record_processor.rb
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,7 @@ def on_emit(log_record, context); end
# the process after an invocation, but before the `Processor` exports
# the completed spans.
#
# @param [Numeric] timeout An optional timeout in seconds.
# @param [optional Numeric] timeout An optional timeout in seconds.
# @return [Integer] Export::SUCCESS if no error occurred, Export::FAILURE if
# a non-specific failure occurred, Export::TIMEOUT if a timeout occurred.
def force_flush(timeout: nil)
Expand All @@ -35,7 +35,7 @@ def force_flush(timeout: nil)

# Called when {LoggerProvider#shutdown} is called.
#
# @param [Numeric] timeout An optional timeout in seconds.
# @param [optional Numeric] timeout An optional timeout in seconds.
# @return [Integer] Export::SUCCESS if no error occurred, Export::FAILURE if
# a non-specific failure occurred, Export::TIMEOUT if a timeout occurred.
def shutdown(timeout: nil)
Expand Down
2 changes: 2 additions & 0 deletions logs_sdk/lib/opentelemetry/sdk/logs/logger.rb
Original file line number Diff line number Diff line change
Expand Up @@ -34,6 +34,8 @@ def initialize(name, version, logger_provider)
# @param [optional OpenTelemetry::Trace::SpanContext] span_context The
# OpenTelemetry::Trace::SpanContext to associate with the
# {LogRecord}.
# @param [optional String] severity_text Original string representation of
# the severity as it is known at the source. Also known as log level.
# @param severity_number [optional Integer] Numerical value of the
# severity. Smaller numerical values correspond to less severe events
# (such as debug events), larger numerical values correspond to more
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,33 @@
# frozen_string_literal: true

# Copyright The OpenTelemetry Authors
#
# SPDX-License-Identifier: Apache-2.0

require 'test_helper'

describe OpenTelemetry::SDK::Logs::LogRecordProcessor do
let(:processor) { OpenTelemetry::SDK::Logs::LogRecordProcessor.new }
let(:log_record) { nil }
let(:context) { nil }

it 'implements #on_emit' do
processor.on_emit(log_record, context)
end

it 'implements #force_flush' do
processor.force_flush
end

it 'returns a success code when #force_flush is called' do
assert(OpenTelemetry::SDK::Logs::Export::SUCCESS, processor.force_flush)
end

it 'implements #shutdown' do
processor.shutdown
end

it 'returns a success code when #shutdown is called' do
assert(OpenTelemetry::SDK::Logs::Export::SUCCESS, processor.shutdown)
end
end
10 changes: 3 additions & 7 deletions logs_sdk/test/opentelemetry/sdk/logs/log_record_test.rb
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,8 @@
describe '#initialize' do
describe 'observed_timestamp' do
describe 'when observed_timestamp is present' do
let(:observed_timestamp) { '1692661486.2841358' }
let(:current_time) { Time.now }
let(:observed_timestamp) { current_time + 1 }
let(:args) { { observed_timestamp: observed_timestamp } }

it 'is equal to observed_timestamp' do
Expand All @@ -26,13 +27,8 @@
refute_equal(log_record.timestamp, log_record.observed_timestamp)
end

# Process.clock_gettime is used to set the current time
# That method returns a Float. Since the stubbed value of
# observed_timestamp is a String, we can know the the
# observed_timestamp was not set to the value of Process.clock_gettime
# by making sure its value is not a Float.
it 'is not equal to the current time' do
refute_instance_of(Float, log_record.observed_timestamp)
refute_equal(current_time, log_record.observed_timestamp)
end
end

Expand Down
7 changes: 6 additions & 1 deletion logs_sdk/test/test_helper.rb
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,12 @@
# SPDX-License-Identifier: Apache-2.0

require 'simplecov'
SimpleCov.start { enable_coverage :branch }

SimpleCov.start do
enable_coverage :branch
add_filter '/test/'
end

SimpleCov.minimum_coverage 85

require 'opentelemetry-logs-api'
Expand Down
Loading