@@ -172,30 +172,23 @@ SegmentContextImpl::SegmentContextImpl(const std::string& service_name,
172172 service_(service_name),
173173 service_instance_(instance_name) {}
174174
175- CurrentSegmentSpanPtr SegmentContextImpl::createCurrentSegmentSpan (
175+ CurrentSegmentSpanPtr SegmentContextImpl::createExitSpan (
176176 CurrentSegmentSpanPtr parent_span) {
177- auto current_span =
178- std::make_shared<CurrentSegmentSpanImpl>(spans_.size (), *this );
179- if (parent_span != nullptr ) {
180- current_span->setParentSpanId (parent_span->spanId ());
181- current_span->setSpanType (SpanType::Exit);
182- } else {
183- current_span->setParentSpanId (-1 );
184- current_span->setSpanType (SpanType::Entry);
185- }
186- // It supports only HTTP request tracing.
187- current_span->setSpanLayer (SpanLayer::Http);
188- if (should_skip_analysis_) {
189- current_span->setSkipAnalysis ();
190- }
191-
192- spans_.push_back (current_span);
177+ auto current_span = createSpan ();
178+ current_span->setParentSpanId (parent_span->spanId ());
179+ current_span->setSpanType (SpanType::Exit);
193180 return current_span;
194181}
195182
196- CurrentSegmentSpanPtr SegmentContextImpl::createCurrentSegmentRootSpan () {
197- assert (spans_.empty ());
198- return createCurrentSegmentSpan (nullptr );
183+ CurrentSegmentSpanPtr SegmentContextImpl::createEntrySpan () {
184+ if (!spans_.empty ()) {
185+ return nullptr ;
186+ }
187+
188+ auto current_span = createSpan ();
189+ current_span->setParentSpanId (-1 );
190+ current_span->setSpanType (SpanType::Entry);
191+ return current_span;
199192}
200193
201194std::optional<std::string> SegmentContextImpl::createSW8HeaderValue (
@@ -215,8 +208,8 @@ std::optional<std::string> SegmentContextImpl::createSW8HeaderValue(
215208 return encodeSpan (target_span, target_address);
216209}
217210
218- std::string SegmentContextImpl::encodeSpan (CurrentSegmentSpanPtr parent_span,
219- const std::string_view target_address) {
211+ std::string SegmentContextImpl::encodeSpan (
212+ CurrentSegmentSpanPtr parent_span, const std::string_view target_address) {
220213 assert (parent_span);
221214 std::string header_value;
222215
@@ -236,6 +229,20 @@ std::string SegmentContextImpl::encodeSpan(CurrentSegmentSpanPtr parent_span,
236229 return header_value;
237230}
238231
232+ CurrentSegmentSpanPtr SegmentContextImpl::createSpan () {
233+ auto current_span =
234+ std::make_shared<CurrentSegmentSpanImpl>(spans_.size (), *this );
235+
236+ // It supports only HTTP request tracing.
237+ current_span->setSpanLayer (SpanLayer::Http);
238+ if (should_skip_analysis_) {
239+ current_span->setSkipAnalysis ();
240+ }
241+
242+ spans_.push_back (current_span);
243+ return current_span;
244+ }
245+
239246SegmentObject SegmentContextImpl::createSegmentObject () {
240247 SegmentObject obj;
241248 obj.set_traceid (trace_id_);
0 commit comments