@@ -352,9 +352,10 @@ class LightStepDriverTest : public Test {
352352 }
353353
354354 const std::string operation_name_{" test" };
355- const Http::TestHeaderMapImpl request_headers_{
355+ Http::TestHeaderMapImpl request_headers_{
356356 {" :path" , " /" }, {" :method" , " GET" }, {" x-request-id" , " foo" }};
357357 const Http::TestHeaderMapImpl response_headers_{{" :status" , " 500" }};
358+ SystemTime start_time_;
358359
359360 std::unique_ptr<LightStepDriver> driver_;
360361 NiceMock<Event::MockTimer>* timer_;
@@ -447,7 +448,7 @@ TEST(HttpTracerImplTest, BasicFunctionalityNullSpan) {
447448
448449 HttpTracerImpl tracer (std::move (driver_ptr), local_info);
449450
450- EXPECT_CALL (*driver, startSpan_ (operation_name, time)).WillOnce (Return (nullptr ));
451+ EXPECT_CALL (*driver, startSpan_ (_, operation_name, time)).WillOnce (Return (nullptr ));
451452
452453 tracer.startSpan (config, request_headers, request_info);
453454}
@@ -471,7 +472,7 @@ TEST(HttpTracerImplTest, BasicFunctionalityNodeSet) {
471472 HttpTracerImpl tracer (std::move (driver_ptr), local_info);
472473
473474 NiceMock<MockSpan>* span = new NiceMock<MockSpan>();
474- EXPECT_CALL (*driver, startSpan_ (operation_name, time)).WillOnce (Return (span));
475+ EXPECT_CALL (*driver, startSpan_ (_, operation_name, time)).WillOnce (Return (span));
475476
476477 EXPECT_CALL (*span, setTag (_, _)).Times (testing::AnyNumber ());
477478 EXPECT_CALL (*span, setTag (" node_id" , " node_name" ));
@@ -499,16 +500,17 @@ TEST_F(LightStepDriverTest, FlushSeveralSpans) {
499500 return &request;
500501 }));
501502
502- SystemTime start_time;
503503 EXPECT_CALL (runtime_.snapshot_ , getInteger (" tracing.lightstep.min_flush_spans" , 5 ))
504504 .Times (2 )
505505 .WillRepeatedly (Return (2 ));
506506 EXPECT_CALL (runtime_.snapshot_ , getInteger (" tracing.lightstep.request_timeout" , 5000U ))
507507 .WillOnce (Return (5000U ));
508508
509- SpanPtr first_span = driver_->startSpan (operation_name_, start_time);
509+ Http::TestHeaderMapImpl headers;
510+ SpanPtr first_span = driver_->startSpan (headers, operation_name_, start_time_);
510511 first_span->finishSpan ();
511- SpanPtr second_span = driver_->startSpan (operation_name_, start_time);
512+
513+ SpanPtr second_span = driver_->startSpan (headers, operation_name_, start_time_);
512514 second_span->finishSpan ();
513515
514516 Http::MessagePtr msg (new Http::ResponseMessageImpl (
@@ -539,11 +541,10 @@ TEST_F(LightStepDriverTest, FlushSpansTimer) {
539541 const Optional<std::chrono::milliseconds> timeout (std::chrono::seconds (5 ));
540542 EXPECT_CALL (cm_.async_client_ , send_ (_, _, timeout));
541543
542- SystemTime start_time;
543544 EXPECT_CALL (runtime_.snapshot_ , getInteger (" tracing.lightstep.min_flush_spans" , 5 ))
544545 .WillOnce (Return (5 ));
545546
546- SpanPtr span = driver_->startSpan (operation_name_, start_time );
547+ SpanPtr span = driver_->startSpan (request_headers_, operation_name_, start_time_ );
547548 span->finishSpan ();
548549
549550 // Timer should be re-enabled.
@@ -579,15 +580,13 @@ TEST_F(LightStepDriverTest, FlushOneSpanGrpcFailure) {
579580
580581 return &request;
581582 }));
582-
583- SystemTime start_time;
584-
585583 EXPECT_CALL (runtime_.snapshot_ , getInteger (" tracing.lightstep.min_flush_spans" , 5 ))
586584 .WillOnce (Return (1 ));
587585 EXPECT_CALL (runtime_.snapshot_ , getInteger (" tracing.lightstep.request_timeout" , 5000U ))
588586 .WillOnce (Return (5000U ));
589587
590- SpanPtr span = driver_->startSpan (operation_name_, start_time);
588+ Http::TestHeaderMapImpl headers;
589+ SpanPtr span = driver_->startSpan (headers, operation_name_, start_time_);
591590 span->finishSpan ();
592591
593592 Http::MessagePtr msg (new Http::ResponseMessageImpl (
@@ -605,4 +604,32 @@ TEST_F(LightStepDriverTest, FlushOneSpanGrpcFailure) {
605604 EXPECT_EQ (1U , stats_.counter (" tracing.lightstep.spans_sent" ).value ());
606605}
607606
607+ TEST_F (LightStepDriverTest, SerializeAndDeserializeContext) {
608+ setupValidDriver ();
609+
610+ // Supply bogus context, that will be simply ignored.
611+ const std::string invalid_context = " not valid context" ;
612+ request_headers_.insertOtSpanContext ().value (invalid_context);
613+ driver_->startSpan (request_headers_, operation_name_, start_time_);
614+
615+ std::string injected_ctx = request_headers_.OtSpanContext ()->value ().c_str ();
616+ EXPECT_FALSE (injected_ctx.empty ());
617+
618+ // Supply empty context.
619+ request_headers_.removeOtSpanContext ();
620+ SpanPtr span = driver_->startSpan (request_headers_, operation_name_, start_time_);
621+
622+ injected_ctx = request_headers_.OtSpanContext ()->value ().c_str ();
623+ EXPECT_FALSE (injected_ctx.empty ());
624+
625+ // Context can be parsed fine.
626+ lightstep::envoy::CarrierStruct ctx;
627+ ctx.ParseFromString (injected_ctx);
628+
629+ // Supply parent context, request_headers has properly populated x-ot-span-context.
630+ SpanPtr span_with_parent = driver_->startSpan (request_headers_, operation_name_, start_time_);
631+ injected_ctx = request_headers_.OtSpanContext ()->value ().c_str ();
632+ EXPECT_FALSE (injected_ctx.empty ());
633+ }
634+
608635} // Tracing
0 commit comments