Skip to content
Open
Show file tree
Hide file tree
Changes from 4 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 0 additions & 4 deletions metrics_sdk/.rubocop.yml
Original file line number Diff line number Diff line change
Expand Up @@ -12,10 +12,6 @@ Lint/AmbiguousOperatorPrecedence:
Enabled: false
Lint/AmbiguousRange:
Enabled: false
Naming/BlockForwarding:
Enabled: false
Naming/PredicateMethod:
Enabled: false
Performance/CollectionLiteralInLoop:
Enabled: false
Style/ArgumentsForwarding:
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -134,8 +134,8 @@ def report_result(result_code)
OpenTelemetry.logger.debug 'Successfully exported metrics' if result_code == Export::SUCCESS
end

def lock(&block)
@mutex.synchronize(&block)
def lock(&)
@mutex.synchronize(&)
end
end
end
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -32,9 +32,11 @@ def match_instrument?(metric_stream)
true
end

# rubocop:disable Naming/PredicateMethod
Comment thread
thompson-tomo marked this conversation as resolved.
Outdated
def name_match(stream_name)
!!@regex&.match(stream_name)
end
# rubocop:enable Naming/PredicateMethod

def valid_aggregation?
@aggregation.class.name.rpartition('::')[0] == 'OpenTelemetry::SDK::Metrics::Aggregation'
Expand Down
4 changes: 0 additions & 4 deletions sdk/.rubocop.yml
Original file line number Diff line number Diff line change
Expand Up @@ -10,10 +10,6 @@ Lint/EmptyClass:
Enabled: false
Minitest/UselessAssertion:
Enabled: false
Naming/BlockForwarding:
Enabled: false
Naming/PredicateMethod:
Enabled: false
Style/ArgumentsForwarding:
Enabled: false
Style/EmptyClassDefinition:
Expand Down
28 changes: 14 additions & 14 deletions sdk/lib/opentelemetry/sdk/forwarding_logger.rb
Original file line number Diff line number Diff line change
Expand Up @@ -35,34 +35,34 @@ def initialize(logger, level:)
end
end

def add(severity, message = nil, progname = nil, &block)
def add(severity, message = nil, progname = nil, &)
return true if severity < @level

@logger.add(severity, message, progname, &block)
@logger.add(severity, message, progname, &)
end

def debug(progname = nil, &block)
add(Logger::DEBUG, nil, progname, &block)
def debug(progname = nil, &)
add(Logger::DEBUG, nil, progname, &)
end

def info(progname = nil, &block)
add(Logger::INFO, nil, progname, &block)
def info(progname = nil, &)
add(Logger::INFO, nil, progname, &)
end

def warn(progname = nil, &block)
add(Logger::WARN, nil, progname, &block)
def warn(progname = nil, &)
add(Logger::WARN, nil, progname, &)
end

def error(progname = nil, &block)
add(Logger::ERROR, nil, progname, &block)
def error(progname = nil, &)
add(Logger::ERROR, nil, progname, &)
end

def fatal(progname = nil, &block)
add(Logger::FATAL, nil, progname, &block)
def fatal(progname = nil, &)
add(Logger::FATAL, nil, progname, &)
end

def unknown(progname = nil, &block)
add(Logger::UNKNOWN, nil, progname, &block)
def unknown(progname = nil, &)
add(Logger::UNKNOWN, nil, progname, &)
end
end
end
Expand Down
44 changes: 22 additions & 22 deletions sdk/test/opentelemetry/sdk/trace/samplers_test.rb
Original file line number Diff line number Diff line change
Expand Up @@ -17,21 +17,21 @@

describe '.ALWAYS_ON' do
it 'samples' do
_(call_sampler(Samplers::ALWAYS_ON)).must_be :sampled?
_(call_sampler?(Samplers::ALWAYS_ON)).must_be :sampled?
end

it 'passes through the tracestate from context' do
_(call_sampler(Samplers::ALWAYS_ON, parent_context: context_with_tracestate).tracestate).must_equal tracestate
_(call_sampler?(Samplers::ALWAYS_ON, parent_context: context_with_tracestate).tracestate).must_equal tracestate
end
end

