From 78095ce0c709c251c01bbd08a87910aa36e62fe1 Mon Sep 17 00:00:00 2001 From: Larry Osterman Date: Thu, 2 Jun 2022 17:25:08 -0700 Subject: [PATCH] Additional OpenTelemetry Feedback... (#3691) * OpenTelemetry API Review Feedback * Returns std::unique_ptr")); std::unique_ptr response - = m_pipeline->Send(requestToSend, contextAndSpan.first); - contextAndSpan.second.SetStatus(Azure::Core::Tracing::_internal::SpanStatus::Ok); + = m_pipeline->Send(requestToSend, contextAndSpan.Context); + contextAndSpan.Span.SetStatus(Azure::Core::Tracing::_internal::SpanStatus::Ok); return Azure::Response("", std::move(response)); } catch (std::exception const& ex) { // Register that the exception has happened and that the span is now in error. - contextAndSpan.second.AddEvent(ex); - contextAndSpan.second.SetStatus(Azure::Core::Tracing::_internal::SpanStatus::Error); + contextAndSpan.Span.AddEvent(ex); + contextAndSpan.Span.SetStatus(Azure::Core::Tracing::_internal::SpanStatus::Error); throw; } diff --git a/sdk/core/azure-core-tracing-opentelemetry/test/ut/service_support_test.cpp b/sdk/core/azure-core-tracing-opentelemetry/test/ut/service_support_test.cpp index 377ba2e66..630296ccb 100644 --- a/sdk/core/azure-core-tracing-opentelemetry/test/ut/service_support_test.cpp +++ b/sdk/core/azure-core-tracing-opentelemetry/test/ut/service_support_test.cpp @@ -274,22 +274,21 @@ protected: TEST_F(OpenTelemetryServiceTests, SimplestTest) { { - Azure::Core::Tracing::_internal::DiagnosticTracingFactory serviceTrace; + Azure::Core::Tracing::_internal::TracingContextFactory serviceTrace; } { Azure::Core::_internal::ClientOptions clientOptions; - Azure::Core::Tracing::_internal::DiagnosticTracingFactory serviceTrace( + Azure::Core::Tracing::_internal::TracingContextFactory serviceTrace( clientOptions, "my-service-cpp", "1.0b2"); } { Azure::Core::_internal::ClientOptions clientOptions; - Azure::Core::Tracing::_internal::DiagnosticTracingFactory serviceTrace( + Azure::Core::Tracing::_internal::TracingContextFactory serviceTrace( clientOptions, "my-service-cpp", "1.0b2"); - auto contextAndSpan = serviceTrace.CreateSpan( - "My API", Azure::Core::Tracing::_internal::SpanKind::Internal, {}); - EXPECT_FALSE(contextAndSpan.first.IsCancelled()); + auto contextAndSpan = serviceTrace.CreateTracingContext("My API", {}); + EXPECT_FALSE(contextAndSpan.Context.IsCancelled()); } } @@ -320,13 +319,12 @@ TEST_F(OpenTelemetryServiceTests, CreateWithExplicitProvider) clientOptions.Telemetry.TracingProvider = provider; clientOptions.Telemetry.ApplicationId = "MyApplication"; - Azure::Core::Tracing::_internal::DiagnosticTracingFactory serviceTrace( + Azure::Core::Tracing::_internal::TracingContextFactory serviceTrace( clientOptions, "my-service", "1.0beta-2"); Azure::Core::Context clientContext; - auto contextAndSpan = serviceTrace.CreateSpan( - "My API", Azure::Core::Tracing::_internal::SpanKind::Internal, clientContext); - EXPECT_FALSE(contextAndSpan.first.IsCancelled()); + auto contextAndSpan = serviceTrace.CreateTracingContext("My API", clientContext); + EXPECT_FALSE(contextAndSpan.Context.IsCancelled()); } // Now let's verify what was logged via OpenTelemetry. auto spans = m_spanData->GetSpans(); @@ -360,13 +358,12 @@ TEST_F(OpenTelemetryServiceTests, CreateWithImplicitProvider) Azure::Core::_internal::ClientOptions clientOptions; clientOptions.Telemetry.ApplicationId = "MyApplication"; - Azure::Core::Tracing::_internal::DiagnosticTracingFactory serviceTrace( + Azure::Core::Tracing::_internal::TracingContextFactory serviceTrace( clientOptions, "my-service", "1.0beta-2"); Azure::Core::Context clientContext; - auto contextAndSpan = serviceTrace.CreateSpan( - "My API", Azure::Core::Tracing::_internal::SpanKind::Internal, clientContext); - EXPECT_FALSE(contextAndSpan.first.IsCancelled()); + auto contextAndSpan = serviceTrace.CreateTracingContext("My API", clientContext); + EXPECT_FALSE(contextAndSpan.Context.IsCancelled()); } // Now let's verify what was logged via OpenTelemetry. @@ -404,7 +401,7 @@ TEST_F(OpenTelemetryServiceTests, CreateSpanWithOptions) Azure::Core::_internal::ClientOptions clientOptions; clientOptions.Telemetry.ApplicationId = "MyApplication"; - Azure::Core::Tracing::_internal::DiagnosticTracingFactory serviceTrace( + Azure::Core::Tracing::_internal::TracingContextFactory serviceTrace( clientOptions, "my-service", "1.0beta-2"); Azure::Core::Context clientContext; @@ -412,8 +409,9 @@ TEST_F(OpenTelemetryServiceTests, CreateSpanWithOptions) createOptions.Kind = Azure::Core::Tracing::_internal::SpanKind::Internal; createOptions.Attributes = serviceTrace.CreateAttributeSet(); createOptions.Attributes->AddAttribute("TestAttribute", 3); - auto contextAndSpan = serviceTrace.CreateSpan("My API", createOptions, clientContext); - EXPECT_FALSE(contextAndSpan.first.IsCancelled()); + auto contextAndSpan + = serviceTrace.CreateTracingContext("My API", createOptions, clientContext); + EXPECT_FALSE(contextAndSpan.Context.IsCancelled()); } // Now let's verify what was logged via OpenTelemetry. @@ -456,21 +454,25 @@ TEST_F(OpenTelemetryServiceTests, NestSpans) Azure::Core::_internal::ClientOptions clientOptions; clientOptions.Telemetry.ApplicationId = "MyApplication"; - Azure::Core::Tracing::_internal::DiagnosticTracingFactory serviceTrace( + Azure::Core::Tracing::_internal::TracingContextFactory serviceTrace( clientOptions, "my-service", "1.0beta-2"); Azure::Core::Context parentContext; - auto contextAndSpan = serviceTrace.CreateSpan( - "My API", Azure::Core::Tracing::_internal::SpanKind::Client, parentContext); - EXPECT_FALSE(contextAndSpan.first.IsCancelled()); - parentContext = contextAndSpan.first; - contextAndSpan.second.PropagateToHttpHeaders(outerRequest); + Azure::Core::Tracing::_internal::CreateSpanOptions createOptions; + createOptions.Kind = Azure::Core::Tracing::_internal::SpanKind::Client; + auto contextAndSpan + = serviceTrace.CreateTracingContext("My API", createOptions, parentContext); + EXPECT_FALSE(contextAndSpan.Context.IsCancelled()); + parentContext = contextAndSpan.Context; + contextAndSpan.Span.PropagateToHttpHeaders(outerRequest); { - auto innerContextAndSpan = serviceTrace.CreateSpan( - "Nested API", Azure::Core::Tracing::_internal::SpanKind::Server, parentContext); - EXPECT_FALSE(innerContextAndSpan.first.IsCancelled()); - innerContextAndSpan.second.PropagateToHttpHeaders(innerRequest); + Azure::Core::Tracing::_internal::CreateSpanOptions innerOptions; + innerOptions.Kind = Azure::Core::Tracing::_internal::SpanKind::Server; + auto innerContextAndSpan + = serviceTrace.CreateTracingContext("Nested API", innerOptions, parentContext); + EXPECT_FALSE(innerContextAndSpan.Context.IsCancelled()); + innerContextAndSpan.Span.PropagateToHttpHeaders(innerRequest); } } // Now let's verify what was logged via OpenTelemetry. @@ -580,7 +582,7 @@ public: class ServiceClient { private: ServiceClientOptions m_clientOptions; - Azure::Core::Tracing::_internal::DiagnosticTracingFactory m_tracingFactory; + Azure::Core::Tracing::_internal::TracingContextFactory m_tracingFactory; std::unique_ptr m_pipeline; public: @@ -612,20 +614,19 @@ public: Azure::Response GetConfigurationString( std::string const& inputString, - Azure::Core::Context const& context = Azure::Core::Context{}) + Azure::Core::Context const& context = Azure::Core::Context{}) const { - auto contextAndSpan = m_tracingFactory.CreateSpan( - "GetConfigurationString", Azure::Core::Tracing::_internal::SpanKind::Internal, context); + auto contextAndSpan = m_tracingFactory.CreateTracingContext("GetConfigurationString", context); // Azure::Core::Http::Request requestToSend( HttpMethod::Get, Azure::Core::Url("https://www.microsoft.com/")); std::unique_ptr response - = m_pipeline->Send(requestToSend, contextAndSpan.first); + = m_pipeline->Send(requestToSend, contextAndSpan.Context); // Reflect that the operation was successful. - contextAndSpan.second.SetStatus(Azure::Core::Tracing::_internal::SpanStatus::Ok); + contextAndSpan.Span.SetStatus(Azure::Core::Tracing::_internal::SpanStatus::Ok); Azure::Response rv(inputString, std::move(response)); return rv; // When contextAndSpan.second goes out of scope, it ends the span, which will record it. @@ -633,10 +634,9 @@ public: Azure::Response ApiWhichThrows( std::string const&, - Azure::Core::Context const& context = Azure::Core::Context{}) + Azure::Core::Context const& context = Azure::Core::Context{}) const { - auto contextAndSpan = m_tracingFactory.CreateSpan( - "ApiWhichThrows", Azure::Core::Tracing::_internal::SpanKind::Internal, context); + auto contextAndSpan = m_tracingFactory.CreateTracingContext("ApiWhichThrows", context); try { @@ -645,14 +645,14 @@ public: HttpMethod::Get, Azure::Core::Url("https://www.microsoft.com/:12345/index.html")); std::unique_ptr response - = m_pipeline->Send(requestToSend, contextAndSpan.first); + = m_pipeline->Send(requestToSend, contextAndSpan.Context); return Azure::Response("", std::move(response)); } catch (std::exception const& ex) { // Register that the exception has happened and that the span is now in error. - contextAndSpan.second.AddEvent(ex); - contextAndSpan.second.SetStatus(Azure::Core::Tracing::_internal::SpanStatus::Error); + contextAndSpan.Span.AddEvent(ex); + contextAndSpan.Span.SetStatus(Azure::Core::Tracing::_internal::SpanStatus::Error); throw; } diff --git a/sdk/core/azure-core/inc/azure/core/internal/tracing/service_tracing.hpp b/sdk/core/azure-core/inc/azure/core/internal/tracing/service_tracing.hpp index d153161cf..b023a850c 100644 --- a/sdk/core/azure-core/inc/azure/core/internal/tracing/service_tracing.hpp +++ b/sdk/core/azure-core/inc/azure/core/internal/tracing/service_tracing.hpp @@ -29,7 +29,7 @@ namespace Azure { namespace Core { namespace Tracing { namespace _internal { private: std::shared_ptr m_span; - friend class DiagnosticTracingFactory; + friend class TracingContextFactory; ServiceSpan() = default; explicit ServiceSpan(std::shared_ptr span) : m_span(span) {} @@ -49,11 +49,11 @@ namespace Azure { namespace Core { namespace Tracing { namespace _internal { } } - void End(Azure::Nullable = Azure::Nullable{}) override + void End(Azure::Nullable endTime = Azure::Nullable{}) override { if (m_span) { - m_span->End(); + m_span->End(endTime); } } void SetStatus( @@ -161,7 +161,7 @@ namespace Azure { namespace Core { namespace Tracing { namespace _internal { * @details Each service implementation SHOULD have a member variable which aids in managing * the distributed tracing for the service. */ - class DiagnosticTracingFactory final { + class TracingContextFactory final { private: std::string m_serviceName; std::string m_serviceVersion; @@ -177,11 +177,9 @@ namespace Azure { namespace Core { namespace Tracing { namespace _internal { */ static Azure::Core::Context::Key ContextSpanKey; static Azure::Core::Context::Key TracingFactoryContextKey; - // using TracingContext = std::pair, std::shared_ptr>; - using TracingContext = std::shared_ptr; public: - DiagnosticTracingFactory( + TracingContextFactory( Azure::Core::_internal::ClientOptions const& options, std::string serviceName, std::string serviceVersion) @@ -193,27 +191,59 @@ namespace Azure { namespace Core { namespace Tracing { namespace _internal { { } - DiagnosticTracingFactory() = default; - DiagnosticTracingFactory(DiagnosticTracingFactory const&) = default; + TracingContextFactory() = default; + TracingContextFactory(TracingContextFactory const&) = default; - /** @brief A ContextAndSpan provides an updated Context object and a new span object + /** @brief A TracingContext provides an updated Context object and a new span object * which can be used to add events and attributes to the span. */ - using ContextAndSpan = std::pair; + struct TracingContext + { + /** + * @brief New Context to be used for subsequent methods which take a Context parameter. + */ + Azure::Core::Context Context; + /** + * @brief Distributed Tracing Span which can be used to update status if the API succeeds or + * fails. + */ + ServiceSpan Span; + }; - ContextAndSpan CreateSpan( + /** + * @brief Create a span with the specified span name. + * + * @details This method is a convenience method intended for use by service clients, it creates + * a SpanKind::Internal span and context. + * + * @param spanName Name for the span to be created. + * @param context parent context object for the newly created span. + * + * @returns Newly allocated context and Span object. + * + */ + TracingContext CreateTracingContext( std::string const& spanName, - Azure::Core::Tracing::_internal::SpanKind const& spanKind, - Azure::Core::Context const& clientContext); + Azure::Core::Context const& context) const; - ContextAndSpan CreateSpan( + /** + * @brief Create a span with the specified span name and create options. + * + * @param spanName Name for the span to be created. + * @param spanOptions Options for the newly created span. + * @param context parent context object for the newly created span. + * + * @returns Newly allocated context and Span object. + * + */ + TracingContext CreateTracingContext( std::string const& spanName, Azure::Core::Tracing::_internal::CreateSpanOptions& spanOptions, - Azure::Core::Context const& clientContext); + Azure::Core::Context const& context) const; - std::unique_ptr CreateAttributeSet(); + std::unique_ptr CreateAttributeSet() const; - static std::unique_ptr DiagnosticFactoryFromContext( + static std::unique_ptr CreateFromContext( Azure::Core::Context const& context); }; diff --git a/sdk/core/azure-core/src/http/request_activity_policy.cpp b/sdk/core/azure-core/src/http/request_activity_policy.cpp index 504a4017e..f52a54861 100644 --- a/sdk/core/azure-core/src/http/request_activity_policy.cpp +++ b/sdk/core/azure-core/src/http/request_activity_policy.cpp @@ -25,7 +25,7 @@ std::unique_ptr RequestActivityPolicy::Send( { // Find a tracing factory from our context. Note that the factory value is owned by the // context chain so we can manage a raw pointer to the factory. - auto tracingFactory = DiagnosticTracingFactory::DiagnosticFactoryFromContext(context); + auto tracingFactory = TracingContextFactory::CreateFromContext(context); if (tracingFactory) { // Create a tracing span over the HTTP request. @@ -38,27 +38,32 @@ std::unique_ptr RequestActivityPolicy::Send( // Note that the AttributeSet takes a *reference* to the values passed into the AttributeSet. // This means that all the values passed into the AttributeSet MUST be stabilized across the // lifetime of the AttributeSet. - std::string httpMethod = request.GetMethod().ToString(); - createOptions.Attributes->AddAttribute(TracingAttributes::HttpMethod.ToString(), httpMethod); - std::string sanitizedUrl = m_inputSanitizer.SanitizeUrl(request.GetUrl()).GetAbsoluteUrl(); + // Note that request.GetMethod() returns an HttpMethod object, which is always a static + // object, and thus its lifetime is constant. That is not the case for the other values + // stored in the attributes. + createOptions.Attributes->AddAttribute( + TracingAttributes::HttpMethod.ToString(), request.GetMethod().ToString()); + + const std::string sanitizedUrl + = m_inputSanitizer.SanitizeUrl(request.GetUrl()).GetAbsoluteUrl(); createOptions.Attributes->AddAttribute("http.url", sanitizedUrl); - Azure::Nullable requestId = request.GetHeader("x-ms-client-request-id"); + const Azure::Nullable requestId = request.GetHeader("x-ms-client-request-id"); if (requestId.HasValue()) { createOptions.Attributes->AddAttribute( TracingAttributes::RequestId.ToString(), requestId.Value()); } - auto userAgent = request.GetHeader("User-Agent"); + const auto userAgent = request.GetHeader("User-Agent"); if (userAgent.HasValue()) { createOptions.Attributes->AddAttribute( TracingAttributes::HttpUserAgent.ToString(), userAgent.Value()); } - auto contextAndSpan = tracingFactory->CreateSpan(ss.str(), createOptions, context); - auto scope = std::move(contextAndSpan.second); + auto contextAndSpan = tracingFactory->CreateTracingContext(ss.str(), createOptions, context); + auto scope = std::move(contextAndSpan.Span); // Propagate information from the scope to the HTTP headers. // @@ -68,7 +73,7 @@ std::unique_ptr RequestActivityPolicy::Send( try { // Send the request on to the service. - auto response = nextPolicy.Send(request, contextAndSpan.first); + auto response = nextPolicy.Send(request, contextAndSpan.Context); // And register the headers we received from the service. scope.AddAttribute( diff --git a/sdk/core/azure-core/src/tracing/tracing.cpp b/sdk/core/azure-core/src/tracing/tracing.cpp index 0df489e30..de183e822 100644 --- a/sdk/core/azure-core/src/tracing/tracing.cpp +++ b/sdk/core/azure-core/src/tracing/tracing.cpp @@ -21,43 +21,42 @@ namespace Azure { namespace Core { namespace Tracing { namespace _internal { const TracingAttributes TracingAttributes::RequestId("requestId"); const TracingAttributes TracingAttributes::HttpStatusCode("http.status_code"); - DiagnosticTracingFactory::ContextAndSpan DiagnosticTracingFactory::CreateSpan( + TracingContextFactory::TracingContext TracingContextFactory::CreateTracingContext( std::string const& methodName, - Azure::Core::Tracing::_internal::SpanKind const& spanKind, - Azure::Core::Context const& context) + Azure::Core::Context const& context) const { if (m_serviceTracer) { Azure::Core::Context contextToUse = context; CreateSpanOptions createOptions; - createOptions.Kind = spanKind; + createOptions.Kind = SpanKind::Internal; createOptions.Attributes = m_serviceTracer->CreateAttributeSet(); - return CreateSpan(methodName, createOptions, context); + return CreateTracingContext(methodName, createOptions, context); } else { - return std::make_pair(context, ServiceSpan{}); + return TracingContext{context, ServiceSpan{}}; } } - DiagnosticTracingFactory::ContextAndSpan DiagnosticTracingFactory::CreateSpan( + TracingContextFactory::TracingContext TracingContextFactory::CreateTracingContext( std::string const& methodName, Azure::Core::Tracing::_internal::CreateSpanOptions& createOptions, - Azure::Core::Context const& context) + Azure::Core::Context const& context) const { if (m_serviceTracer) { Azure::Core::Context contextToUse = context; // Ensure that the factory is available in the context chain. - DiagnosticTracingFactory* tracingFactoryFromContext; + TracingContextFactory const* tracingFactoryFromContext; if (!context.TryGetValue(TracingFactoryContextKey, tracingFactoryFromContext)) { contextToUse = context.WithValue(TracingFactoryContextKey, this); } - TracingContext traceContext; + std::shared_ptr traceContext; // Find a span in the context hierarchy. if (contextToUse.TryGetValue(ContextSpanKey, traceContext)) { @@ -78,25 +77,23 @@ namespace Azure { namespace Core { namespace Tracing { namespace _internal { TracingAttributes::AzNamespace.ToString(), m_serviceName); std::shared_ptr newSpan(m_serviceTracer->CreateSpan(methodName, createOptions)); - TracingContext tracingContext = newSpan; - Azure::Core::Context newContext = contextToUse.WithValue(ContextSpanKey, tracingContext); + Azure::Core::Context newContext = contextToUse.WithValue(ContextSpanKey, newSpan); ServiceSpan newServiceSpan(newSpan); - return std::make_pair( - std::move(newContext), std::move(newServiceSpan)); + return TracingContext{std::move(newContext), std::move(newServiceSpan)}; } else { - return std::make_pair(context, ServiceSpan{}); + return TracingContext{context, ServiceSpan{}}; } } - std::unique_ptr DiagnosticTracingFactory::DiagnosticFactoryFromContext( + std::unique_ptr TracingContextFactory::CreateFromContext( Azure::Core::Context const& context) { - DiagnosticTracingFactory* factory; + TracingContextFactory const* factory; if (context.TryGetValue(TracingFactoryContextKey, factory)) { - return std::make_unique(*factory); + return std::make_unique(*factory); } else { @@ -105,7 +102,7 @@ namespace Azure { namespace Core { namespace Tracing { namespace _internal { } std::unique_ptr - DiagnosticTracingFactory::CreateAttributeSet() + TracingContextFactory::CreateAttributeSet() const { if (m_serviceTracer) { @@ -114,6 +111,6 @@ namespace Azure { namespace Core { namespace Tracing { namespace _internal { return nullptr; } - Azure::Core::Context::Key DiagnosticTracingFactory::ContextSpanKey; - Azure::Core::Context::Key DiagnosticTracingFactory::TracingFactoryContextKey; + Azure::Core::Context::Key TracingContextFactory::ContextSpanKey; + Azure::Core::Context::Key TracingContextFactory::TracingFactoryContextKey; }}}} // namespace Azure::Core::Tracing::_internal diff --git a/sdk/core/azure-core/test/ut/request_activity_policy_test.cpp b/sdk/core/azure-core/test/ut/request_activity_policy_test.cpp index 2d5e34ad2..927b3777a 100644 --- a/sdk/core/azure-core/test/ut/request_activity_policy_test.cpp +++ b/sdk/core/azure-core/test/ut/request_activity_policy_test.cpp @@ -159,12 +159,11 @@ TEST(RequestActivityPolicy, Basic) Azure::Core::_internal::ClientOptions clientOptions; clientOptions.Telemetry.TracingProvider = testTracer; - Azure::Core::Tracing::_internal::DiagnosticTracingFactory serviceTrace( + Azure::Core::Tracing::_internal::TracingContextFactory serviceTrace( clientOptions, "my-service-cpp", "1.0b2"); - auto contextAndSpan = serviceTrace.CreateSpan( - "My API", Azure::Core::Tracing::_internal::SpanKind::Internal, {}); - Azure::Core::Context callContext = std::move(contextAndSpan.first); + auto contextAndSpan = serviceTrace.CreateTracingContext("My API", {}); + Azure::Core::Context callContext = std::move(contextAndSpan.Context); Request request(HttpMethod::Get, Url("https://www.microsoft.com")); { @@ -192,11 +191,10 @@ TEST(RequestActivityPolicy, Basic) Azure::Core::_internal::ClientOptions clientOptions; clientOptions.Telemetry.TracingProvider = testTracer; - Azure::Core::Tracing::_internal::DiagnosticTracingFactory serviceTrace( + Azure::Core::Tracing::_internal::TracingContextFactory serviceTrace( clientOptions, "my-service-cpp", "1.0b2"); - auto contextAndSpan = serviceTrace.CreateSpan( - "My API", Azure::Core::Tracing::_internal::SpanKind::Internal, {}); - Azure::Core::Context callContext = std::move(contextAndSpan.first); + auto contextAndSpan = serviceTrace.CreateTracingContext("My API", {}); + Azure::Core::Context callContext = std::move(contextAndSpan.Context); Request request(HttpMethod::Get, Url("https://www.microsoft.com")); { @@ -230,12 +228,11 @@ TEST(RequestActivityPolicy, TryRetries) Azure::Core::_internal::ClientOptions clientOptions; clientOptions.Telemetry.TracingProvider = testTracer; - Azure::Core::Tracing::_internal::DiagnosticTracingFactory serviceTrace( + Azure::Core::Tracing::_internal::TracingContextFactory serviceTrace( clientOptions, "my-service-cpp", "1.0b2"); - auto contextAndSpan = serviceTrace.CreateSpan( - "My API", Azure::Core::Tracing::_internal::SpanKind::Internal, {}); - Azure::Core::Context callContext = std::move(contextAndSpan.first); + auto contextAndSpan = serviceTrace.CreateTracingContext("My API", {}); + Azure::Core::Context callContext = std::move(contextAndSpan.Context); Request request(HttpMethod::Get, Url("https://www.microsoft.com")); { diff --git a/sdk/core/azure-core/test/ut/service_tracing_test.cpp b/sdk/core/azure-core/test/ut/service_tracing_test.cpp index 4c3988233..1ac5e8eea 100644 --- a/sdk/core/azure-core/test/ut/service_tracing_test.cpp +++ b/sdk/core/azure-core/test/ut/service_tracing_test.cpp @@ -9,7 +9,7 @@ using namespace Azure::Core; using namespace Azure::Core::Tracing; using namespace Azure::Core::Tracing::_internal; -TEST(DiagnosticTracingFactory, ServiceTraceEnums) +TEST(TracingContextFactory, ServiceTraceEnums) { // Exercise the SpanKind and SpanStatus constructors from the distributed tracing header. { @@ -32,25 +32,24 @@ TEST(DiagnosticTracingFactory, ServiceTraceEnums) std::string tracingAttributeName = TracingAttributes::AzNamespace.ToString(); } -TEST(DiagnosticTracingFactory, SimpleServiceSpanTests) +TEST(TracingContextFactory, SimpleServiceSpanTests) { { - Azure::Core::Tracing::_internal::DiagnosticTracingFactory serviceTrace; + Azure::Core::Tracing::_internal::TracingContextFactory serviceTrace; } { Azure::Core::_internal::ClientOptions clientOptions; - Azure::Core::Tracing::_internal::DiagnosticTracingFactory serviceTrace( + Azure::Core::Tracing::_internal::TracingContextFactory serviceTrace( clientOptions, "my-service-cpp", "1.0b2"); } { Azure::Core::_internal::ClientOptions clientOptions; - Azure::Core::Tracing::_internal::DiagnosticTracingFactory serviceTrace( + Azure::Core::Tracing::_internal::TracingContextFactory serviceTrace( clientOptions, "my-service-cpp", "1.0b2"); - auto contextAndSpan = serviceTrace.CreateSpan( - "My API", Azure::Core::Tracing::_internal::SpanKind::Internal, {}); - EXPECT_FALSE(contextAndSpan.first.IsCancelled()); + auto contextAndSpan = serviceTrace.CreateTracingContext("My API", {}); + EXPECT_FALSE(contextAndSpan.Context.IsCancelled()); } } namespace { @@ -113,16 +112,15 @@ public: }; }; } // namespace -TEST(DiagnosticTracingFactory, BasicServiceSpanTests) +TEST(TracingContextFactory, BasicServiceSpanTests) { { Azure::Core::_internal::ClientOptions clientOptions; - Azure::Core::Tracing::_internal::DiagnosticTracingFactory serviceTrace( + Azure::Core::Tracing::_internal::TracingContextFactory serviceTrace( clientOptions, "my-service-cpp", "1.0b2"); - auto contextAndSpan = serviceTrace.CreateSpan( - "My API", Azure::Core::Tracing::_internal::SpanKind::Internal, {}); - ServiceSpan span = std::move(contextAndSpan.second); + auto contextAndSpan = serviceTrace.CreateTracingContext("My API", {}); + ServiceSpan span = std::move(contextAndSpan.Span); span.End(); span.AddEvent("New Event"); @@ -134,12 +132,11 @@ TEST(DiagnosticTracingFactory, BasicServiceSpanTests) Azure::Core::_internal::ClientOptions clientOptions; auto testTracer = std::make_shared(); clientOptions.Telemetry.TracingProvider = testTracer; - Azure::Core::Tracing::_internal::DiagnosticTracingFactory serviceTrace( + Azure::Core::Tracing::_internal::TracingContextFactory serviceTrace( clientOptions, "my-service-cpp", "1.0b2"); - auto contextAndSpan = serviceTrace.CreateSpan( - "My API", Azure::Core::Tracing::_internal::SpanKind::Internal, {}); - ServiceSpan span = std::move(contextAndSpan.second); + auto contextAndSpan = serviceTrace.CreateTracingContext("My API", {}); + ServiceSpan span = std::move(contextAndSpan.Span); span.End(); span.AddEvent("New Event"); @@ -152,16 +149,15 @@ TEST(DiagnosticTracingFactory, BasicServiceSpanTests) span.SetStatus(SpanStatus::Error); } - // Now run all the previous tests on a DiagnosticTracingFactory created *without* a tracing + // Now run all the previous tests on a TracingContextFactory created *without* a tracing // provider. { Azure::Core::_internal::ClientOptions clientOptions; - Azure::Core::Tracing::_internal::DiagnosticTracingFactory serviceTrace( + Azure::Core::Tracing::_internal::TracingContextFactory serviceTrace( clientOptions, "my-service-cpp", "1.0b2"); - auto contextAndSpan = serviceTrace.CreateSpan( - "My API", Azure::Core::Tracing::_internal::SpanKind::Internal, {}); - ServiceSpan span = std::move(contextAndSpan.second); + auto contextAndSpan = serviceTrace.CreateTracingContext("My API", {}); + ServiceSpan span = std::move(contextAndSpan.Span); span.End(); span.AddEvent("New Event");