diff --git a/changelogs/1.23.0.yaml b/changelogs/1.23.0.yaml index 5760af0887e95..f25ff820f9593 100644 --- a/changelogs/1.23.0.yaml +++ b/changelogs/1.23.0.yaml @@ -33,6 +33,9 @@ minor_behavior_changes: change: | export symbols of LuaJit by default on Linux. This is useful in cases where you have a lua script that loads shared object libraries, such as those installed via luarocks. +- area: skywalking + change: | + use upstream host address as ``addressUsedAtClient`` in propagation header. bug_fixes: diff --git a/envoy/tracing/trace_driver.h b/envoy/tracing/trace_driver.h index e2a9de2347fe6..60557ef41f678 100644 --- a/envoy/tracing/trace_driver.h +++ b/envoy/tracing/trace_driver.h @@ -50,8 +50,10 @@ class Span { * Mutate the provided headers with the context necessary to propagate this * (implementation-specific) trace. * @param request_headers the headers to which propagation context will be added + * @param upstream connecting host description */ - virtual void injectContext(TraceContext& trace_conext) PURE; + virtual void injectContext(TraceContext& trace_conext, + const Upstream::HostDescriptionConstSharedPtr& upstream) PURE; /** * Create and start a child Span, with this Span as its parent in the trace. diff --git a/source/common/grpc/async_client_impl.cc b/source/common/grpc/async_client_impl.cc index f1da95844a407..2bbabb86fa91e 100644 --- a/source/common/grpc/async_client_impl.cc +++ b/source/common/grpc/async_client_impl.cc @@ -254,7 +254,7 @@ void AsyncRequestImpl::cancel() { } void AsyncRequestImpl::onCreateInitialMetadata(Http::RequestHeaderMap& metadata) { - current_span_->injectContext(metadata); + current_span_->injectContext(metadata, nullptr); callbacks_.onCreateInitialMetadata(metadata); } diff --git a/source/common/grpc/google_async_client_impl.cc b/source/common/grpc/google_async_client_impl.cc index da51a25baeeb9..1a59b220b0b33 100644 --- a/source/common/grpc/google_async_client_impl.cc +++ b/source/common/grpc/google_async_client_impl.cc @@ -455,7 +455,7 @@ void GoogleAsyncRequestImpl::cancel() { } void GoogleAsyncRequestImpl::onCreateInitialMetadata(Http::RequestHeaderMap& metadata) { - current_span_->injectContext(metadata); + current_span_->injectContext(metadata, nullptr); callbacks_.onCreateInitialMetadata(metadata); } diff --git a/source/common/http/async_client_impl.cc b/source/common/http/async_client_impl.cc index 1352861406a77..ab2f9941c1edd 100644 --- a/source/common/http/async_client_impl.cc +++ b/source/common/http/async_client_impl.cc @@ -270,7 +270,7 @@ AsyncRequestImpl::AsyncRequestImpl(RequestMessagePtr&& request, AsyncClientImpl& } void AsyncRequestImpl::initialize() { - child_span_->injectContext(request_->headers()); + child_span_->injectContext(request_->headers(), nullptr); sendHeaders(request_->headers(), request_->body().length() == 0); if (request_->body().length() != 0) { // It's possible this will be a no-op due to a local response synchronously generated in diff --git a/source/common/router/upstream_request.cc b/source/common/router/upstream_request.cc index c05270aaad146..e8a8d82de775f 100644 --- a/source/common/router/upstream_request.cc +++ b/source/common/router/upstream_request.cc @@ -488,12 +488,12 @@ void UpstreamRequest::onPoolReady( } if (span_ != nullptr) { - span_->injectContext(*parent_.downstreamHeaders()); + span_->injectContext(*parent_.downstreamHeaders(), host); } else { // No independent child span for current upstream request then inject the parent span's tracing // context into the request headers. // The injectContext() of the parent span may be called repeatedly when the request is retried. - parent_.callbacks()->activeSpan().injectContext(*parent_.downstreamHeaders()); + parent_.callbacks()->activeSpan().injectContext(*parent_.downstreamHeaders(), host); } upstreamTiming().onFirstUpstreamTxByteSent(parent_.callbacks()->dispatcher().timeSource()); diff --git a/source/common/tracing/null_span_impl.h b/source/common/tracing/null_span_impl.h index 1377000632349..19f6cb1e3e676 100644 --- a/source/common/tracing/null_span_impl.h +++ b/source/common/tracing/null_span_impl.h @@ -22,7 +22,8 @@ class NullSpan : public Span { void setTag(absl::string_view, absl::string_view) override {} void log(SystemTime, const std::string&) override {} void finishSpan() override {} - void injectContext(Tracing::TraceContext&) override {} + void injectContext(Tracing::TraceContext&, + const Upstream::HostDescriptionConstSharedPtr&) override {} void setBaggage(absl::string_view, absl::string_view) override {} std::string getBaggage(absl::string_view) override { return EMPTY_STRING; } std::string getTraceIdAsHex() const override { return EMPTY_STRING; } diff --git a/source/extensions/tracers/common/ot/opentracing_driver_impl.cc b/source/extensions/tracers/common/ot/opentracing_driver_impl.cc index e5c37a4fd060c..4f0399f3ddf1e 100644 --- a/source/extensions/tracers/common/ot/opentracing_driver_impl.cc +++ b/source/extensions/tracers/common/ot/opentracing_driver_impl.cc @@ -107,7 +107,8 @@ std::string OpenTracingSpan::getBaggage(absl::string_view key) { return span_->BaggageItem({key.data(), key.length()}); } -void OpenTracingSpan::injectContext(Tracing::TraceContext& trace_context) { +void OpenTracingSpan::injectContext(Tracing::TraceContext& trace_context, + const Upstream::HostDescriptionConstSharedPtr&) { if (driver_.propagationMode() == OpenTracingDriver::PropagationMode::SingleHeader) { // Inject the span context using Envoy's single-header format. std::ostringstream oss; diff --git a/source/extensions/tracers/common/ot/opentracing_driver_impl.h b/source/extensions/tracers/common/ot/opentracing_driver_impl.h index 6494b8b140f89..07982592e932f 100644 --- a/source/extensions/tracers/common/ot/opentracing_driver_impl.h +++ b/source/extensions/tracers/common/ot/opentracing_driver_impl.h @@ -37,7 +37,8 @@ class OpenTracingSpan : public Tracing::Span, Logger::Loggableaddress()->asString() + : std::string(trace_context.authority()); // TODO(wbpcode): Due to https://github.com/SkyAPM/cpp2sky/issues/83 in cpp2sky, it is necessary // to ensure that there is '\0' at the end of the string_view parameter to ensure that the // corresponding trace header is generated correctly. For this reason, we cannot directly use host // as argument. We need create a copy of std::string based on host and std::string will // automatically add '\0' to the end of the string content. - auto sw8_header = tracing_context_->createSW8HeaderValue(std::string(trace_context.authority())); + auto sw8_header = tracing_context_->createSW8HeaderValue(remote_address); if (sw8_header.has_value()) { trace_context.setByReferenceKey(skywalkingPropagationHeaderKey(), sw8_header.value()); } diff --git a/source/extensions/tracers/skywalking/tracer.h b/source/extensions/tracers/skywalking/tracer.h index 07224b0376540..1d3e2910f6066 100644 --- a/source/extensions/tracers/skywalking/tracer.h +++ b/source/extensions/tracers/skywalking/tracer.h @@ -68,7 +68,8 @@ class Span : public Tracing::Span { void setTag(absl::string_view name, absl::string_view value) override; void log(SystemTime timestamp, const std::string& event) override; void finishSpan() override; - void injectContext(Tracing::TraceContext& trace_context) override; + void injectContext(Tracing::TraceContext& trace_context, + const Upstream::HostDescriptionConstSharedPtr& upstream) override; Tracing::SpanPtr spawnChild(const Tracing::Config& config, const std::string& name, SystemTime start_time) override; void setSampled(bool do_sample) override; diff --git a/source/extensions/tracers/xray/tracer.cc b/source/extensions/tracers/xray/tracer.cc index 89ea1a46865f0..30608ff6b596d 100644 --- a/source/extensions/tracers/xray/tracer.cc +++ b/source/extensions/tracers/xray/tracer.cc @@ -101,7 +101,8 @@ void Span::finishSpan() { broker_.send(json); } // namespace XRay -void Span::injectContext(Tracing::TraceContext& trace_context) { +void Span::injectContext(Tracing::TraceContext& trace_context, + const Upstream::HostDescriptionConstSharedPtr&) { const std::string xray_header_value = fmt::format("Root={};Parent={};Sampled={}", traceId(), id(), sampled() ? "1" : "0"); trace_context.setByReferenceKey(XRayTraceHeader, xray_header_value); diff --git a/source/extensions/tracers/xray/tracer.h b/source/extensions/tracers/xray/tracer.h index 382e79c683cc3..d6c14fadd6767 100644 --- a/source/extensions/tracers/xray/tracer.h +++ b/source/extensions/tracers/xray/tracer.h @@ -165,7 +165,8 @@ class Span : public Tracing::Span, Logger::Loggable { /** * Adds X-Ray trace header to the set of outgoing headers. */ - void injectContext(Tracing::TraceContext& trace_context) override; + void injectContext(Tracing::TraceContext& trace_context, + const Upstream::HostDescriptionConstSharedPtr&) override; /** * Gets the start time of this Span. diff --git a/source/extensions/tracers/zipkin/zipkin_tracer_impl.cc b/source/extensions/tracers/zipkin/zipkin_tracer_impl.cc index 33e0327b26fc0..c8eecec21d273 100644 --- a/source/extensions/tracers/zipkin/zipkin_tracer_impl.cc +++ b/source/extensions/tracers/zipkin/zipkin_tracer_impl.cc @@ -39,7 +39,8 @@ void ZipkinSpan::log(SystemTime timestamp, const std::string& event) { void ZipkinSpan::setBaggage(absl::string_view, absl::string_view) {} std::string ZipkinSpan::getBaggage(absl::string_view) { return EMPTY_STRING; } -void ZipkinSpan::injectContext(Tracing::TraceContext& trace_context) { +void ZipkinSpan::injectContext(Tracing::TraceContext& trace_context, + const Upstream::HostDescriptionConstSharedPtr&) { // Set the trace-id and span-id headers properly, based on the newly-created span structure. trace_context.setByReferenceKey(ZipkinCoreConstants::get().X_B3_TRACE_ID, span_.traceIdAsHexString()); diff --git a/source/extensions/tracers/zipkin/zipkin_tracer_impl.h b/source/extensions/tracers/zipkin/zipkin_tracer_impl.h index a416c3268a4b3..1f2aad8d3497f 100644 --- a/source/extensions/tracers/zipkin/zipkin_tracer_impl.h +++ b/source/extensions/tracers/zipkin/zipkin_tracer_impl.h @@ -72,7 +72,8 @@ class ZipkinSpan : public Tracing::Span { void log(SystemTime timestamp, const std::string& event) override; - void injectContext(Tracing::TraceContext& trace_context) override; + void injectContext(Tracing::TraceContext& trace_context, + const Upstream::HostDescriptionConstSharedPtr&) override; Tracing::SpanPtr spawnChild(const Tracing::Config&, const std::string& name, SystemTime start_time) override; diff --git a/test/common/grpc/async_client_impl_test.cc b/test/common/grpc/async_client_impl_test.cc index c6f2b34006683..44f50532a3d9a 100644 --- a/test/common/grpc/async_client_impl_test.cc +++ b/test/common/grpc/async_client_impl_test.cc @@ -184,7 +184,7 @@ TEST_F(EnvoyAsyncClientImplTest, RequestHttpStartFail) { EXPECT_CALL(*child_span, setTag(Eq(Tracing::Tags::get().GrpcStatusCode), Eq("14"))); EXPECT_CALL(*child_span, setTag(Eq(Tracing::Tags::get().Error), Eq(Tracing::Tags::get().True))); EXPECT_CALL(*child_span, finishSpan()); - EXPECT_CALL(*child_span, injectContext(_)).Times(0); + EXPECT_CALL(*child_span, injectContext(_, _)).Times(0); auto* grpc_request = grpc_client_->send(*method_descriptor_, request_msg, grpc_callbacks, active_span, Http::AsyncClient::RequestOptions()); @@ -249,7 +249,7 @@ TEST_F(EnvoyAsyncClientImplTest, RequestHttpSendHeadersFail) { setTag(Eq(Tracing::Tags::get().Component), Eq(Tracing::Tags::get().Proxy))); EXPECT_CALL(*child_span, setTag(Eq(Tracing::Tags::get().UpstreamCluster), Eq("test_cluster"))); EXPECT_CALL(*child_span, setTag(Eq(Tracing::Tags::get().UpstreamAddress), Eq("test_cluster"))); - EXPECT_CALL(*child_span, injectContext(_)); + EXPECT_CALL(*child_span, injectContext(_, _)); EXPECT_CALL(*child_span, setTag(Eq(Tracing::Tags::get().GrpcStatusCode), Eq("13"))); EXPECT_CALL(*child_span, setTag(Eq(Tracing::Tags::get().Error), Eq(Tracing::Tags::get().True))); EXPECT_CALL(*child_span, finishSpan()); diff --git a/test/common/grpc/google_async_client_impl_test.cc b/test/common/grpc/google_async_client_impl_test.cc index 70fa4bf3e6f59..447c834a27198 100644 --- a/test/common/grpc/google_async_client_impl_test.cc +++ b/test/common/grpc/google_async_client_impl_test.cc @@ -169,7 +169,7 @@ TEST_F(EnvoyGoogleAsyncClientImplTest, RequestHttpStartFail) { EXPECT_CALL(*child_span, setTag(Eq(Tracing::Tags::get().GrpcStatusCode), Eq("14"))); EXPECT_CALL(*child_span, setTag(Eq(Tracing::Tags::get().Error), Eq(Tracing::Tags::get().True))); EXPECT_CALL(*child_span, finishSpan()); - EXPECT_CALL(*child_span, injectContext(_)); + EXPECT_CALL(*child_span, injectContext(_, _)); auto* grpc_request = grpc_client_->send(*method_descriptor_, request_msg, grpc_callbacks, active_span, Http::AsyncClient::RequestOptions()); diff --git a/test/common/grpc/grpc_client_integration_test_harness.h b/test/common/grpc/grpc_client_integration_test_harness.h index f03caff22fecc..a0947cf4c2a80 100644 --- a/test/common/grpc/grpc_client_integration_test_harness.h +++ b/test/common/grpc/grpc_client_integration_test_harness.h @@ -385,7 +385,7 @@ class GrpcClientIntegrationTest : public GrpcClientIntegrationParamTest { .Times(AtMost(1)); EXPECT_CALL(*request->child_span_, setTag(Eq(Tracing::Tags::get().Component), Eq(Tracing::Tags::get().Proxy))); - EXPECT_CALL(*request->child_span_, injectContext(_)); + EXPECT_CALL(*request->child_span_, injectContext(_, _)); request->grpc_request_ = grpc_client_->send(*method_descriptor_, request_msg, *request, active_span, Http::AsyncClient::RequestOptions()); diff --git a/test/common/http/async_client_impl_test.cc b/test/common/http/async_client_impl_test.cc index 34a2ba60fda3c..5dbb64ac91643 100644 --- a/test/common/http/async_client_impl_test.cc +++ b/test/common/http/async_client_impl_test.cc @@ -227,7 +227,7 @@ TEST_F(AsyncClientImplTracingTest, Basic) { AsyncClient::RequestOptions options = AsyncClient::RequestOptions().setParentSpan(parent_span_); EXPECT_CALL(*child_span, setSampled(true)); - EXPECT_CALL(*child_span, injectContext(_)); + EXPECT_CALL(*child_span, injectContext(_, _)); auto* request = client_.send(std::move(message_), callbacks_, options); EXPECT_NE(request, nullptr); @@ -281,7 +281,7 @@ TEST_F(AsyncClientImplTracingTest, BasicNamedChildSpan) { .setChildSpanName(child_span_name_) .setSampled(false); EXPECT_CALL(*child_span, setSampled(false)); - EXPECT_CALL(*child_span, injectContext(_)); + EXPECT_CALL(*child_span, injectContext(_, _)); auto* request = client_.send(std::move(message_), callbacks_, options); EXPECT_NE(request, nullptr); @@ -333,7 +333,7 @@ TEST_F(AsyncClientImplTracingTest, BasicNamedChildSpanKeepParentSampling) { .setChildSpanName(child_span_name_) .setSampled(absl::nullopt); EXPECT_CALL(*child_span, setSampled(_)).Times(0); - EXPECT_CALL(*child_span, injectContext(_)); + EXPECT_CALL(*child_span, injectContext(_, _)); auto* request = client_.send(std::move(message_), callbacks_, options); EXPECT_NE(request, nullptr); @@ -1248,7 +1248,7 @@ TEST_F(AsyncClientImplTracingTest, CancelRequest) { AsyncClient::RequestOptions options = AsyncClient::RequestOptions().setParentSpan(parent_span_); EXPECT_CALL(*child_span, setSampled(true)); - EXPECT_CALL(*child_span, injectContext(_)); + EXPECT_CALL(*child_span, injectContext(_, _)); EXPECT_CALL(callbacks_, onBeforeFinalizeUpstreamSpan(_, _)) .WillOnce(Invoke([](Tracing::Span& span, const Http::ResponseHeaderMap* response_headers) { span.setTag("onBeforeFinalizeUpstreamSpan", "called"); @@ -1336,7 +1336,7 @@ TEST_F(AsyncClientImplTracingTest, DestroyWithActiveRequest) { AsyncClient::RequestOptions options = AsyncClient::RequestOptions().setParentSpan(parent_span_); EXPECT_CALL(*child_span, setSampled(true)); - EXPECT_CALL(*child_span, injectContext(_)); + EXPECT_CALL(*child_span, injectContext(_, _)); auto* request = client_.send(std::move(message_), callbacks_, options); EXPECT_NE(request, nullptr); @@ -1537,7 +1537,7 @@ TEST_F(AsyncClientImplTracingTest, RequestTimeout) { .setParentSpan(parent_span_) .setTimeout(std::chrono::milliseconds(40)); EXPECT_CALL(*child_span, setSampled(true)); - EXPECT_CALL(*child_span, injectContext(_)); + EXPECT_CALL(*child_span, injectContext(_, _)); auto* request = client_.send(std::move(message_), callbacks_, options); EXPECT_NE(request, nullptr); diff --git a/test/common/router/router_2_test.cc b/test/common/router/router_2_test.cc index 8c615a7549fe9..5d45a0dc3c019 100644 --- a/test/common/router/router_2_test.cc +++ b/test/common/router/router_2_test.cc @@ -309,7 +309,7 @@ TEST_F(RouterTestChildSpan, BasicFlow) { const Http::ConnectionPool::Instance::StreamOptions&) -> Http::ConnectionPool::Cancellable* { response_decoder = &decoder; - EXPECT_CALL(*child_span, injectContext(_)); + EXPECT_CALL(*child_span, injectContext(_, _)); callbacks.onPoolReady(encoder, cm_.thread_local_cluster_.conn_pool_.host_, upstream_stream_info_, Http::Protocol::Http10); return nullptr; @@ -358,7 +358,7 @@ TEST_F(RouterTestChildSpan, ResetFlow) { const Http::ConnectionPool::Instance::StreamOptions&) -> Http::ConnectionPool::Cancellable* { response_decoder = &decoder; - EXPECT_CALL(*child_span, injectContext(_)); + EXPECT_CALL(*child_span, injectContext(_, _)); callbacks.onPoolReady(encoder, cm_.thread_local_cluster_.conn_pool_.host_, upstream_stream_info_, Http::Protocol::Http10); return nullptr; @@ -411,7 +411,7 @@ TEST_F(RouterTestChildSpan, CancelFlow) { .WillOnce(Invoke([&](Http::StreamDecoder&, Http::ConnectionPool::Callbacks& callbacks, const Http::ConnectionPool::Instance::StreamOptions&) -> Http::ConnectionPool::Cancellable* { - EXPECT_CALL(*child_span, injectContext(_)); + EXPECT_CALL(*child_span, injectContext(_, _)); callbacks.onPoolReady(encoder, cm_.thread_local_cluster_.conn_pool_.host_, upstream_stream_info_, Http::Protocol::Http10); return nullptr; @@ -458,7 +458,7 @@ TEST_F(RouterTestChildSpan, ResetRetryFlow) { const Http::ConnectionPool::Instance::StreamOptions&) -> Http::ConnectionPool::Cancellable* { response_decoder = &decoder; - EXPECT_CALL(*child_span_1, injectContext(_)); + EXPECT_CALL(*child_span_1, injectContext(_, _)); callbacks.onPoolReady(encoder1, cm_.thread_local_cluster_.conn_pool_.host_, upstream_stream_info_, Http::Protocol::Http10); return nullptr; @@ -503,7 +503,7 @@ TEST_F(RouterTestChildSpan, ResetRetryFlow) { const Http::ConnectionPool::Instance::StreamOptions&) -> Http::ConnectionPool::Cancellable* { response_decoder = &decoder; - EXPECT_CALL(*child_span_2, injectContext(_)); + EXPECT_CALL(*child_span_2, injectContext(_, _)); EXPECT_CALL(*router_.retry_state_, onHostAttempted(_)); callbacks.onPoolReady(encoder2, cm_.thread_local_cluster_.conn_pool_.host_, upstream_stream_info_, Http::Protocol::Http10); @@ -556,7 +556,7 @@ TEST_F(RouterTestNoChildSpan, BasicFlow) { const Http::ConnectionPool::Instance::StreamOptions&) -> Http::ConnectionPool::Cancellable* { response_decoder = &decoder; - EXPECT_CALL(callbacks_.active_span_, injectContext(_)); + EXPECT_CALL(callbacks_.active_span_, injectContext(_, _)); callbacks.onPoolReady(encoder, cm_.thread_local_cluster_.conn_pool_.host_, upstream_stream_info_, Http::Protocol::Http10); return nullptr; diff --git a/test/common/router/router_test.cc b/test/common/router/router_test.cc index 6ccd08fabffb3..582488f11b921 100644 --- a/test/common/router/router_test.cc +++ b/test/common/router/router_test.cc @@ -412,6 +412,7 @@ TEST_F(RouterTest, Http1Upstream) { Http::TestRequestHeaderMapImpl headers; HttpTestUtility::addDefaultHeaders(headers); EXPECT_CALL(callbacks_.route_->route_entry_, finalizeRequestHeaders(_, _, true)); + router_.decodeHeaders(headers, true); EXPECT_EQ("10", headers.get_("x-envoy-expected-rq-timeout-ms")); @@ -431,6 +432,7 @@ TEST_F(RouterTest, Http2Upstream) { Http::TestRequestHeaderMapImpl headers; HttpTestUtility::addDefaultHeaders(headers); + router_.decodeHeaders(headers, true); // When the router filter gets reset we should cancel the pool request. diff --git a/test/common/tracing/http_tracer_impl_test.cc b/test/common/tracing/http_tracer_impl_test.cc index 391ac29fb90b6..0c4af62ab2097 100644 --- a/test/common/tracing/http_tracer_impl_test.cc +++ b/test/common/tracing/http_tracer_impl_test.cc @@ -740,6 +740,8 @@ TEST(HttpNullTracerTest, BasicFunctionality) { Http::TestRequestHeaderMapImpl request_headers; Http::TestResponseHeaderMapImpl response_headers; Http::TestResponseTrailerMapImpl response_trailers; + Upstream::HostDescriptionConstSharedPtr host{ + new testing::NiceMock()}; SpanPtr span_ptr = null_tracer.startSpan(config, request_headers, stream_info, {Reason::Sampling, true}); @@ -750,7 +752,7 @@ TEST(HttpNullTracerTest, BasicFunctionality) { span_ptr->setBaggage("key", "value"); ASSERT_EQ("", span_ptr->getBaggage("baggage_key")); ASSERT_EQ(span_ptr->getTraceIdAsHex(), ""); - span_ptr->injectContext(request_headers); + span_ptr->injectContext(request_headers, host); span_ptr->log(SystemTime(), "fake_event"); EXPECT_NE(nullptr, span_ptr->spawnChild(config, "foo", SystemTime())); diff --git a/test/extensions/tracers/common/ot/opentracing_driver_impl_test.cc b/test/extensions/tracers/common/ot/opentracing_driver_impl_test.cc index f0cda348224e7..2e4b3f0fc832f 100644 --- a/test/extensions/tracers/common/ot/opentracing_driver_impl_test.cc +++ b/test/extensions/tracers/common/ot/opentracing_driver_impl_test.cc @@ -190,7 +190,7 @@ TEST_F(OpenTracingDriverTest, InjectFailure) { const auto span_context_injection_error_count = stats_.counter("tracing.opentracing.span_context_injection_error").value(); EXPECT_FALSE(request_headers_.has(Http::CustomHeaders::get().OtSpanContext)); - span->injectContext(request_headers_); + span->injectContext(request_headers_, nullptr); EXPECT_EQ(span_context_injection_error_count + 1, stats_.counter("tracing.opentracing.span_context_injection_error").value()); @@ -204,7 +204,7 @@ TEST_F(OpenTracingDriverTest, ExtractWithUnindexedHeader) { Tracing::SpanPtr first_span = driver_->startSpan(config_, request_headers_, operation_name_, start_time_, {Tracing::Reason::Sampling, true}); - first_span->injectContext(request_headers_); + first_span->injectContext(request_headers_, nullptr); Tracing::SpanPtr second_span = driver_->startSpan(config_, request_headers_, operation_name_, start_time_, {Tracing::Reason::Sampling, true}); diff --git a/test/extensions/tracers/lightstep/lightstep_tracer_impl_test.cc b/test/extensions/tracers/lightstep/lightstep_tracer_impl_test.cc index 162e8534be470..226ee65b05a26 100644 --- a/test/extensions/tracers/lightstep/lightstep_tracer_impl_test.cc +++ b/test/extensions/tracers/lightstep/lightstep_tracer_impl_test.cc @@ -626,7 +626,7 @@ TEST_F(LightStepDriverTest, SerializeAndDeserializeContext) { start_time_, {Tracing::Reason::Sampling, true}); EXPECT_FALSE(request_headers_.has(Http::CustomHeaders::get().OtSpanContext)); - span->injectContext(request_headers_); + span->injectContext(request_headers_, nullptr); injected_ctx = std::string(request_headers_.get_(Http::CustomHeaders::get().OtSpanContext)); EXPECT_FALSE(injected_ctx.empty()); @@ -641,7 +641,7 @@ TEST_F(LightStepDriverTest, SerializeAndDeserializeContext) { Tracing::SpanPtr span_with_parent = driver_->startSpan( config_, request_headers_, operation_name_, start_time_, {Tracing::Reason::Sampling, true}); request_headers_.remove(Http::CustomHeaders::get().OtSpanContext); - span_with_parent->injectContext(request_headers_); + span_with_parent->injectContext(request_headers_, nullptr); injected_ctx = std::string(request_headers_.get_(Http::CustomHeaders::get().OtSpanContext)); EXPECT_FALSE(injected_ctx.empty()); } @@ -677,7 +677,7 @@ TEST_F(LightStepDriverTest, MultiplePropagationModes) { start_time_, {Tracing::Reason::Sampling, true}); EXPECT_FALSE(request_headers_.has(Http::CustomHeaders::get().OtSpanContext)); - span->injectContext(request_headers_); + span->injectContext(request_headers_, nullptr); EXPECT_TRUE(request_headers_.has(Http::CustomHeaders::get().OtSpanContext)); EXPECT_TRUE(request_headers_.has("ot-tracer-traceid")); EXPECT_TRUE(request_headers_.has("x-b3-traceid")); @@ -689,7 +689,7 @@ TEST_F(LightStepDriverTest, SpawnChild) { Tracing::SpanPtr parent = driver_->startSpan(config_, request_headers_, operation_name_, start_time_, {Tracing::Reason::Sampling, true}); - parent->injectContext(request_headers_); + parent->injectContext(request_headers_, nullptr); Tracing::SpanPtr childViaHeaders = driver_->startSpan( config_, request_headers_, operation_name_, start_time_, {Tracing::Reason::Sampling, true}); @@ -698,8 +698,8 @@ TEST_F(LightStepDriverTest, SpawnChild) { Http::TestRequestHeaderMapImpl base1{{":path", "/"}, {":method", "GET"}, {"x-request-id", "foo"}}; Http::TestRequestHeaderMapImpl base2{{":path", "/"}, {":method", "GET"}, {"x-request-id", "foo"}}; - childViaHeaders->injectContext(base1); - childViaSpawn->injectContext(base2); + childViaHeaders->injectContext(base1, nullptr); + childViaSpawn->injectContext(base2, nullptr); std::string base1_context = Base64::decode(std::string(base1.get_(Http::CustomHeaders::get().OtSpanContext))); diff --git a/test/extensions/tracers/opencensus/tracer_test.cc b/test/extensions/tracers/opencensus/tracer_test.cc index b642bfac2d6ff..c0d61cac9f25c 100644 --- a/test/extensions/tracers/opencensus/tracer_test.cc +++ b/test/extensions/tracers/opencensus/tracer_test.cc @@ -217,7 +217,7 @@ void testIncomingHeaders( { Tracing::SpanPtr span = driver->startSpan(config, request_headers, operation_name, start_time, {Tracing::Reason::Sampling, false}); - span->injectContext(injected_headers); + span->injectContext(injected_headers, nullptr); span->finishSpan(); // Check contents via public API. diff --git a/test/extensions/tracers/skywalking/tracer_test.cc b/test/extensions/tracers/skywalking/tracer_test.cc index e505603fb6c55..6dcf918d67e5f 100644 --- a/test/extensions/tracers/skywalking/tracer_test.cc +++ b/test/extensions/tracers/skywalking/tracer_test.cc @@ -152,8 +152,37 @@ TEST_F(TracerTest, TracerTestCreateNewSpanWithNoPropagationHeaders) { EXPECT_NE(0, first_child_span->spanEntity()->endTime()); Http::TestRequestHeaderMapImpl first_child_headers{{":authority", "test.com"}}; + Upstream::HostDescriptionConstSharedPtr host{ + new testing::NiceMock()}; - first_child_span->injectContext(first_child_headers); + first_child_span->injectContext(first_child_headers, host); + auto sp = createSpanContext(first_child_headers.get_("sw8")); + EXPECT_EQ("CURR#SERVICE", sp->service()); + EXPECT_EQ("CURR#INSTANCE", sp->serviceInstance()); + EXPECT_EQ("TEST_OP", sp->endpoint()); + EXPECT_EQ("10.0.0.1:443", sp->targetAddress()); + } + + { + Envoy::Tracing::SpanPtr org_first_child_span = + org_span->spawnChild(mock_tracing_config_, "TestChild", mock_time_source_.systemTime()); + + Span* first_child_span = dynamic_cast(org_first_child_span.get()); + + EXPECT_TRUE(first_child_span->spanEntity()->spanType() == skywalking::v3::SpanType::Exit); + + EXPECT_FALSE(first_child_span->spanEntity()->skipAnalysis()); + EXPECT_EQ(2, first_child_span->spanEntity()->spanId()); + EXPECT_EQ(0, first_child_span->spanEntity()->parentSpanId()); + + EXPECT_EQ("TestChild", first_child_span->spanEntity()->operationName()); + + first_child_span->finishSpan(); + EXPECT_NE(0, first_child_span->spanEntity()->endTime()); + + Http::TestRequestHeaderMapImpl first_child_headers{{":authority", "test.com"}}; + + first_child_span->injectContext(first_child_headers, nullptr); auto sp = createSpanContext(first_child_headers.get_("sw8")); EXPECT_EQ("CURR#SERVICE", sp->service()); EXPECT_EQ("CURR#INSTANCE", sp->serviceInstance()); @@ -170,7 +199,7 @@ TEST_F(TracerTest, TracerTestCreateNewSpanWithNoPropagationHeaders) { // SkipAnalysis is true by default with calling setSkipAnalysis() on segment_context. EXPECT_TRUE(second_child_span->spanEntity()->skipAnalysis()); - EXPECT_EQ(2, second_child_span->spanEntity()->spanId()); + EXPECT_EQ(3, second_child_span->spanEntity()->spanId()); EXPECT_EQ(0, second_child_span->spanEntity()->parentSpanId()); second_child_span->finishSpan(); diff --git a/test/extensions/tracers/xray/tracer_test.cc b/test/extensions/tracers/xray/tracer_test.cc index df960cf04e102..f75b3d649d44f 100644 --- a/test/extensions/tracers/xray/tracer_test.cc +++ b/test/extensions/tracers/xray/tracer_test.cc @@ -508,7 +508,7 @@ TEST_F(XRayTracerTest, SpanInjectContextHasXRayHeader) { absl::nullopt /*headers*/, absl::nullopt /*client_ip from x-forwarded-for header*/); Http::TestRequestHeaderMapImpl request_headers; - span->injectContext(request_headers); + span->injectContext(request_headers, nullptr); auto header = request_headers.get(Http::LowerCaseString{XRayTraceHeader}); ASSERT_FALSE(header.empty()); EXPECT_NE(header[0]->value().getStringView().find("Root="), absl::string_view::npos); @@ -526,7 +526,7 @@ TEST_F(XRayTracerTest, SpanInjectContextHasXRayHeaderNonSampled) { server_.api().randomGenerator()}; auto span = tracer.createNonSampledSpan(absl::nullopt /*headers*/); Http::TestRequestHeaderMapImpl request_headers; - span->injectContext(request_headers); + span->injectContext(request_headers, nullptr); auto header = request_headers.get(Http::LowerCaseString{XRayTraceHeader}); ASSERT_FALSE(header.empty()); EXPECT_NE(header[0]->value().getStringView().find("Root="), absl::string_view::npos); diff --git a/test/extensions/tracers/zipkin/zipkin_tracer_impl_test.cc b/test/extensions/tracers/zipkin/zipkin_tracer_impl_test.cc index 93cb4bafbfc2c..f65ea7b6a592f 100644 --- a/test/extensions/tracers/zipkin/zipkin_tracer_impl_test.cc +++ b/test/extensions/tracers/zipkin/zipkin_tracer_impl_test.cc @@ -557,7 +557,7 @@ TEST_F(ZipkinDriverTest, PropagateB3NotSampled) { request_headers_.remove(ZipkinCoreConstants::get().X_B3_SAMPLED); - span->injectContext(request_headers_); + span->injectContext(request_headers_, nullptr); auto sampled_entry = request_headers_.get(ZipkinCoreConstants::get().X_B3_SAMPLED); @@ -580,7 +580,7 @@ TEST_F(ZipkinDriverTest, PropagateB3NotSampledWithFalse) { request_headers_.remove(ZipkinCoreConstants::get().X_B3_SAMPLED); - span->injectContext(request_headers_); + span->injectContext(request_headers_, nullptr); auto sampled_entry = request_headers_.get(ZipkinCoreConstants::get().X_B3_SAMPLED); // Check B3 sampled flag is set to not sample @@ -602,7 +602,7 @@ TEST_F(ZipkinDriverTest, PropagateB3SampledWithTrue) { request_headers_.remove(ZipkinCoreConstants::get().X_B3_SAMPLED); - span->injectContext(request_headers_); + span->injectContext(request_headers_, nullptr); auto sampled_entry = request_headers_.get(ZipkinCoreConstants::get().X_B3_SAMPLED); // Check B3 sampled flag is set to sample @@ -844,7 +844,7 @@ TEST_F(ZipkinDriverTest, ExplicitlySetSampledFalse) { request_headers_.remove(ZipkinCoreConstants::get().X_B3_SAMPLED); - span->injectContext(request_headers_); + span->injectContext(request_headers_, nullptr); auto sampled_entry = request_headers_.get(ZipkinCoreConstants::get().X_B3_SAMPLED); // Check B3 sampled flag is set to not sample @@ -861,7 +861,7 @@ TEST_F(ZipkinDriverTest, ExplicitlySetSampledTrue) { request_headers_.remove(ZipkinCoreConstants::get().X_B3_SAMPLED); - span->injectContext(request_headers_); + span->injectContext(request_headers_, nullptr); auto sampled_entry = request_headers_.get(ZipkinCoreConstants::get().X_B3_SAMPLED); // Check B3 sampled flag is set to sample @@ -890,7 +890,7 @@ TEST_F(ZipkinDriverTest, DuplicatedHeader) { }; span->setSampled(true); - span->injectContext(request_headers_); + span->injectContext(request_headers_, nullptr); request_headers_.iterate( [&dup_callback](const Http::HeaderEntry& header) -> Http::HeaderMap::Iterate { dup_callback(header.key().getStringView()); diff --git a/test/mocks/tracing/mocks.h b/test/mocks/tracing/mocks.h index 0b954e10aaaf1..c43a310322d7b 100644 --- a/test/mocks/tracing/mocks.h +++ b/test/mocks/tracing/mocks.h @@ -36,7 +36,9 @@ class MockSpan : public Span { MOCK_METHOD(void, setTag, (absl::string_view name, absl::string_view value)); MOCK_METHOD(void, log, (SystemTime timestamp, const std::string& event)); MOCK_METHOD(void, finishSpan, ()); - MOCK_METHOD(void, injectContext, (Tracing::TraceContext & request_headers)); + MOCK_METHOD(void, injectContext, + (Tracing::TraceContext & request_headers, + const Upstream::HostDescriptionConstSharedPtr& upstream)); MOCK_METHOD(void, setSampled, (const bool sampled)); MOCK_METHOD(void, setBaggage, (absl::string_view key, absl::string_view value)); MOCK_METHOD(std::string, getBaggage, (absl::string_view key));