describe '.ALWAYS_OFF' do
it 'does not sample' do
_(call_sampler(Samplers::ALWAYS_OFF)).wont_be :sampled?
_(call_sampler?(Samplers::ALWAYS_OFF)).wont_be :sampled?
end

it 'passes through the tracestate from context' do
_(call_sampler(Samplers::ALWAYS_ON, parent_context: context_with_tracestate).tracestate).must_equal tracestate
_(call_sampler?(Samplers::ALWAYS_ON, parent_context: context_with_tracestate).tracestate).must_equal tracestate
end
end

Expand All @@ -52,10 +52,10 @@

it 'provides defaults for parent samplers' do
sampler = Samplers.parent_based(root: not_a_sampler)
_(call_sampler(sampler, parent_context: remote_sampled_parent_context)).must_be :sampled?
_(call_sampler(sampler, parent_context: remote_not_sampled_parent_context)).wont_be :sampled?
_(call_sampler(sampler, parent_context: local_sampled_parent_context)).must_be :sampled?
_(call_sampler(sampler, parent_context: local_not_sampled_parent_context)).wont_be :sampled?
_(call_sampler?(sampler, parent_context: remote_sampled_parent_context)).must_be :sampled?
_(call_sampler?(sampler, parent_context: remote_not_sampled_parent_context)).wont_be :sampled?
_(call_sampler?(sampler, parent_context: local_sampled_parent_context)).must_be :sampled?
_(call_sampler?(sampler, parent_context: local_not_sampled_parent_context)).wont_be :sampled?
end

it 'delegates sampling of remote sampled spans' do
Expand All @@ -69,7 +69,7 @@
local_parent_not_sampled: not_a_sampler
)
OpenTelemetry::Trace.stub :generate_trace_id, trace_id do
call_sampler(sampler, parent_context: remote_sampled_parent_context)
call_sampler?(sampler, parent_context: remote_sampled_parent_context)
end
mock_sampler.verify
end
Expand All @@ -85,7 +85,7 @@
local_parent_not_sampled: not_a_sampler
)
OpenTelemetry::Trace.stub :generate_trace_id, trace_id do
call_sampler(sampler, parent_context: remote_not_sampled_parent_context)
call_sampler?(sampler, parent_context: remote_not_sampled_parent_context)
end
mock_sampler.verify
end
Expand All @@ -101,7 +101,7 @@
local_parent_not_sampled: not_a_sampler
)
OpenTelemetry::Trace.stub :generate_trace_id, trace_id do
call_sampler(sampler, parent_context: local_sampled_parent_context)
call_sampler?(sampler, parent_context: local_sampled_parent_context)
end
mock_sampler.verify
end
Expand All @@ -117,7 +117,7 @@
local_parent_not_sampled: mock_sampler
)
OpenTelemetry::Trace.stub :generate_trace_id, trace_id do
call_sampler(sampler, parent_context: local_not_sampled_parent_context)
call_sampler?(sampler, parent_context: local_not_sampled_parent_context)
end
mock_sampler.verify
end
Expand All @@ -133,7 +133,7 @@
local_parent_not_sampled: not_a_sampler
)
OpenTelemetry::Trace.stub :generate_trace_id, trace_id do
call_sampler(sampler, parent_context: nil)
call_sampler?(sampler, parent_context: nil)
end
mock_sampler.verify
end
Expand All @@ -147,48 +147,48 @@
span_context = OpenTelemetry::Trace::SpanContext.new(trace_flags: OpenTelemetry::Trace::TraceFlags.from_byte(1))
span = OpenTelemetry::Trace.non_recording_span(span_context)
parent_context = OpenTelemetry::Trace.context_with_span(span)
result = call_sampler(sampler, parent_context: parent_context, trace_id: trace_id(123))
result = call_sampler?(sampler, parent_context: parent_context, trace_id: trace_id(123))
_(result).wont_be :sampled?
end

it 'returns a result' do
result = call_sampler(sampler, trace_id: trace_id(123))
result = call_sampler?(sampler, trace_id: trace_id(123))
_(result).must_be_instance_of(Result)
end

