diff --git a/source/tracing_context_impl.cc b/source/tracing_context_impl.cc index 918a5be..6ebab32 100644 --- a/source/tracing_context_impl.cc +++ b/source/tracing_context_impl.cc @@ -138,7 +138,8 @@ TracingContextImpl::TracingContextImpl( SpanContextExtensionPtr parent_ext_span_context, RandomGenerator& random) : parent_span_context_(std::move(parent_span_context)), parent_ext_span_context_(std::move(parent_ext_span_context)) { - segment_store_.set_traceid(random.uuid()); + segment_store_.set_traceid( + parent_span_context_ ? parent_span_context_->traceId() : random.uuid()); segment_store_.set_tracesegmentid(random.uuid()); segment_store_.set_service(service_name); segment_store_.set_serviceinstance(instance_name); diff --git a/test/tracing_context_test.cc b/test/tracing_context_test.cc index bcd63c3..eaadfa5 100644 --- a/test/tracing_context_test.cc +++ b/test/tracing_context_test.cc @@ -330,7 +330,7 @@ TEST_F(TracingContextTest, SW8CreateTest) { span2->endSpan(); std::string expect_sw8( - "1-dXVpZA==-dXVpZA==-1-bWVzaA==-c2VydmljZV8w-c2FtcGxlMQ==-" + "1-MQ==-dXVpZA==-1-bWVzaA==-c2VydmljZV8w-c2FtcGxlMQ==-" "MTAuMC4wLjE6NDQz"); EXPECT_EQ(expect_sw8, *sc.createSW8HeaderValue(target_address)); @@ -388,7 +388,7 @@ TEST_F(TracingContextTest, TraceLogTest) { TracingContextImpl sc(config_.service_name(), config_.instance_name(), span_ctx_, span_ext_ctx_, random_); EXPECT_EQ( - "test\", \"SW_CTX\": [\"mesh\",\"service_0\",\"uuid\",\"uuid\",\"-1\"]}", + "test\", \"SW_CTX\": [\"mesh\",\"service_0\",\"1\",\"uuid\",\"-1\"]}", sc.logMessage("test")); }