-
Notifications
You must be signed in to change notification settings - Fork 244
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
feat: Add log record attribute limits (#1696)
* feat: Add log record attribute limits Similar to SpanLimits, add a LogRecordLimits class that handles configuration of attribute count and value length values. * Update logs_sdk/test/opentelemetry/sdk/logs/log_record_test.rb * Update logs_sdk/lib/opentelemetry/sdk/logs/log_record.rb * Update logs_sdk/lib/opentelemetry/sdk/logs/log_record.rb --------- Co-authored-by: Matthew Wear <matthew.wear@gmail.com>
- Loading branch information
1 parent
7aa9c11
commit c469bb5
Showing
7 changed files
with
277 additions
and
6 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
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,43 @@ | ||
# frozen_string_literal: true | ||
|
||
# Copyright The OpenTelemetry Authors | ||
# | ||
# SPDX-License-Identifier: Apache-2.0 | ||
|
||
module OpenTelemetry | ||
module SDK | ||
module Logs | ||
# Class that holds log record attribute limit parameters. | ||
class LogRecordLimits | ||
# The global default max number of attributes per {LogRecord}. | ||
attr_reader :attribute_count_limit | ||
|
||
# The global default max length of attribute value per {LogRecord}. | ||
attr_reader :attribute_length_limit | ||
|
||
# Returns a {LogRecordLimits} with the desired values. | ||
# | ||
# @return [LogRecordLimits] with the desired values. | ||
# @raise [ArgumentError] if any of the max numbers are not positive. | ||
def initialize(attribute_count_limit: Integer(OpenTelemetry::Common::Utilities.config_opt( | ||
'OTEL_LOG_RECORD_ATTRIBUTE_COUNT_LIMIT', | ||
'OTEL_ATTRIBUTE_COUNT_LIMIT', | ||
default: 128 | ||
)), | ||
attribute_length_limit: OpenTelemetry::Common::Utilities.config_opt( | ||
'OTEL_LOG_RECORD_ATTRIBUTE_VALUE_LENGTH_LIMIT', | ||
'OTEL_ATTRIBUTE_VALUE_LENGTH_LIMIT' | ||
)) | ||
raise ArgumentError, 'attribute_count_limit must be positive' unless attribute_count_limit.positive? | ||
raise ArgumentError, 'attribute_length_limit must not be less than 32' unless attribute_length_limit.nil? || Integer(attribute_length_limit) >= 32 | ||
|
||
@attribute_count_limit = attribute_count_limit | ||
@attribute_length_limit = attribute_length_limit.nil? ? nil : Integer(attribute_length_limit) | ||
end | ||
|
||
# The default {LogRecordLimits}. | ||
DEFAULT = new | ||
end | ||
end | ||
end | ||
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
79 changes: 79 additions & 0 deletions
79
logs_sdk/test/opentelemetry/sdk/logs/log_record_limits_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,79 @@ | ||
# frozen_string_literal: true | ||
|
||
# Copyright The OpenTelemetry Authors | ||
# | ||
# SPDX-License-Identifier: Apache-2.0 | ||
|
||
require 'test_helper' | ||
|
||
describe OpenTelemetry::SDK::Logs::LogRecordLimits do | ||
let(:log_record_limits) { OpenTelemetry::SDK::Logs::LogRecordLimits.new } | ||
|
||
describe '#initialize' do | ||
it 'provides defaults' do | ||
_(log_record_limits.attribute_count_limit).must_equal 128 | ||
_(log_record_limits.attribute_length_limit).must_be_nil | ||
end | ||
|
||
it 'prioritizes specific environment varibles for attribute value length limits' do | ||
OpenTelemetry::TestHelpers.with_env('OTEL_ATTRIBUTE_VALUE_LENGTH_LIMIT' => '35', | ||
'OTEL_LOG_RECORD_ATTRIBUTE_VALUE_LENGTH_LIMIT' => '33') do | ||
_(log_record_limits.attribute_length_limit).must_equal 33 | ||
end | ||
end | ||
|
||
it 'uses general attribute value length limits in the absence of more specific ones' do | ||
OpenTelemetry::TestHelpers.with_env('OTEL_ATTRIBUTE_VALUE_LENGTH_LIMIT' => '35') do | ||
_(log_record_limits.attribute_length_limit).must_equal 35 | ||
end | ||
end | ||
|
||
it 'reflects environment variables' do | ||
OpenTelemetry::TestHelpers.with_env('OTEL_LOG_RECORD_ATTRIBUTE_COUNT_LIMIT' => '1', | ||
'OTEL_LOG_RECORD_ATTRIBUTE_VALUE_LENGTH_LIMIT' => '32') do | ||
_(log_record_limits.attribute_count_limit).must_equal 1 | ||
_(log_record_limits.attribute_length_limit).must_equal 32 | ||
end | ||
end | ||
|
||
it 'reflects explicit overrides' do | ||
OpenTelemetry::TestHelpers.with_env('OTEL_LOG_RECORD_ATTRIBUTE_COUNT_LIMIT' => '1', | ||
'OTEL_LOG_RECORD_ATTRIBUTE_VALUE_LENGTH_LIMIT' => '4') do | ||
log_record_limits = OpenTelemetry::SDK::Logs::LogRecordLimits.new(attribute_count_limit: 10, | ||
attribute_length_limit: 32) | ||
_(log_record_limits.attribute_count_limit).must_equal 10 | ||
_(log_record_limits.attribute_length_limit).must_equal 32 | ||
end | ||
end | ||
|
||
it 'reflects generic attribute env vars' do | ||
OpenTelemetry::TestHelpers.with_env('OTEL_ATTRIBUTE_COUNT_LIMIT' => '1', | ||
'OTEL_ATTRIBUTE_VALUE_LENGTH_LIMIT' => '32') do | ||
_(log_record_limits.attribute_count_limit).must_equal 1 | ||
_(log_record_limits.attribute_length_limit).must_equal 32 | ||
end | ||
end | ||
|
||
it 'prefers model-specific attribute env vars over generic attribute env vars' do | ||
OpenTelemetry::TestHelpers.with_env('OTEL_LOG_RECORD_ATTRIBUTE_COUNT_LIMIT' => '1', | ||
'OTEL_ATTRIBUTE_COUNT_LIMIT' => '2', | ||
'OTEL_LOG_RECORD_ATTRIBUTE_VALUE_LENGTH_LIMIT' => '32', | ||
'OTEL_ATTRIBUTE_VALUE_LENGTH_LIMIT' => '33') do | ||
_(log_record_limits.attribute_count_limit).must_equal 1 | ||
_(log_record_limits.attribute_length_limit).must_equal 32 | ||
end | ||
end | ||
|
||
it 'raises if attribute_count_limit is not positive' do | ||
assert_raises ArgumentError do | ||
OpenTelemetry::SDK::Logs::LogRecordLimits.new(attribute_count_limit: -1) | ||
end | ||
end | ||
|
||
it 'raises if attribute_length_limit is less than 32' do | ||
assert_raises ArgumentError do | ||
OpenTelemetry::SDK::Logs::LogRecordLimits.new(attribute_length_limit: 31) | ||
end | ||
end | ||
end | ||
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