it 'passes through the tracestate from context' do
_(call_sampler(sampler, parent_context: context_with_tracestate).tracestate).must_equal tracestate
_(call_sampler?(sampler, parent_context: context_with_tracestate).tracestate).must_equal tracestate
end

it 'samples if ratio is 1' do
positive = Samplers.trace_id_ratio_based(1)
result = call_sampler(positive, trace_id: 'f' * 32)
result = call_sampler?(positive, trace_id: 'f' * 32)
_(result).must_be :sampled?
end

it 'does not sample if ratio is 0' do
sampler = Samplers.trace_id_ratio_based(0)
result = call_sampler(sampler, trace_id: trace_id(1))
result = call_sampler?(sampler, trace_id: trace_id(1))
_(result).wont_be :sampled?
end

it 'samples the smallest ratio larger than the smallest trace_id' do
ratio = 2.0 / (2**64 - 1)
sampler = Samplers.trace_id_ratio_based(ratio)
result = call_sampler(sampler, trace_id: trace_id(1))
result = call_sampler?(sampler, trace_id: trace_id(1))
_(result).must_be :sampled?
end

it 'does not sample the largest trace_id with ratio less than 1' do
ratio = 1.0.prev_float
sampler = Samplers.trace_id_ratio_based(ratio)
result = call_sampler(sampler, trace_id: trace_id(0xffff_ffff_ffff_ffff))
result = call_sampler?(sampler, trace_id: trace_id(0xffff_ffff_ffff_ffff))
_(result).wont_be :sampled?
end

it 'ignores the high bits of the trace_id for sampling' do
sampler = Samplers.trace_id_ratio_based(0.5)
result = call_sampler(sampler, trace_id: trace_id(0x1_0000_0000_0000_0001))
result = call_sampler?(sampler, trace_id: trace_id(0x1_0000_0000_0000_0001))
_(result).must_be :sampled?
end

Expand All @@ -207,7 +207,7 @@ def trace_id(id)
[first, second].pack('Q>Q>')
end

