From e20bb1d8b55b71d49772acb3458f5e256be64db8 Mon Sep 17 00:00:00 2001 From: Robb Kidd Date: Wed, 5 Jun 2024 16:34:21 -0400 Subject: [PATCH] spec the new new method Co-authored-by: Mike Goldsmith --- .../processor/baggage/baggage_span_processor.rb | 2 ++ .../processor/baggage/baggage_span_processor_test.rb | 8 ++++++++ 2 files changed, 10 insertions(+) diff --git a/processor/baggage/lib/opentelemetry/processor/baggage/baggage_span_processor.rb b/processor/baggage/lib/opentelemetry/processor/baggage/baggage_span_processor.rb index 1bf961dbf..58e857cef 100644 --- a/processor/baggage/lib/opentelemetry/processor/baggage/baggage_span_processor.rb +++ b/processor/baggage/lib/opentelemetry/processor/baggage/baggage_span_processor.rb @@ -53,6 +53,8 @@ class BaggageSpanProcessor < OpenTelemetry::SDK::Trace::SpanProcessor # @param [lambda] baggage_key_predicate A lambda that takes a baggage key and returns true if # the key should be added to the span as an attribute, false otherwise. def initialize(baggage_key_predicate) + raise ArgumentError, 'baggage_key_predicate must respond to :call (lambda/Proc)' unless baggage_key_predicate.respond_to?(:call) + @baggage_key_predicate = baggage_key_predicate super() end diff --git a/processor/baggage/test/opentelemetry/processor/baggage/baggage_span_processor_test.rb b/processor/baggage/test/opentelemetry/processor/baggage/baggage_span_processor_test.rb index 78dfd8674..73687f0e4 100644 --- a/processor/baggage/test/opentelemetry/processor/baggage/baggage_span_processor_test.rb +++ b/processor/baggage/test/opentelemetry/processor/baggage/baggage_span_processor_test.rb @@ -39,6 +39,14 @@ end end + describe '#new' do + it 'requires a callable baggage_key_predicate' do + _(-> { OpenTelemetry::Processor::Baggage::BaggageSpanProcessor.new }).must_raise(ArgumentError) + err = _(-> { OpenTelemetry::Processor::Baggage::BaggageSpanProcessor.new(:not_a_callable) }).must_raise(ArgumentError) + _(err.message).must_match(/must respond to :call/) + end + end + describe '#on_start' do describe 'with the ALLOW_ALL_BAGGAGE_KEYS predicate' do it 'adds current baggage keys/values as attributes when a span starts' do