@@ -33,7 +33,7 @@ TracerContext::TracerContext(std::vector<std::unique_ptr<SpanProcessor>> &&proce
3333 sampler_ (std::move(sampler)),
3434 id_generator_(std::move(id_generator)),
3535 tracer_configurator_(std::move(tracer_configurator)),
36- num_processors_( 0 )
36+ multi_processor_( nullptr )
3737{
3838 if (processors.empty ())
3939 {
@@ -77,27 +77,28 @@ void TracerContext::AddProcessor(std::unique_ptr<SpanProcessor> processor) noexc
7777 return ;
7878 }
7979
80- if (num_processors_ == 0 )
80+ if (!processor_ )
8181 {
82- // this is the first processor to be added, maybe the MultiSpanProcessor is not needed
82+ // this is the first processor to be added
8383 processor_ = std::move (processor);
8484 }
85- else if (num_processors_ == 1 )
85+ else if (multi_processor_ == nullptr )
8686 {
87- // if there already is a processor, then make a new MultiSpanProcessor to handle both
87+ // if there already is a processor, but its not a MultiSpanProcessor. make a new MultiSpanProcessor
8888 std::unique_ptr<MultiSpanProcessor> multi_processor (new MultiSpanProcessor ({}));
8989 multi_processor->AddProcessor (std::move (processor_));
9090 multi_processor->AddProcessor (std::move (processor));
91+
92+ // duplicate the pointer before it gets type erased
93+ multi_processor_ = multi_processor.get ();
94+
9195 processor_ = std::move (multi_processor);
9296 }
93- else /* if (num_processors_ > 1 )*/
97+ else /* if (multi_processor_ != nullptr )*/
9498 {
9599 // already have a MultiSpanProcessor, add the processor to it
96- auto multi_processor = static_cast <MultiSpanProcessor *>(processor_.get ());
97- multi_processor->AddProcessor (std::move (processor));
100+ multi_processor_->AddProcessor (std::move (processor));
98101 }
99-
100- ++num_processors_;
101102}
102103
103104SpanProcessor &TracerContext::GetProcessor () const noexcept
0 commit comments