def call_sampler(sampler, trace_id: nil, parent_context: OpenTelemetry::Context.current, links: nil, name: nil, kind: nil, attributes: nil)
def call_sampler?(sampler, trace_id: nil, parent_context: OpenTelemetry::Context.current, links: nil, name: nil, kind: nil, attributes: nil)
sampler.should_sample?(
trace_id: trace_id || OpenTelemetry::Trace.generate_trace_id,
parent_context: parent_context,
Expand Down
4 changes: 0 additions & 4 deletions sdk_experimental/.rubocop.yml
Original file line number Diff line number Diff line change
Expand Up @@ -9,13 +9,9 @@ Metrics/PerceivedComplexity:
Metrics/CyclomaticComplexity:
Max: 20

Naming/MethodParameterName:
Enabled: false
Lint/AmbiguousOperatorPrecedence:
Enabled: false
Lint/DuplicateBranch:
Enabled: false
Naming/PredicateMethod:
Enabled: false
Style/NegatedIfElseCondition:
Enabled: false
Original file line number Diff line number Diff line change
Expand Up @@ -77,7 +77,7 @@ def parse_ot_vendor_tag(tracestate)
yield(p, r, rest)
end

def update_tracestate(tracestate, p, r, rest)
def update_tracestate(tracestate, p, r, rest) # rubocop:disable Naming/MethodParameterName
if p.nil? && r.nil? && rest.nil?
tracestate.delete('ot')
elsif p.nil? && r.nil?
Expand All @@ -97,7 +97,7 @@ def update_tracestate(tracestate, p, r, rest)
end
end

def invariant(p, r, sampled)
def invariant(p, r, sampled) # rubocop:disable Naming/MethodParameterName
((p <= r) == sampled) || (sampled && (p == 63))
end

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -17,13 +17,13 @@

describe '#should_sample?' do
it 'populates tracestate for a sampled root span' do
result = call_sampler(subject, trace_id: trace_id(1), parent_context: OpenTelemetry::Context::ROOT)
result = call_sampler?(subject, trace_id: trace_id(1), parent_context: OpenTelemetry::Context::ROOT)
_(result.tracestate['ot']).must_equal('p:1;r:62')
_(result).must_be :sampled?
end

it 'populates tracestate for an unsampled root span' do
result = call_sampler(subject, trace_id: trace_id(-1), parent_context: OpenTelemetry::Context::ROOT)
result = call_sampler?(subject, trace_id: trace_id(-1), parent_context: OpenTelemetry::Context::ROOT)
_(result.tracestate['ot']).must_equal('r:0')
_(result).wont_be :sampled?
end
Expand All @@ -32,38 +32,38 @@
tracestate = OpenTelemetry::Trace::Tracestate.from_hash({ 'foo' => 'bar' })
parent_span_context = OpenTelemetry::Trace::SpanContext.new(tracestate: tracestate)
parent_context = OpenTelemetry::Trace.context_with_span(OpenTelemetry::Trace::Span.new(span_context: parent_span_context))
result = call_sampler(subject, trace_id: trace_id(1), parent_context: parent_context)
result = call_sampler?(subject, trace_id: trace_id(1), parent_context: parent_context)
_(result.tracestate['foo']).must_equal('bar')
end

it 'populates tracestate with the parent r for a sampled child span' do
tid = trace_id(1)
ctx = parent_context(trace_id: tid, ot: 'p:1;r:1')
result = call_sampler(subject, trace_id: tid, parent_context: ctx)
result = call_sampler?(subject, trace_id: tid, parent_context: ctx)
_(result.tracestate['ot']).must_equal('p:1;r:1')
_(result).must_be :sampled?
end

it 'populates tracestate without p for an unsampled child span' do
tid = trace_id(-1)
ctx = parent_context(trace_id: tid, ot: 'p:0;r:0')
result = call_sampler(subject, trace_id: tid, parent_context: ctx)
result = call_sampler?(subject, trace_id: tid, parent_context: ctx)
_(result.tracestate['ot']).must_equal('r:0')
_(result).wont_be :sampled?
end

it 'generates a new r if r is missing in the parent tracestate' do
tid = trace_id(1)
ctx = parent_context(trace_id: tid, ot: 'p:1')
result = call_sampler(subject, trace_id: tid, parent_context: ctx)
result = call_sampler?(subject, trace_id: tid, parent_context: ctx)
_(result.tracestate['ot']).must_equal('p:1;r:62')
_(result).must_be :sampled?
end

it 'generates a new r if r is invalid in the parent tracestate' do
tid = trace_id(1)
ctx = parent_context(trace_id: tid, ot: 'p:1;r:63')
result = call_sampler(subject, trace_id: tid, parent_context: ctx)
result = call_sampler?(subject, trace_id: tid, parent_context: ctx)
_(result.tracestate['ot']).must_equal('p:1;r:62')
_(result).must_be :sampled?
end
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -17,36 +17,36 @@

describe '#should_sample?' do
it 'delegates to the root sampler for root spans' do
result = call_sampler(subject, parent_context: OpenTelemetry::Context::ROOT)
result = call_sampler?(subject, parent_context: OpenTelemetry::Context::ROOT)
_(result).must_be :sampled?
end

it 'does not modify valid tracestate' do
_(call_sampler(subject, parent_context: parent_context(ot: 'junk;p:1;r:0')).tracestate['ot']).must_equal('junk;p:1;r:0')
_(call_sampler?(subject, parent_context: parent_context(ot: 'junk;p:1;r:0')).tracestate['ot']).must_equal('junk;p:1;r:0')
end

it 'sanitizes input tracestate' do
_(call_sampler(subject, parent_context: parent_context(ot: 'junk;p:1;r:1')).tracestate['ot']).must_equal('r:1;junk')
_(call_sampler(subject, parent_context: parent_context(ot: 'p:64;r:1')).tracestate['ot']).must_equal('r:1')
_(call_sampler(subject, parent_context: parent_context(sampled: false, ot: 'p:2;r:1')).tracestate['ot']).must_equal('p:2;r:1')
_(call_sampler(subject, parent_context: parent_context(sampled: true, ot: 'p:2;r:1')).tracestate['ot']).must_equal('r:1')
_(call_sampler(subject, parent_context: parent_context(sampled: true, ot: 'p:63;r:1')).tracestate['ot']).must_equal('p:63;r:1')
_(call_sampler(subject, trace_id: trace_id(-1), parent_context: parent_context(ot: 'p:1;r:63')).tracestate['ot']).must_equal('r:0')
_(call_sampler(subject, trace_id: trace_id(-1), parent_context: parent_context(ot: 'p:1;r:63;junk')).tracestate['ot']).must_equal('r:0;junk')
_(call_sampler?(subject, parent_context: parent_context(ot: 'junk;p:1;r:1')).tracestate['ot']).must_equal('r:1;junk')
_(call_sampler?(subject, parent_context: parent_context(ot: 'p:64;r:1')).tracestate['ot']).must_equal('r:1')
_(call_sampler?(subject, parent_context: parent_context(sampled: false, ot: 'p:2;r:1')).tracestate['ot']).must_equal('p:2;r:1')
_(call_sampler?(subject, parent_context: parent_context(sampled: true, ot: 'p:2;r:1')).tracestate['ot']).must_equal('r:1')
_(call_sampler?(subject, parent_context: parent_context(sampled: true, ot: 'p:63;r:1')).tracestate['ot']).must_equal('p:63;r:1')
_(call_sampler?(subject, trace_id: trace_id(-1), parent_context: parent_context(ot: 'p:1;r:63')).tracestate['ot']).must_equal('r:0')
_(call_sampler?(subject, trace_id: trace_id(-1), parent_context: parent_context(ot: 'p:1;r:63;junk')).tracestate['ot']).must_equal('r:0;junk')
end

it 'sets r based on the trace_id if missing or invalid' do
_(call_sampler(subject, trace_id: trace_id(-1), parent_context: parent_context(sampled: true)).tracestate['ot']).must_equal('r:0')
_(call_sampler(subject, trace_id: trace_id(-1), parent_context: parent_context(sampled: false)).tracestate['ot']).must_equal('r:0')
_(call_sampler(subject, trace_id: trace_id(-1), parent_context: parent_context(ot: 'r:63', sampled: true)).tracestate['ot']).must_equal('r:0')
_(call_sampler(subject, trace_id: trace_id(-1), parent_context: parent_context(ot: 'r:63', sampled: false)).tracestate['ot']).must_equal('r:0')
_(call_sampler?(subject, trace_id: trace_id(-1), parent_context: parent_context(sampled: true)).tracestate['ot']).must_equal('r:0')
_(call_sampler?(subject, trace_id: trace_id(-1), parent_context: parent_context(sampled: false)).tracestate['ot']).must_equal('r:0')
_(call_sampler?(subject, trace_id: trace_id(-1), parent_context: parent_context(ot: 'r:63', sampled: true)).tracestate['ot']).must_equal('r:0')
_(call_sampler?(subject, trace_id: trace_id(-1), parent_context: parent_context(ot: 'r:63', sampled: false)).tracestate['ot']).must_equal('r:0')
end

it 'respects parent sampling decision' do
_(call_sampler(subject, parent_context: parent_context(sampled: true, ot: 'p:2;r:1'))).must_be :sampled?
_(call_sampler(subject, parent_context: parent_context(sampled: false, ot: 'p:2;r:1'))).wont_be :sampled?
_(call_sampler(subject, parent_context: parent_context(sampled: true, ot: 'p:1;r:2'))).must_be :sampled?
_(call_sampler(subject, parent_context: parent_context(sampled: false, ot: 'p:1;r:2'))).wont_be :sampled?
_(call_sampler?(subject, parent_context: parent_context(sampled: true, ot: 'p:2;r:1'))).must_be :sampled?
_(call_sampler?(subject, parent_context: parent_context(sampled: false, ot: 'p:2;r:1'))).wont_be :sampled?
_(call_sampler?(subject, parent_context: parent_context(sampled: true, ot: 'p:1;r:2'))).must_be :sampled?
_(call_sampler?(subject, parent_context: parent_context(sampled: false, ot: 'p:1;r:2'))).wont_be :sampled?
end
end
end
Loading
Loading