Removed internal types from OpenTelemetry API surface; removed default parameters from OpenTelemetry API surface. (#3762)
* Removed internal references from public headers * Updated changelog files * Updated DistributedTracing.md to reflect Factory construction of Azure::Core::Tracing::OpenTelemetry::OpenTelemetryProvider type Co-authored-by: Ahson Khan <ahkha@microsoft.com> Co-authored-by: Anton Kolesnyk <41349689+antkmsft@users.noreply.github.com>
This commit is contained in:
Родитель
3d62767b5e
Коммит
38b07749dc
|
@ -85,7 +85,7 @@ functions as an abstract class integration between OpenTelemetry and Azure Core:
|
|||
|
||||
```c++
|
||||
std::shared_ptr<Azure::Core::Tracing::TracerProvider> traceProvider
|
||||
= std::make_shared<Azure::Core::Tracing::OpenTelemetry::OpenTelemetryProvider>(CreateOpenTelemetryProvider());
|
||||
= Azure::Core::Tracing::OpenTelemetry::OpenTelemetryProvider::Create(CreateOpenTelemetryProvider());
|
||||
```
|
||||
|
||||
To finish the integration with Azure clients, there are two mechanisms to integrate OpenTelemetry into a client application:
|
||||
|
@ -110,7 +110,7 @@ the service client.
|
|||
|
||||
```c++
|
||||
auto tracerProvider(CreateOpenTelemetryProvider());
|
||||
auto provider(std::make_shared<Azure::Core::Tracing::OpenTelemetry::OpenTelemetryProvider>(tracerProvider));
|
||||
auto provider(Azure::Core::Tracing::OpenTelemetry::OpenTelemetryProvider::Create(tracerProvider));
|
||||
|
||||
ServiceClientOptions clientOptions;
|
||||
clientOptions.Telemetry.TracingProvider = provider;
|
||||
|
|
|
@ -6,10 +6,14 @@
|
|||
|
||||
### Breaking Changes
|
||||
|
||||
- The `Azure::Core::Tracing::OpenTelemetry::OpenTelemetryProvider` type can only be instantiated via a factory method: `OpenTelemetryProvider::Create`.
|
||||
|
||||
### Bugs Fixed
|
||||
|
||||
### Other Changes
|
||||
|
||||
- Removed `_internal` APIs from the public API surface. Also removed most of the `_internal` APIs from the public `opentelemetry.hpp` headers.
|
||||
|
||||
## 1.0.0-beta.1 (2022-06-07)
|
||||
|
||||
### Features Added
|
||||
|
|
|
@ -41,6 +41,7 @@ if (BUILD_AZURE_CORE_TRACING_OPENTELEMETRY)
|
|||
set(
|
||||
AZURE_CORE_OPENTELEMETRY_HEADER
|
||||
inc/azure/core/tracing/opentelemetry/opentelemetry.hpp
|
||||
src/opentelemetry_private.hpp
|
||||
)
|
||||
|
||||
set(
|
||||
|
@ -79,13 +80,13 @@ if(BUILD_AZURE_CORE_TRACING_OPENTELEMETRY)
|
|||
az_vcpkg_export(
|
||||
azure-core-tracing-opentelemetry
|
||||
CORE_TRACING_OPENTELEMETRY
|
||||
"azure/core/tracing/opentelemetry/dll_import_export.hpp"
|
||||
azure/core/tracing/opentelemetry/dll_import_export.hpp
|
||||
)
|
||||
|
||||
az_rtti_setup(
|
||||
azure-core-tracing-opentelemetry
|
||||
CORE_TRACING_OPENTELEMETRY
|
||||
"azure/core/tracing/opentelemetry/rtti.hpp"
|
||||
azure/core/tracing/opentelemetry/rtti.hpp
|
||||
)
|
||||
endif()
|
||||
|
||||
|
|
|
@ -49,7 +49,7 @@ the [opentelemetry-cpp](https://github.com/open-telemetry/opentelemetry-cpp/blob
|
|||
```cpp
|
||||
// Start by creating an OpenTelemetry Provider using the
|
||||
// default OpenTelemetry tracer provider.
|
||||
std::shared_ptr<Azure::Core::Tracing::TracerProvider> tracerProvider = std::make_shared<Azure::Core::OpenTelemetry::TracerProvider>();
|
||||
std::shared_ptr<Azure::Core::Tracing::TracerProvider> tracerProvider = Azure::Core::OpenTelemetry::TracerProvider::Create();
|
||||
|
||||
// Connect the tracerProvider to the current application context.
|
||||
ApplicationContext().SetTracerProvider(tracerProvider);
|
||||
|
@ -80,7 +80,7 @@ auto openTelemetryProvider = opentelemetry::nostd::shared_ptr<opentelemetry::tra
|
|||
|
||||
// Use the default OpenTelemetry tracer provider.
|
||||
std::shared_ptr<Azure::Core::Tracing::TracerProvider> tracerProvider =
|
||||
std::make_shared<Azure::Core::OpenTelemetry::TracerProvider>(openTelemetryProvider);
|
||||
Azure::Core::OpenTelemetry::TracerProvider::Create(openTelemetryProvider);
|
||||
|
||||
// Connect the tracerProvider to the current application context.
|
||||
ApplicationContext().SetTracerProvider(tracerProvider);
|
||||
|
|
|
@ -4,7 +4,6 @@
|
|||
#pragma once
|
||||
|
||||
#include <azure/core/tracing/tracing.hpp>
|
||||
|
||||
#if defined(_MSC_VER)
|
||||
// The OpenTelemetry headers generate a couple of warnings on MSVC in the OTel 1.2 package, suppress
|
||||
// the warnings across the includes.
|
||||
|
@ -13,10 +12,7 @@
|
|||
#pragma warning(disable : 4244)
|
||||
#pragma warning(disable : 6323) // Disable "Use of arithmetic operator on Boolean type" warning.
|
||||
#endif
|
||||
#include <opentelemetry/common/kv_properties.h>
|
||||
#include <opentelemetry/trace/provider.h>
|
||||
#include <opentelemetry/trace/span.h>
|
||||
#include <opentelemetry/trace/tracer.h>
|
||||
#include <opentelemetry/trace/tracer_provider.h>
|
||||
#if defined(_MSC_VER)
|
||||
#pragma warning(pop)
|
||||
|
@ -24,139 +20,6 @@
|
|||
|
||||
namespace Azure { namespace Core { namespace Tracing { namespace OpenTelemetry {
|
||||
|
||||
namespace _detail {
|
||||
class OpenTelemetryAttributeSet final : public Azure::Core::Tracing::_internal::AttributeSet,
|
||||
public opentelemetry::common::KeyValueIterable {
|
||||
std::map<std::string, opentelemetry::common::AttributeValue> m_propertySet;
|
||||
|
||||
template <typename T> void AddAttributeToSet(std::string const& attributeName, T value)
|
||||
{
|
||||
m_propertySet.emplace(
|
||||
std::make_pair(attributeName, opentelemetry::common::AttributeValue(value)));
|
||||
}
|
||||
|
||||
public:
|
||||
void AddAttribute(std::string const& attributeName, int32_t value) override
|
||||
{
|
||||
AddAttributeToSet(attributeName, value);
|
||||
}
|
||||
|
||||
void AddAttribute(std::string const& attributeName, int64_t value) override
|
||||
{
|
||||
AddAttributeToSet(attributeName, value);
|
||||
}
|
||||
|
||||
void AddAttribute(std::string const& attributeName, uint64_t value) override
|
||||
{
|
||||
AddAttributeToSet(attributeName, value);
|
||||
}
|
||||
void AddAttribute(std::string const& attributeName, double value) override
|
||||
{
|
||||
AddAttributeToSet(attributeName, value);
|
||||
}
|
||||
|
||||
void AddAttribute(std::string const& attributeName, std::string const& value) override
|
||||
{
|
||||
AddAttributeToSet<std::string const&>(attributeName, value);
|
||||
}
|
||||
void AddAttribute(std::string const& attributeName, const char* value) override
|
||||
{
|
||||
AddAttributeToSet(attributeName, value);
|
||||
}
|
||||
|
||||
void AddAttribute(std::string const& attributeName, bool value) override
|
||||
{
|
||||
AddAttributeToSet(attributeName, value);
|
||||
}
|
||||
|
||||
/**
|
||||
* Iterate over key-value pairs
|
||||
* @param callback a callback to invoke for each key-value. If the callback returns false,
|
||||
* the iteration is aborted.
|
||||
* @return true if every key-value pair was iterated over
|
||||
*/
|
||||
bool ForEachKeyValue(
|
||||
opentelemetry::nostd::function_ref<
|
||||
bool(opentelemetry::nostd::string_view, opentelemetry::common::AttributeValue)>
|
||||
callback) const noexcept override
|
||||
{
|
||||
for (auto& value : m_propertySet)
|
||||
{
|
||||
if (!callback(value.first, value.second))
|
||||
{
|
||||
return false;
|
||||
}
|
||||
}
|
||||
return true;
|
||||
}
|
||||
|
||||
/**
|
||||
* @return the number of key-value pairs
|
||||
*/
|
||||
size_t size() const noexcept override { return m_propertySet.size(); }
|
||||
|
||||
~OpenTelemetryAttributeSet() {}
|
||||
};
|
||||
/**
|
||||
* @brief Span - represents a span in tracing.
|
||||
*/
|
||||
class OpenTelemetrySpan final : public Azure::Core::Tracing::_internal::Span {
|
||||
opentelemetry::nostd::shared_ptr<opentelemetry::trace::Span> m_span;
|
||||
|
||||
public:
|
||||
OpenTelemetrySpan(opentelemetry::nostd::shared_ptr<opentelemetry::trace::Span> span);
|
||||
|
||||
~OpenTelemetrySpan();
|
||||
|
||||
/**
|
||||
* @brief Signals that the span has now ended.
|
||||
*/
|
||||
virtual void End(Azure::Nullable<Azure::DateTime> endTime) override;
|
||||
|
||||
virtual void AddAttributes(
|
||||
Azure::Core::Tracing::_internal::AttributeSet const& attributeToAdd) override;
|
||||
virtual void AddAttribute(std::string const& attributeName, std::string const& attributeValue)
|
||||
override;
|
||||
|
||||
/**
|
||||
* Add an Event to the span. An event is identified by a name and an optional set of
|
||||
* attributes associated with the event.
|
||||
*/
|
||||
virtual void AddEvent(
|
||||
std::string const& eventName,
|
||||
Azure::Core::Tracing::_internal::AttributeSet const& eventAttributes) override;
|
||||
virtual void AddEvent(std::string const& eventName) override;
|
||||
virtual void AddEvent(std::exception const& exception) override;
|
||||
|
||||
virtual void SetStatus(
|
||||
Azure::Core::Tracing::_internal::SpanStatus const& status,
|
||||
std::string const& statusMessage) override;
|
||||
|
||||
/**
|
||||
* @brief Propogate information from the current span to the HTTP request headers.
|
||||
*
|
||||
* @param request HTTP Request to the service. If there is an active tracing span, this will
|
||||
* add required headers to the HTTP Request.
|
||||
*/
|
||||
virtual void PropagateToHttpHeaders(Azure::Core::Http::Request& request) override;
|
||||
|
||||
opentelemetry::trace::SpanContext GetContext() { return m_span->GetContext(); }
|
||||
};
|
||||
|
||||
class OpenTelemetryTracer final : public Azure::Core::Tracing::_internal::Tracer {
|
||||
opentelemetry::nostd::shared_ptr<opentelemetry::trace::Tracer> m_tracer;
|
||||
|
||||
public:
|
||||
OpenTelemetryTracer(opentelemetry::nostd::shared_ptr<opentelemetry::trace::Tracer> tracer);
|
||||
std::shared_ptr<Azure::Core::Tracing::_internal::Span> CreateSpan(
|
||||
std::string const& spanName,
|
||||
Azure::Core::Tracing::_internal::CreateSpanOptions const& options) const override;
|
||||
|
||||
std::unique_ptr<Azure::Core::Tracing::_internal::AttributeSet> CreateAttributeSet()
|
||||
const override;
|
||||
};
|
||||
} // namespace _detail
|
||||
|
||||
/**
|
||||
* @brief Trace Provider - factory for creating Tracer objects.
|
||||
*
|
||||
|
@ -166,23 +29,30 @@ namespace Azure { namespace Core { namespace Tracing { namespace OpenTelemetry {
|
|||
*
|
||||
*/
|
||||
class OpenTelemetryProvider final : public Azure::Core::Tracing::TracerProvider {
|
||||
private:
|
||||
std::shared_ptr<Azure::Core::Tracing::_internal::Tracer> CreateTracer(
|
||||
std::string const& name,
|
||||
std::string const& version) const override;
|
||||
|
||||
opentelemetry::nostd::shared_ptr<opentelemetry::trace::TracerProvider> m_tracerProvider;
|
||||
|
||||
public:
|
||||
OpenTelemetryProvider(
|
||||
opentelemetry::nostd::shared_ptr<opentelemetry::trace::TracerProvider> tracerProvider);
|
||||
OpenTelemetryProvider();
|
||||
explicit OpenTelemetryProvider(
|
||||
opentelemetry::nostd::shared_ptr<opentelemetry::trace::TracerProvider> tracerProvider
|
||||
= opentelemetry::trace::Provider::GetTracerProvider());
|
||||
|
||||
public:
|
||||
/**
|
||||
* @brief Create a Tracer object
|
||||
* @brief Create a new instance of an OpenTelemetryProvider.
|
||||
*
|
||||
* @param name Name of the tracer object, typically the name of the Service client
|
||||
* (Azure.Storage.Blobs, for example)
|
||||
* @param version Version of the service client.
|
||||
* @return std::shared_ptr<Azure::Core::Tracing::Tracer>
|
||||
* @param tracerProvider opentelemetry-cpp TracerProvider object.
|
||||
*
|
||||
* @returns a new OpenTelemetryProvider object
|
||||
*/
|
||||
virtual std::shared_ptr<Azure::Core::Tracing::_internal::Tracer> CreateTracer(
|
||||
std::string const& name,
|
||||
std::string const& version = "") const override;
|
||||
static std::shared_ptr<OpenTelemetryProvider> Create(
|
||||
opentelemetry::nostd::shared_ptr<opentelemetry::trace::TracerProvider> tracerProvider
|
||||
= opentelemetry::trace::Provider::GetTracerProvider());
|
||||
|
||||
virtual ~OpenTelemetryProvider() = default;
|
||||
};
|
||||
|
||||
}}}} // namespace Azure::Core::Tracing::OpenTelemetry
|
||||
|
|
|
@ -2,9 +2,10 @@
|
|||
// SPDX-License-Identifier: MIT
|
||||
|
||||
#include "azure/core/tracing/opentelemetry/opentelemetry.hpp"
|
||||
#include "opentelemetry_private.hpp"
|
||||
#include <azure/core/http/http.hpp>
|
||||
#include <azure/core/internal/tracing/tracing_impl.hpp>
|
||||
#include <azure/core/nullable.hpp>
|
||||
#include <azure/core/tracing/tracing.hpp>
|
||||
#include <memory>
|
||||
#if defined(_MSC_VER)
|
||||
// The OpenTelemetry headers generate a couple of warnings on MSVC in the OTel 1.2 package, suppress
|
||||
|
@ -29,9 +30,11 @@ namespace Azure { namespace Core { namespace Tracing { namespace OpenTelemetry {
|
|||
{
|
||||
}
|
||||
|
||||
OpenTelemetryProvider::OpenTelemetryProvider()
|
||||
: m_tracerProvider(opentelemetry::trace::Provider::GetTracerProvider())
|
||||
std::shared_ptr<OpenTelemetryProvider> OpenTelemetryProvider::Create(
|
||||
opentelemetry::nostd::shared_ptr<opentelemetry::trace::TracerProvider> tracerProvider)
|
||||
{
|
||||
auto rv = std::shared_ptr<OpenTelemetryProvider>(new OpenTelemetryProvider(tracerProvider));
|
||||
return {rv, rv.get()};
|
||||
}
|
||||
|
||||
std::shared_ptr<Azure::Core::Tracing::_internal::Tracer> OpenTelemetryProvider::CreateTracer(
|
||||
|
@ -44,6 +47,7 @@ namespace Azure { namespace Core { namespace Tracing { namespace OpenTelemetry {
|
|||
returnTracer);
|
||||
}
|
||||
namespace _detail {
|
||||
|
||||
std::unique_ptr<Azure::Core::Tracing::_internal::AttributeSet>
|
||||
OpenTelemetryTracer::CreateAttributeSet() const
|
||||
{
|
||||
|
@ -84,7 +88,8 @@ namespace Azure { namespace Core { namespace Tracing { namespace OpenTelemetry {
|
|||
}
|
||||
else
|
||||
{
|
||||
throw std::runtime_error("Unknown SpanOptions Kind: " + options.Kind.ToString());
|
||||
throw std::runtime_error(
|
||||
"Unknown SpanOptions Kind: " + std::to_string(static_cast<int>(options.Kind)));
|
||||
}
|
||||
|
||||
if (options.ParentSpan)
|
||||
|
@ -184,7 +189,8 @@ namespace Azure { namespace Core { namespace Tracing { namespace OpenTelemetry {
|
|||
}
|
||||
else
|
||||
{
|
||||
throw std::runtime_error("Unknown status code: " + status.ToString());
|
||||
throw std::runtime_error(
|
||||
"Unknown status code: " + std::to_string(static_cast<int>(status)));
|
||||
}
|
||||
|
||||
m_span->SetStatus(statusCode, statusMessage);
|
||||
|
@ -251,6 +257,6 @@ namespace Azure { namespace Core { namespace Tracing { namespace OpenTelemetry {
|
|||
opentelemetry::trace::propagation::HttpTraceContext().Inject(propagator, currentContext);
|
||||
}
|
||||
}
|
||||
|
||||
} // namespace _detail
|
||||
|
||||
}}}} // namespace Azure::Core::Tracing::OpenTelemetry
|
||||
|
|
|
@ -0,0 +1,159 @@
|
|||
// Copyright (c) Microsoft Corporation. All rights reserved.
|
||||
// SPDX-License-Identifier: MIT
|
||||
|
||||
#pragma once
|
||||
|
||||
#include "azure/core/tracing/opentelemetry/opentelemetry.hpp"
|
||||
#include <azure/core/internal/tracing/tracing_impl.hpp>
|
||||
#if defined(_MSC_VER)
|
||||
// The OpenTelemetry headers generate a couple of warnings on MSVC in the OTel 1.2 package, suppress
|
||||
// the warnings across the includes.
|
||||
#pragma warning(push)
|
||||
#pragma warning(disable : 4100)
|
||||
#pragma warning(disable : 4244)
|
||||
#pragma warning(disable : 6323) // Disable "Use of arithmetic operator on Boolean type" warning.
|
||||
#endif
|
||||
#include <opentelemetry/common/kv_properties.h>
|
||||
#include <opentelemetry/trace/provider.h>
|
||||
#include <opentelemetry/trace/span.h>
|
||||
#include <opentelemetry/trace/tracer.h>
|
||||
#include <opentelemetry/trace/tracer_provider.h>
|
||||
#if defined(_MSC_VER)
|
||||
#pragma warning(pop)
|
||||
#endif
|
||||
|
||||
namespace Azure { namespace Core { namespace Tracing { namespace OpenTelemetry { namespace _detail {
|
||||
class OpenTelemetryAttributeSet final : public Azure::Core::Tracing::_internal::AttributeSet,
|
||||
public opentelemetry::common::KeyValueIterable {
|
||||
std::map<std::string, opentelemetry::common::AttributeValue> m_propertySet;
|
||||
|
||||
template <typename T> void AddAttributeToSet(std::string const& attributeName, T value)
|
||||
{
|
||||
m_propertySet.emplace(
|
||||
std::make_pair(attributeName, opentelemetry::common::AttributeValue(value)));
|
||||
}
|
||||
|
||||
public:
|
||||
void AddAttribute(std::string const& attributeName, int32_t value) override
|
||||
{
|
||||
AddAttributeToSet(attributeName, value);
|
||||
}
|
||||
|
||||
void AddAttribute(std::string const& attributeName, int64_t value) override
|
||||
{
|
||||
AddAttributeToSet(attributeName, value);
|
||||
}
|
||||
|
||||
void AddAttribute(std::string const& attributeName, uint64_t value) override
|
||||
{
|
||||
AddAttributeToSet(attributeName, value);
|
||||
}
|
||||
void AddAttribute(std::string const& attributeName, double value) override
|
||||
{
|
||||
AddAttributeToSet(attributeName, value);
|
||||
}
|
||||
|
||||
void AddAttribute(std::string const& attributeName, std::string const& value) override
|
||||
{
|
||||
AddAttributeToSet<std::string const&>(attributeName, value);
|
||||
}
|
||||
void AddAttribute(std::string const& attributeName, const char* value) override
|
||||
{
|
||||
AddAttributeToSet(attributeName, value);
|
||||
}
|
||||
|
||||
void AddAttribute(std::string const& attributeName, bool value) override
|
||||
{
|
||||
AddAttributeToSet(attributeName, value);
|
||||
}
|
||||
|
||||
/**
|
||||
* Iterate over key-value pairs
|
||||
* @param callback a callback to invoke for each key-value. If the callback returns false,
|
||||
* the iteration is aborted.
|
||||
* @return true if every key-value pair was iterated over
|
||||
*/
|
||||
bool ForEachKeyValue(
|
||||
opentelemetry::nostd::function_ref<
|
||||
bool(opentelemetry::nostd::string_view, opentelemetry::common::AttributeValue)>
|
||||
callback) const noexcept override
|
||||
{
|
||||
for (auto& value : m_propertySet)
|
||||
{
|
||||
if (!callback(value.first, value.second))
|
||||
{
|
||||
return false;
|
||||
}
|
||||
}
|
||||
return true;
|
||||
}
|
||||
|
||||
/**
|
||||
* @return the number of key-value pairs
|
||||
*/
|
||||
size_t size() const noexcept override { return m_propertySet.size(); }
|
||||
|
||||
~OpenTelemetryAttributeSet() {}
|
||||
};
|
||||
/**
|
||||
* @brief Span - represents a span in tracing.
|
||||
*/
|
||||
class OpenTelemetrySpan final : public Azure::Core::Tracing::_internal::Span {
|
||||
opentelemetry::nostd::shared_ptr<opentelemetry::trace::Span> m_span;
|
||||
// Copyright (c) Microsoft Corporation. All rights reserved.
|
||||
// SPDX-License-Identifier: MIT
|
||||
|
||||
public:
|
||||
OpenTelemetrySpan(opentelemetry::nostd::shared_ptr<opentelemetry::trace::Span> span);
|
||||
|
||||
~OpenTelemetrySpan();
|
||||
|
||||
/**
|
||||
* @brief Signals that the span has now ended.
|
||||
*/
|
||||
virtual void End(Azure::Nullable<Azure::DateTime> endTime) override;
|
||||
|
||||
virtual void AddAttributes(
|
||||
Azure::Core::Tracing::_internal::AttributeSet const& attributeToAdd) override;
|
||||
virtual void AddAttribute(std::string const& attributeName, std::string const& attributeValue)
|
||||
override;
|
||||
|
||||
/**
|
||||
* Add an Event to the span. An event is identified by a name and an optional set of
|
||||
* attributes associated with the event.
|
||||
*/
|
||||
virtual void AddEvent(
|
||||
std::string const& eventName,
|
||||
Azure::Core::Tracing::_internal::AttributeSet const& eventAttributes) override;
|
||||
virtual void AddEvent(std::string const& eventName) override;
|
||||
virtual void AddEvent(std::exception const& exception) override;
|
||||
|
||||
virtual void SetStatus(
|
||||
Azure::Core::Tracing::_internal::SpanStatus const& status,
|
||||
std::string const& statusMessage) override;
|
||||
|
||||
/**
|
||||
* @brief Propogate information from the current span to the HTTP request headers.
|
||||
*
|
||||
* @param request HTTP Request to the service. If there is an active tracing span,
|
||||
* this will add required headers to the HTTP Request.
|
||||
*/
|
||||
virtual void PropagateToHttpHeaders(Azure::Core::Http::Request& request) override;
|
||||
|
||||
opentelemetry::trace::SpanContext GetContext() { return m_span->GetContext(); }
|
||||
};
|
||||
|
||||
class OpenTelemetryTracer final : public Azure::Core::Tracing::_internal::Tracer {
|
||||
opentelemetry::nostd::shared_ptr<opentelemetry::trace::Tracer> m_tracer;
|
||||
|
||||
public:
|
||||
OpenTelemetryTracer(opentelemetry::nostd::shared_ptr<opentelemetry::trace::Tracer> tracer);
|
||||
std::shared_ptr<Azure::Core::Tracing::_internal::Span> CreateSpan(
|
||||
std::string const& spanName,
|
||||
Azure::Core::Tracing::_internal::CreateSpanOptions const& options) const override;
|
||||
|
||||
std::unique_ptr<Azure::Core::Tracing::_internal::AttributeSet> CreateAttributeSet()
|
||||
const override;
|
||||
};
|
||||
|
||||
}}}}} // namespace Azure::Core::Tracing::OpenTelemetry::_detail
|
|
@ -2,6 +2,7 @@
|
|||
// SPDX-License-Identifier: MIT
|
||||
|
||||
#define USE_MEMORY_EXPORTER 1
|
||||
#include "../src/opentelemetry_private.hpp"
|
||||
#include "azure/core/tracing/opentelemetry/opentelemetry.hpp"
|
||||
#include <azure/core/test/test_base.hpp>
|
||||
|
||||
|
@ -137,18 +138,24 @@ protected:
|
|||
|
||||
TEST_F(OpenTelemetryTests, Basic)
|
||||
{
|
||||
// Simple create an OTel telemetry provider as a static member variable.
|
||||
// Simple create an OTel telemetry provider and call a method on the concrete implementation.
|
||||
{
|
||||
Azure::Core::Tracing::OpenTelemetry::OpenTelemetryProvider provider;
|
||||
auto tracer = provider.CreateTracer("TracerName", "1.0");
|
||||
auto provider = Azure::Core::Tracing::OpenTelemetry::OpenTelemetryProvider::Create();
|
||||
|
||||
auto tracer
|
||||
= Azure::Core::Tracing::_internal::TracerProviderImplGetter::TracerImplFromTracer(provider)
|
||||
->CreateTracer("TracerName", "1.0");
|
||||
EXPECT_TRUE(tracer);
|
||||
}
|
||||
|
||||
// Create a shared provider using the tracing abstract classes.
|
||||
// Create a provider using the tracing abstract classes.
|
||||
{
|
||||
std::shared_ptr<Azure::Core::Tracing::TracerProvider> provider
|
||||
= std::make_shared<Azure::Core::Tracing::OpenTelemetry::OpenTelemetryProvider>();
|
||||
auto tracer = provider->CreateTracer("TracerName", "1.0");
|
||||
auto otProvider = Azure::Core::Tracing::OpenTelemetry::OpenTelemetryProvider::Create();
|
||||
auto provider = otProvider;
|
||||
|
||||
std::shared_ptr<Azure::Core::Tracing::_internal::TracerProviderImpl> providerImpl
|
||||
= Azure::Core::Tracing::_internal::TracerProviderImplGetter::TracerImplFromTracer(provider);
|
||||
auto tracer = providerImpl->CreateTracer("TracerName", "1.0");
|
||||
EXPECT_TRUE(tracer);
|
||||
}
|
||||
|
||||
|
@ -157,9 +164,11 @@ TEST_F(OpenTelemetryTests, Basic)
|
|||
auto rawTracer(opentelemetry::trace::Provider::GetTracerProvider());
|
||||
|
||||
auto traceProvider
|
||||
= std::make_shared<Azure::Core::Tracing::OpenTelemetry::OpenTelemetryProvider>(rawTracer);
|
||||
= Azure::Core::Tracing::OpenTelemetry::OpenTelemetryProvider::Create(rawTracer);
|
||||
|
||||
auto tracer = traceProvider->CreateTracer("TracerName");
|
||||
auto tracer = Azure::Core::Tracing::_internal::TracerProviderImplGetter::TracerImplFromTracer(
|
||||
traceProvider)
|
||||
->CreateTracer("TracerName", "1.0");
|
||||
EXPECT_TRUE(tracer);
|
||||
}
|
||||
|
||||
|
@ -168,10 +177,11 @@ TEST_F(OpenTelemetryTests, Basic)
|
|||
{
|
||||
auto otelProvider(CreateOpenTelemetryProvider());
|
||||
auto traceProvider
|
||||
= std::make_shared<Azure::Core::Tracing::OpenTelemetry::OpenTelemetryProvider>(
|
||||
otelProvider);
|
||||
= Azure::Core::Tracing::OpenTelemetry::OpenTelemetryProvider::Create(otelProvider);
|
||||
|
||||
auto tracer = traceProvider->CreateTracer("TracerName");
|
||||
auto tracer = Azure::Core::Tracing::_internal::TracerProviderImplGetter::TracerImplFromTracer(
|
||||
traceProvider)
|
||||
->CreateTracer("TracerName", {});
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -179,28 +189,32 @@ TEST_F(OpenTelemetryTests, CreateSpanSimple)
|
|||
{
|
||||
// Simple create an OTel telemetry provider as a static member variable.
|
||||
{
|
||||
Azure::Core::Tracing::OpenTelemetry::OpenTelemetryProvider provider;
|
||||
auto tracer = provider.CreateTracer("TracerName", "1.0");
|
||||
auto provider(Azure::Core::Tracing::OpenTelemetry::OpenTelemetryProvider::Create());
|
||||
auto tracer
|
||||
= Azure::Core::Tracing::_internal::TracerProviderImplGetter::TracerImplFromTracer(provider)
|
||||
->CreateTracer("TracerName", "1.0");
|
||||
EXPECT_TRUE(tracer);
|
||||
auto span = tracer->CreateSpan("My Span");
|
||||
auto span = tracer->CreateSpan("My Span", {});
|
||||
EXPECT_TRUE(span);
|
||||
|
||||
span->End();
|
||||
span->End({});
|
||||
}
|
||||
|
||||
// Create a provider using the OpenTelemetry reference provider (this will be a working provider
|
||||
// using the ostream logger).
|
||||
{
|
||||
std::shared_ptr<Azure::Core::Tracing::TracerProvider> traceProvider
|
||||
= std::make_shared<Azure::Core::Tracing::OpenTelemetry::OpenTelemetryProvider>(
|
||||
CreateOpenTelemetryProvider());
|
||||
auto otProvider = Azure::Core::Tracing::OpenTelemetry::OpenTelemetryProvider::Create(
|
||||
CreateOpenTelemetryProvider());
|
||||
std::shared_ptr<Azure::Core::Tracing::TracerProvider> traceProvider(otProvider);
|
||||
|
||||
auto tracer = traceProvider->CreateTracer("TracerName");
|
||||
auto tracer = Azure::Core::Tracing::_internal::TracerProviderImplGetter::TracerImplFromTracer(
|
||||
traceProvider)
|
||||
->CreateTracer("TracerName", {});
|
||||
{
|
||||
auto span = tracer->CreateSpan("My Span2");
|
||||
auto span = tracer->CreateSpan("My Span2", {});
|
||||
EXPECT_TRUE(span);
|
||||
|
||||
span->End();
|
||||
span->End({});
|
||||
}
|
||||
// Return the collected spans.
|
||||
auto spans = m_spanData->GetSpans();
|
||||
|
@ -307,31 +321,38 @@ TEST_F(OpenTelemetryTests, CreateSpanWithOptions)
|
|||
{
|
||||
// Simple create an OTel telemetry provider as a static member variable.
|
||||
{
|
||||
Azure::Core::Tracing::OpenTelemetry::OpenTelemetryProvider provider;
|
||||
auto tracer = provider.CreateTracer("TracerName", "1.0");
|
||||
auto provider = Azure::Core::Tracing::OpenTelemetry::OpenTelemetryProvider::Create(
|
||||
opentelemetry::trace::Provider::GetTracerProvider());
|
||||
auto tracer
|
||||
= Azure::Core::Tracing::_internal::TracerProviderImplGetter::TracerImplFromTracer(provider)
|
||||
->CreateTracer("TracerName", "1.0");
|
||||
EXPECT_TRUE(tracer);
|
||||
Azure::Core::Tracing::_internal::CreateSpanOptions options;
|
||||
auto span = tracer->CreateSpan("My Span", options);
|
||||
EXPECT_TRUE(span);
|
||||
|
||||
span->End();
|
||||
span->End({});
|
||||
}
|
||||
|
||||
// Create a provider using the OpenTelemetry reference provider (this will be a working provider
|
||||
// using the ostream logger).
|
||||
{
|
||||
std::shared_ptr<Azure::Core::Tracing::TracerProvider> traceProvider
|
||||
= std::make_shared<Azure::Core::Tracing::OpenTelemetry::OpenTelemetryProvider>(
|
||||
std::shared_ptr<Azure::Core::Tracing::OpenTelemetry::OpenTelemetryProvider> traceProvider
|
||||
= Azure::Core::Tracing::OpenTelemetry::OpenTelemetryProvider::Create(
|
||||
CreateOpenTelemetryProvider());
|
||||
|
||||
auto tracer = traceProvider->CreateTracer("TracerName");
|
||||
auto tracerImpl
|
||||
= Azure::Core::Tracing::_internal::TracerProviderImplGetter::TracerImplFromTracer(
|
||||
traceProvider);
|
||||
|
||||
auto tracer = tracerImpl->CreateTracer("TracerName", {});
|
||||
{
|
||||
Azure::Core::Tracing::_internal::CreateSpanOptions options;
|
||||
options.Kind = Azure::Core::Tracing::_internal::SpanKind::Client;
|
||||
auto span = tracer->CreateSpan("Client Span", options);
|
||||
EXPECT_TRUE(span);
|
||||
|
||||
span->End();
|
||||
span->End({});
|
||||
}
|
||||
{
|
||||
Azure::Core::Tracing::_internal::CreateSpanOptions options;
|
||||
|
@ -339,7 +360,7 @@ TEST_F(OpenTelemetryTests, CreateSpanWithOptions)
|
|||
auto span = tracer->CreateSpan("Consumer Span", options);
|
||||
EXPECT_TRUE(span);
|
||||
|
||||
span->End();
|
||||
span->End({});
|
||||
}
|
||||
{
|
||||
Azure::Core::Tracing::_internal::CreateSpanOptions options;
|
||||
|
@ -347,7 +368,7 @@ TEST_F(OpenTelemetryTests, CreateSpanWithOptions)
|
|||
auto span = tracer->CreateSpan("Internal Span", options);
|
||||
EXPECT_TRUE(span);
|
||||
|
||||
span->End();
|
||||
span->End({});
|
||||
}
|
||||
{
|
||||
Azure::Core::Tracing::_internal::CreateSpanOptions options;
|
||||
|
@ -355,7 +376,7 @@ TEST_F(OpenTelemetryTests, CreateSpanWithOptions)
|
|||
auto span = tracer->CreateSpan("Producer Span", options);
|
||||
EXPECT_TRUE(span);
|
||||
|
||||
span->End();
|
||||
span->End({});
|
||||
}
|
||||
{
|
||||
Azure::Core::Tracing::_internal::CreateSpanOptions options;
|
||||
|
@ -363,12 +384,7 @@ TEST_F(OpenTelemetryTests, CreateSpanWithOptions)
|
|||
auto span = tracer->CreateSpan("Server Span", options);
|
||||
EXPECT_TRUE(span);
|
||||
|
||||
span->End();
|
||||
}
|
||||
{
|
||||
Azure::Core::Tracing::_internal::CreateSpanOptions options;
|
||||
options.Kind = Azure::Core::Tracing::_internal::SpanKind("Bogus");
|
||||
EXPECT_THROW(tracer->CreateSpan("Bogus Span", options), std::runtime_error);
|
||||
span->End({});
|
||||
}
|
||||
// Return the collected spans.
|
||||
auto spans = m_spanData->GetSpans();
|
||||
|
@ -390,11 +406,13 @@ TEST_F(OpenTelemetryTests, CreateSpanWithOptions)
|
|||
// Create a provider using the OpenTelemetry reference provider (this will be a working provider
|
||||
// using the ostream logger).
|
||||
{
|
||||
std::shared_ptr<Azure::Core::Tracing::TracerProvider> traceProvider
|
||||
= std::make_shared<Azure::Core::Tracing::OpenTelemetry::OpenTelemetryProvider>(
|
||||
CreateOpenTelemetryProvider());
|
||||
auto otProvider = Azure::Core::Tracing::OpenTelemetry::OpenTelemetryProvider::Create(
|
||||
CreateOpenTelemetryProvider());
|
||||
std::shared_ptr<Azure::Core::Tracing::TracerProvider> traceProvider(otProvider);
|
||||
|
||||
auto tracer = traceProvider->CreateTracer("TracerName");
|
||||
auto tracer = Azure::Core::Tracing::_internal::TracerProviderImplGetter::TracerImplFromTracer(
|
||||
traceProvider)
|
||||
->CreateTracer("TracerName", {});
|
||||
{
|
||||
Azure::Core::Tracing::_internal::CreateSpanOptions options;
|
||||
options.Attributes = std::make_unique<
|
||||
|
@ -404,7 +422,7 @@ TEST_F(OpenTelemetryTests, CreateSpanWithOptions)
|
|||
auto span = tracer->CreateSpan("Client Span", options);
|
||||
EXPECT_TRUE(span);
|
||||
|
||||
span->End();
|
||||
span->End({});
|
||||
|
||||
// Return the collected spans.
|
||||
auto spans = m_spanData->GetSpans();
|
||||
|
@ -429,11 +447,13 @@ TEST_F(OpenTelemetryTests, NestSpans)
|
|||
|
||||
{
|
||||
std::shared_ptr<Azure::Core::Tracing::TracerProvider> traceProvider
|
||||
= std::make_shared<Azure::Core::Tracing::OpenTelemetry::OpenTelemetryProvider>(
|
||||
= Azure::Core::Tracing::OpenTelemetry::OpenTelemetryProvider::Create(
|
||||
CreateOpenTelemetryProvider());
|
||||
|
||||
auto tracer = traceProvider->CreateTracer("TracerName");
|
||||
auto span = tracer->CreateSpan("SpanOuter");
|
||||
auto tracer = Azure::Core::Tracing::_internal::TracerProviderImplGetter::TracerImplFromTracer(
|
||||
traceProvider)
|
||||
->CreateTracer("TracerName", {});
|
||||
auto span = tracer->CreateSpan("SpanOuter", {});
|
||||
EXPECT_TRUE(span);
|
||||
{
|
||||
Azure::Core::Tracing::_internal::CreateSpanOptions so;
|
||||
|
@ -444,19 +464,19 @@ TEST_F(OpenTelemetryTests, NestSpans)
|
|||
// Span 3's parent is SpanOuter.
|
||||
so.ParentSpan = span;
|
||||
auto span4 = tracer->CreateSpan("SpanInner4", so);
|
||||
span2->End();
|
||||
span2->End({});
|
||||
|
||||
span->End();
|
||||
span4->End();
|
||||
span3->End();
|
||||
span->End({});
|
||||
span4->End({});
|
||||
span3->End({});
|
||||
}
|
||||
{
|
||||
Azure::Core::Tracing::_internal::CreateSpanOptions so;
|
||||
so.ParentSpan = span;
|
||||
auto span5 = tracer->CreateSpan("SequentialInner", so);
|
||||
auto span6 = tracer->CreateSpan("SequentialInner2", so);
|
||||
span5->End();
|
||||
span6->End();
|
||||
span5->End({});
|
||||
span6->End({});
|
||||
}
|
||||
|
||||
// Return the collected spans.
|
||||
|
@ -500,17 +520,19 @@ TEST_F(OpenTelemetryTests, SetStatus)
|
|||
|
||||
{
|
||||
std::shared_ptr<Azure::Core::Tracing::TracerProvider> traceProvider
|
||||
= std::make_shared<Azure::Core::Tracing::OpenTelemetry::OpenTelemetryProvider>(
|
||||
= Azure::Core::Tracing::OpenTelemetry::OpenTelemetryProvider::Create(
|
||||
CreateOpenTelemetryProvider());
|
||||
|
||||
auto tracer = traceProvider->CreateTracer("TracerName");
|
||||
auto span = tracer->CreateSpan("StatusSpan");
|
||||
auto tracer = Azure::Core::Tracing::_internal::TracerProviderImplGetter::TracerImplFromTracer(
|
||||
traceProvider)
|
||||
->CreateTracer("TracerName", {});
|
||||
auto span = tracer->CreateSpan("StatusSpan", {});
|
||||
EXPECT_TRUE(span);
|
||||
|
||||
span->SetStatus(Azure::Core::Tracing::_internal::SpanStatus::Error);
|
||||
span->SetStatus(Azure::Core::Tracing::_internal::SpanStatus::Ok);
|
||||
span->SetStatus(Azure::Core::Tracing::_internal::SpanStatus::Error, {});
|
||||
span->SetStatus(Azure::Core::Tracing::_internal::SpanStatus::Ok, {});
|
||||
|
||||
span->End();
|
||||
span->End({});
|
||||
|
||||
// Return the collected spans.
|
||||
auto spans = m_spanData->GetSpans();
|
||||
|
@ -520,17 +542,18 @@ TEST_F(OpenTelemetryTests, SetStatus)
|
|||
}
|
||||
|
||||
{
|
||||
std::shared_ptr<Azure::Core::Tracing::TracerProvider> traceProvider
|
||||
= std::make_shared<Azure::Core::Tracing::OpenTelemetry::OpenTelemetryProvider>(
|
||||
CreateOpenTelemetryProvider());
|
||||
auto traceProvider = Azure::Core::Tracing::OpenTelemetry::OpenTelemetryProvider::Create(
|
||||
CreateOpenTelemetryProvider());
|
||||
|
||||
auto tracer = traceProvider->CreateTracer("TracerName");
|
||||
auto span = tracer->CreateSpan("StatusSpan");
|
||||
auto tracer = Azure::Core::Tracing::_internal::TracerProviderImplGetter::TracerImplFromTracer(
|
||||
traceProvider)
|
||||
->CreateTracer("TracerName", {});
|
||||
auto span = tracer->CreateSpan("StatusSpan", {});
|
||||
EXPECT_TRUE(span);
|
||||
|
||||
span->SetStatus(Azure::Core::Tracing::_internal::SpanStatus::Error, "Something went wrong.");
|
||||
|
||||
span->End();
|
||||
span->End({});
|
||||
|
||||
// Return the collected spans.
|
||||
auto spans = m_spanData->GetSpans();
|
||||
|
@ -542,17 +565,18 @@ TEST_F(OpenTelemetryTests, SetStatus)
|
|||
|
||||
// Set to Unset.
|
||||
{
|
||||
std::shared_ptr<Azure::Core::Tracing::TracerProvider> traceProvider
|
||||
= std::make_shared<Azure::Core::Tracing::OpenTelemetry::OpenTelemetryProvider>(
|
||||
CreateOpenTelemetryProvider());
|
||||
auto traceProvider = Azure::Core::Tracing::OpenTelemetry::OpenTelemetryProvider::Create(
|
||||
CreateOpenTelemetryProvider());
|
||||
|
||||
auto tracer = traceProvider->CreateTracer("TracerName");
|
||||
auto span = tracer->CreateSpan("StatusSpan");
|
||||
auto tracer = Azure::Core::Tracing::_internal::TracerProviderImplGetter::TracerImplFromTracer(
|
||||
traceProvider)
|
||||
->CreateTracer("TracerName", {});
|
||||
auto span = tracer->CreateSpan("StatusSpan", {});
|
||||
EXPECT_TRUE(span);
|
||||
|
||||
span->SetStatus(Azure::Core::Tracing::_internal::SpanStatus::Unset);
|
||||
span->SetStatus(Azure::Core::Tracing::_internal::SpanStatus::Unset, {});
|
||||
|
||||
span->End();
|
||||
span->End({});
|
||||
|
||||
// Return the collected spans.
|
||||
auto spans = m_spanData->GetSpans();
|
||||
|
@ -563,15 +587,16 @@ TEST_F(OpenTelemetryTests, SetStatus)
|
|||
|
||||
// Not set.
|
||||
{
|
||||
std::shared_ptr<Azure::Core::Tracing::TracerProvider> traceProvider
|
||||
= std::make_shared<Azure::Core::Tracing::OpenTelemetry::OpenTelemetryProvider>(
|
||||
CreateOpenTelemetryProvider());
|
||||
auto traceProvider = Azure::Core::Tracing::OpenTelemetry::OpenTelemetryProvider::Create(
|
||||
CreateOpenTelemetryProvider());
|
||||
|
||||
auto tracer = traceProvider->CreateTracer("TracerName");
|
||||
auto span = tracer->CreateSpan("StatusSpan");
|
||||
auto tracer = Azure::Core::Tracing::_internal::TracerProviderImplGetter::TracerImplFromTracer(
|
||||
traceProvider)
|
||||
->CreateTracer("TracerName", {});
|
||||
auto span = tracer->CreateSpan("StatusSpan", {});
|
||||
EXPECT_TRUE(span);
|
||||
|
||||
span->End();
|
||||
span->End({});
|
||||
|
||||
// Return the collected spans.
|
||||
auto spans = m_spanData->GetSpans();
|
||||
|
@ -582,17 +607,15 @@ TEST_F(OpenTelemetryTests, SetStatus)
|
|||
|
||||
// Invalid status.
|
||||
{
|
||||
std::shared_ptr<Azure::Core::Tracing::TracerProvider> traceProvider
|
||||
= std::make_shared<Azure::Core::Tracing::OpenTelemetry::OpenTelemetryProvider>(
|
||||
CreateOpenTelemetryProvider());
|
||||
auto traceProvider = Azure::Core::Tracing::OpenTelemetry::OpenTelemetryProvider::Create(
|
||||
CreateOpenTelemetryProvider());
|
||||
|
||||
auto tracer = traceProvider->CreateTracer("TracerName");
|
||||
auto span = tracer->CreateSpan("StatusSpan");
|
||||
auto tracer = Azure::Core::Tracing::_internal::TracerProviderImplGetter::TracerImplFromTracer(
|
||||
traceProvider)
|
||||
->CreateTracer("TracerName", {});
|
||||
auto span = tracer->CreateSpan("StatusSpan", {});
|
||||
EXPECT_TRUE(span);
|
||||
|
||||
EXPECT_THROW(
|
||||
span->SetStatus(Azure::Core::Tracing::_internal::SpanStatus("Bogus")), std::runtime_error);
|
||||
|
||||
// Return the collected spans.
|
||||
auto spans = m_spanData->GetSpans();
|
||||
EXPECT_EQ(0ul, spans.size());
|
||||
|
@ -603,12 +626,13 @@ TEST_F(OpenTelemetryTests, AddSpanAttributes)
|
|||
{
|
||||
|
||||
{
|
||||
std::shared_ptr<Azure::Core::Tracing::TracerProvider> traceProvider
|
||||
= std::make_shared<Azure::Core::Tracing::OpenTelemetry::OpenTelemetryProvider>(
|
||||
CreateOpenTelemetryProvider());
|
||||
auto traceProvider = Azure::Core::Tracing::OpenTelemetry::OpenTelemetryProvider::Create(
|
||||
CreateOpenTelemetryProvider());
|
||||
|
||||
auto tracer = traceProvider->CreateTracer("TracerName");
|
||||
auto span = tracer->CreateSpan("AttributeSpan");
|
||||
auto tracer = Azure::Core::Tracing::_internal::TracerProviderImplGetter::TracerImplFromTracer(
|
||||
traceProvider)
|
||||
->CreateTracer("TracerName", {});
|
||||
auto span = tracer->CreateSpan("AttributeSpan", {});
|
||||
EXPECT_TRUE(span);
|
||||
|
||||
Azure::Core::Tracing::OpenTelemetry::_detail::OpenTelemetryAttributeSet attributeSet;
|
||||
|
@ -622,7 +646,7 @@ TEST_F(OpenTelemetryTests, AddSpanAttributes)
|
|||
std::string stringValue("std::string.");
|
||||
attributeSet.AddAttribute("stdstring", stringValue);
|
||||
span->AddAttributes(attributeSet);
|
||||
span->End();
|
||||
span->End({});
|
||||
|
||||
// Return the collected spans.
|
||||
auto spans = m_spanData->GetSpans();
|
||||
|
@ -643,12 +667,13 @@ TEST_F(OpenTelemetryTests, AddSpanAttributes)
|
|||
TEST_F(OpenTelemetryTests, AddSpanEvents)
|
||||
{
|
||||
{
|
||||
std::shared_ptr<Azure::Core::Tracing::TracerProvider> traceProvider
|
||||
= std::make_shared<Azure::Core::Tracing::OpenTelemetry::OpenTelemetryProvider>(
|
||||
CreateOpenTelemetryProvider());
|
||||
auto traceProvider = Azure::Core::Tracing::OpenTelemetry::OpenTelemetryProvider::Create(
|
||||
CreateOpenTelemetryProvider());
|
||||
|
||||
auto tracer = traceProvider->CreateTracer("TracerName");
|
||||
auto span = tracer->CreateSpan("SpanWithEvents");
|
||||
auto tracer = Azure::Core::Tracing::_internal::TracerProviderImplGetter::TracerImplFromTracer(
|
||||
traceProvider)
|
||||
->CreateTracer("TracerName", {});
|
||||
auto span = tracer->CreateSpan("SpanWithEvents", {});
|
||||
EXPECT_TRUE(span);
|
||||
|
||||
span->AddEvent("String Event");
|
||||
|
@ -667,7 +692,7 @@ TEST_F(OpenTelemetryTests, AddSpanEvents)
|
|||
attributeSet.AddAttribute("stdstring", stringValue);
|
||||
span->AddEvent("Event With Attributes", attributeSet);
|
||||
|
||||
span->End();
|
||||
span->End({});
|
||||
|
||||
// Return the collected spans.
|
||||
auto spans = m_spanData->GetSpans();
|
||||
|
|
|
@ -300,8 +300,8 @@ TEST_F(OpenTelemetryServiceTests, CreateWithExplicitProvider)
|
|||
//
|
||||
{
|
||||
auto tracerProvider(CreateOpenTelemetryProvider());
|
||||
auto provider(std::make_shared<Azure::Core::Tracing::OpenTelemetry::OpenTelemetryProvider>(
|
||||
tracerProvider));
|
||||
auto provider(
|
||||
Azure::Core::Tracing::OpenTelemetry::OpenTelemetryProvider::Create(tracerProvider));
|
||||
|
||||
Azure::Core::Context rootContext;
|
||||
rootContext.SetTracerProvider(provider);
|
||||
|
@ -310,8 +310,8 @@ TEST_F(OpenTelemetryServiceTests, CreateWithExplicitProvider)
|
|||
|
||||
{
|
||||
auto tracerProvider(CreateOpenTelemetryProvider());
|
||||
auto provider(std::make_shared<Azure::Core::Tracing::OpenTelemetry::OpenTelemetryProvider>(
|
||||
tracerProvider));
|
||||
auto provider(
|
||||
Azure::Core::Tracing::OpenTelemetry::OpenTelemetryProvider::Create(tracerProvider));
|
||||
|
||||
// Create a serviceTrace and span using a provider specified in the ClientOptions.
|
||||
{
|
||||
|
@ -349,8 +349,8 @@ TEST_F(OpenTelemetryServiceTests, CreateWithImplicitProvider)
|
|||
{
|
||||
{
|
||||
auto tracerProvider(CreateOpenTelemetryProvider());
|
||||
auto provider(std::make_shared<Azure::Core::Tracing::OpenTelemetry::OpenTelemetryProvider>(
|
||||
tracerProvider));
|
||||
auto provider(
|
||||
Azure::Core::Tracing::OpenTelemetry::OpenTelemetryProvider::Create(tracerProvider));
|
||||
|
||||
Azure::Core::Context::ApplicationContext.SetTracerProvider(provider);
|
||||
|
||||
|
@ -392,8 +392,8 @@ TEST_F(OpenTelemetryServiceTests, CreateSpanWithOptions)
|
|||
{
|
||||
{
|
||||
auto tracerProvider(CreateOpenTelemetryProvider());
|
||||
auto provider(std::make_shared<Azure::Core::Tracing::OpenTelemetry::OpenTelemetryProvider>(
|
||||
tracerProvider));
|
||||
auto provider(
|
||||
Azure::Core::Tracing::OpenTelemetry::OpenTelemetryProvider::Create(tracerProvider));
|
||||
|
||||
Azure::Core::Context::ApplicationContext.SetTracerProvider(provider);
|
||||
|
||||
|
@ -441,8 +441,8 @@ TEST_F(OpenTelemetryServiceTests, NestSpans)
|
|||
{
|
||||
{
|
||||
auto tracerProvider(CreateOpenTelemetryProvider());
|
||||
auto provider(std::make_shared<Azure::Core::Tracing::OpenTelemetry::OpenTelemetryProvider>(
|
||||
tracerProvider));
|
||||
auto provider(
|
||||
Azure::Core::Tracing::OpenTelemetry::OpenTelemetryProvider::Create(tracerProvider));
|
||||
|
||||
Azure::Core::Context::ApplicationContext.SetTracerProvider(provider);
|
||||
|
||||
|
@ -662,8 +662,8 @@ TEST_F(OpenTelemetryServiceTests, ServiceApiImplementation)
|
|||
{
|
||||
{
|
||||
auto tracerProvider(CreateOpenTelemetryProvider());
|
||||
auto provider(std::make_shared<Azure::Core::Tracing::OpenTelemetry::OpenTelemetryProvider>(
|
||||
tracerProvider));
|
||||
auto provider(
|
||||
Azure::Core::Tracing::OpenTelemetry::OpenTelemetryProvider::Create(tracerProvider));
|
||||
|
||||
{
|
||||
// Call a simple API and verify telemetry is generated.
|
||||
|
|
|
@ -10,6 +10,7 @@
|
|||
|
||||
### Other Changes
|
||||
|
||||
- Added prototypes and initial service support for Distributed Tracing.
|
||||
## 1.7.0-beta.1 (2022-06-02)
|
||||
|
||||
### Features Added
|
||||
|
|
|
@ -89,6 +89,7 @@ set(
|
|||
inc/azure/core/internal/json/json_serializable.hpp
|
||||
inc/azure/core/internal/strings.hpp
|
||||
inc/azure/core/internal/tracing/service_tracing.hpp
|
||||
inc/azure/core/internal/tracing/tracing_impl.hpp
|
||||
inc/azure/core/io/body_stream.hpp
|
||||
inc/azure/core/match_conditions.hpp
|
||||
inc/azure/core/modified_conditions.hpp
|
||||
|
|
|
@ -50,6 +50,3 @@
|
|||
|
||||
// azure/core/io
|
||||
#include "azure/core/io/body_stream.hpp"
|
||||
|
||||
// azure/core/tracing
|
||||
#include "azure/core/tracing/tracing.hpp"
|
||||
|
|
|
@ -3,8 +3,9 @@
|
|||
|
||||
#include "azure/core/context.hpp"
|
||||
#include "azure/core/internal/client_options.hpp"
|
||||
#include "azure/core/internal/extendable_enumeration.hpp"
|
||||
#include "azure/core/internal/http/user_agent.hpp"
|
||||
#include "azure/core/tracing/tracing.hpp"
|
||||
#include "azure/core/internal/tracing/tracing_impl.hpp"
|
||||
|
||||
#pragma once
|
||||
|
||||
|
@ -46,20 +47,26 @@ namespace Azure { namespace Core { namespace Tracing { namespace _internal {
|
|||
{
|
||||
if (m_span)
|
||||
{
|
||||
m_span->End();
|
||||
m_span->End({});
|
||||
}
|
||||
}
|
||||
|
||||
void End(Azure::Nullable<Azure::DateTime> endTime = Azure::Nullable<Azure::DateTime>{}) override
|
||||
void End() { End({}); }
|
||||
|
||||
void End(Azure::Nullable<Azure::DateTime> endTime) override
|
||||
{
|
||||
if (m_span)
|
||||
{
|
||||
m_span->End(endTime);
|
||||
}
|
||||
}
|
||||
void SetStatus(Azure::Core::Tracing::_internal::SpanStatus const& status)
|
||||
{
|
||||
SetStatus(status, {});
|
||||
}
|
||||
void SetStatus(
|
||||
Azure::Core::Tracing::_internal::SpanStatus const& status,
|
||||
std::string const& description = "") override
|
||||
std::string const& description) override
|
||||
{
|
||||
if (m_span)
|
||||
{
|
||||
|
@ -72,7 +79,7 @@ namespace Azure { namespace Core { namespace Tracing { namespace _internal {
|
|||
*
|
||||
* @param attributeToAdd Attributes to be added to the span.
|
||||
*/
|
||||
virtual void AddAttributes(AttributeSet const& attributeToAdd) override
|
||||
void AddAttributes(AttributeSet const& attributeToAdd) override
|
||||
{
|
||||
if (m_span)
|
||||
{
|
||||
|
@ -86,8 +93,7 @@ namespace Azure { namespace Core { namespace Tracing { namespace _internal {
|
|||
* @param attributeName Name of the attribute to be added.
|
||||
* @param attributeValue Value of the attribute to be added.
|
||||
*/
|
||||
virtual void AddAttribute(std::string const& attributeName, std::string const& attributeValue)
|
||||
override
|
||||
void AddAttribute(std::string const& attributeName, std::string const& attributeValue) override
|
||||
{
|
||||
if (m_span)
|
||||
{
|
||||
|
@ -104,8 +110,7 @@ namespace Azure { namespace Core { namespace Tracing { namespace _internal {
|
|||
* @param eventName Name of the event to add.
|
||||
* @param eventAttributes Attributes associated with the event.
|
||||
*/
|
||||
virtual void AddEvent(std::string const& eventName, AttributeSet const& eventAttributes)
|
||||
override
|
||||
void AddEvent(std::string const& eventName, AttributeSet const& eventAttributes) override
|
||||
{
|
||||
if (m_span)
|
||||
{
|
||||
|
@ -120,7 +125,7 @@ namespace Azure { namespace Core { namespace Tracing { namespace _internal {
|
|||
*
|
||||
* @param eventName Name of the event to add.
|
||||
*/
|
||||
virtual void AddEvent(std::string const& eventName) override
|
||||
void AddEvent(std::string const& eventName) override
|
||||
{
|
||||
if (m_span)
|
||||
{
|
||||
|
@ -134,12 +139,12 @@ namespace Azure { namespace Core { namespace Tracing { namespace _internal {
|
|||
*
|
||||
* @param exception Exception which has occurred.
|
||||
*/
|
||||
virtual void AddEvent(std::exception const& exception) override
|
||||
void AddEvent(std::exception const& exception) override
|
||||
{
|
||||
if (m_span)
|
||||
{
|
||||
m_span->AddEvent(exception);
|
||||
m_span->SetStatus(SpanStatus::Error);
|
||||
m_span->SetStatus(SpanStatus::Error, {});
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -149,7 +154,7 @@ namespace Azure { namespace Core { namespace Tracing { namespace _internal {
|
|||
* @param request HTTP Request to the service. If there is an active tracing span, this will
|
||||
* add required headers to the HTTP Request.
|
||||
*/
|
||||
virtual void PropagateToHttpHeaders(Azure::Core::Http::Request& request) override
|
||||
void PropagateToHttpHeaders(Azure::Core::Http::Request& request) override
|
||||
{
|
||||
if (m_span)
|
||||
{
|
||||
|
@ -194,7 +199,9 @@ namespace Azure { namespace Core { namespace Tracing { namespace _internal {
|
|||
options.Telemetry.ApplicationId)),
|
||||
m_serviceTracer(
|
||||
options.Telemetry.TracingProvider
|
||||
? options.Telemetry.TracingProvider->CreateTracer(serviceName, serviceVersion)
|
||||
? Azure::Core::Tracing::_internal::TracerProviderImplGetter::TracerImplFromTracer(
|
||||
options.Telemetry.TracingProvider)
|
||||
->CreateTracer(serviceName, serviceVersion)
|
||||
: nullptr)
|
||||
{
|
||||
}
|
||||
|
|
|
@ -0,0 +1,284 @@
|
|||
// Copyright (c) Microsoft Corporation. All rights reserved.
|
||||
// SPDX-License-Identifier: MIT
|
||||
|
||||
/**
|
||||
* @file
|
||||
* @brief Internal classes which abstract the OpenTelemetry API surface.
|
||||
*/
|
||||
|
||||
#pragma once
|
||||
|
||||
#include "azure/core/datetime.hpp"
|
||||
#include "azure/core/nullable.hpp"
|
||||
#include "azure/core/tracing/tracing.hpp"
|
||||
#include <map>
|
||||
#include <memory>
|
||||
#include <string>
|
||||
|
||||
// Forward declare Azure::Core::Http::Request to resolve an include file ordering problem.
|
||||
namespace Azure { namespace Core { namespace Http {
|
||||
class Request;
|
||||
}}} // namespace Azure::Core::Http
|
||||
|
||||
namespace Azure { namespace Core { namespace Tracing { namespace _internal {
|
||||
|
||||
/** The set of attributes to be applied to a Span or Event.
|
||||
*
|
||||
* @details
|
||||
* An AttributeSet represents a set of attributes to be added to a span or
|
||||
* event.
|
||||
*
|
||||
* @note Note that AttributeSets do *NOT* take a copy of their input values,
|
||||
* it is the responsibility of the caller to ensure that the object remains
|
||||
* valid between when it is added to the AttributeSet and when it is added to
|
||||
* a span or event.
|
||||
*
|
||||
* OpenTelemetry property bags can hold:
|
||||
* - bool
|
||||
* - int32_t
|
||||
* - int64_t
|
||||
* - uint64_t
|
||||
* - double
|
||||
* - const char *
|
||||
* - std::string/std::string_view *** Not Implemented
|
||||
* - std::span<const bool> *** Not Implemented
|
||||
* - std::span<const int32_t> *** Not Implemented
|
||||
* - std::span<const int64_t> *** Not Implemented
|
||||
* - std::span<const uint32_t> *** Not Implemented
|
||||
* - std::span<const double> *** Not Implemented
|
||||
* - std::span<std::string/std::string_view> *** Not Implemented
|
||||
* - uint64_t (not fully supported) *** Not Implemented
|
||||
* - std::span<uint64_t> (not fully supported) *** Not Implemented
|
||||
* - std::span<const uint8_t> (not fully supported) *** Not Implemented.
|
||||
*
|
||||
*/
|
||||
class AttributeSet {
|
||||
public:
|
||||
/**
|
||||
* @brief Adds a Boolean attribute to the attribute set.
|
||||
*
|
||||
* @param attributeName Name of attribute to add.
|
||||
* @param value Value of attribute.
|
||||
*/
|
||||
virtual void AddAttribute(std::string const& attributeName, bool value) = 0;
|
||||
/**
|
||||
* @brief Adds a 32bit integer attribute to the attribute set.
|
||||
*
|
||||
* @param attributeName Name of attribute to add.
|
||||
* @param value Value of attribute.
|
||||
*/
|
||||
virtual void AddAttribute(std::string const& attributeName, int32_t value) = 0;
|
||||
/**
|
||||
* @brief Adds a 64bit integer attribute to the attribute set.
|
||||
*
|
||||
* @param attributeName Name of attribute to add.
|
||||
* @param value Value of attribute.
|
||||
*/
|
||||
virtual void AddAttribute(std::string const& attributeName, int64_t value) = 0;
|
||||
/**
|
||||
* @brief Adds an unsigned 64bit integer attribute to the attribute set.
|
||||
*
|
||||
* @param attributeName Name of attribute to add.
|
||||
* @param value Value of attribute.
|
||||
*/
|
||||
virtual void AddAttribute(std::string const& attributeName, uint64_t value) = 0;
|
||||
/**
|
||||
* @brief Adds a 64bit floating point attribute to the attribute set.
|
||||
*
|
||||
* @param attributeName Name of attribute to add.
|
||||
* @param value Value of attribute.
|
||||
*/
|
||||
virtual void AddAttribute(std::string const& attributeName, double value) = 0;
|
||||
/**
|
||||
* @brief Adds a C style string attribute to the attribute set.
|
||||
*
|
||||
* @param attributeName Name of attribute to add.
|
||||
* @param value Value of attribute.
|
||||
*/
|
||||
virtual void AddAttribute(std::string const& attributeName, const char* value) = 0;
|
||||
/**
|
||||
* @brief Adds a C++ string attribute to the attribute set.
|
||||
*
|
||||
* @param attributeName Name of attribute to add.
|
||||
* @param value Value of attribute.
|
||||
*/
|
||||
virtual void AddAttribute(std::string const& attributeName, std::string const& value) = 0;
|
||||
|
||||
/**
|
||||
* @brief destroys an AttributeSet - virtual destructor to enable base class users to
|
||||
* destroy derived classes.
|
||||
*/
|
||||
virtual ~AttributeSet() = default;
|
||||
};
|
||||
|
||||
/** @brief The Type of Span.
|
||||
*/
|
||||
enum class SpanKind : int
|
||||
{
|
||||
/**
|
||||
* @brief Represents an "Internal" operation.
|
||||
*
|
||||
*/
|
||||
Internal,
|
||||
/**
|
||||
* @brief Represents a request to a remote service.
|
||||
*
|
||||
*/
|
||||
Client,
|
||||
/**
|
||||
* @brief Represents a span covering the server side handling of an API call.
|
||||
*
|
||||
*/
|
||||
Server,
|
||||
/**
|
||||
* @brief Represents the initiator of an asynchronous request.
|
||||
*
|
||||
*/
|
||||
Producer,
|
||||
/**
|
||||
* @brief Represents a span which describes a child of a producer request.
|
||||
*
|
||||
*/
|
||||
Consumer,
|
||||
};
|
||||
|
||||
/**
|
||||
* @brief Represents the status of a span.
|
||||
*/
|
||||
enum class SpanStatus : int
|
||||
{
|
||||
|
||||
/**
|
||||
* @brief The default status of a span.
|
||||
*/
|
||||
Unset,
|
||||
/**
|
||||
* @brief The operation has completed successfully.
|
||||
*/
|
||||
Ok,
|
||||
/**
|
||||
* @brief The operation contains an error.
|
||||
*/
|
||||
Error,
|
||||
|
||||
};
|
||||
|
||||
/**
|
||||
* @brief Span - represents a span in tracing.
|
||||
*/
|
||||
class Span {
|
||||
public:
|
||||
/**
|
||||
* @brief Signals that the span has now ended.
|
||||
*/
|
||||
virtual void End(Azure::Nullable<Azure::DateTime> endTime) = 0;
|
||||
|
||||
/**
|
||||
* @brief Adds a set of attributes to the span.
|
||||
*
|
||||
* @param attributeToAdd Attributes to be added to the span.
|
||||
*/
|
||||
virtual void AddAttributes(AttributeSet const& attributeToAdd) = 0;
|
||||
|
||||
/**
|
||||
* @brief Adds a single string valued attribute to the span.
|
||||
*
|
||||
* @param attributeName Name of the attribute to add.
|
||||
* @param attributeValue value of the attribute.
|
||||
*/
|
||||
virtual void AddAttribute(std::string const& attributeName, std::string const& attributeValue)
|
||||
= 0;
|
||||
|
||||
/**
|
||||
* @brief Adds an event to the span.
|
||||
*
|
||||
* Add an Event to the span. An event is identified by a name and an optional set of
|
||||
* attributes associated with the event.
|
||||
*
|
||||
* @param eventName Name of the event to add.
|
||||
* @param eventAttributes Attributes associated with the event.
|
||||
*/
|
||||
virtual void AddEvent(std::string const& eventName, AttributeSet const& eventAttributes) = 0;
|
||||
|
||||
/**
|
||||
* @brief Adds an event to the span.
|
||||
*
|
||||
* Add an Event to the span. An event is identified by a name
|
||||
*
|
||||
* @param eventName Name of the event to add.
|
||||
*/
|
||||
virtual void AddEvent(std::string const& eventName) = 0;
|
||||
/**
|
||||
* @brief Records an exception occurring in the span.
|
||||
*
|
||||
* @param exception Exception which has occurred.
|
||||
*/
|
||||
virtual void AddEvent(std::exception const& exception) = 0;
|
||||
|
||||
/**
|
||||
* @brief Set the Status of the span
|
||||
*
|
||||
* @param status Updated status of the span.
|
||||
* @param description A description associated with the Status.
|
||||
*/
|
||||
virtual void SetStatus(SpanStatus const& status, std::string const& description) = 0;
|
||||
|
||||
/**
|
||||
* @brief Propogate information from the current span to the HTTP request headers.
|
||||
*
|
||||
* @param request HTTP Request to the service. If there is an active tracing span, this will
|
||||
* add required headers to the HTTP Request.
|
||||
*/
|
||||
virtual void PropagateToHttpHeaders(Azure::Core::Http::Request& request) = 0;
|
||||
|
||||
virtual ~Span() = default;
|
||||
};
|
||||
|
||||
/**
|
||||
* @brief Options used while creating a span.
|
||||
*
|
||||
*/
|
||||
struct CreateSpanOptions final
|
||||
{
|
||||
/**
|
||||
* @brief The kind of span to be created.
|
||||
*
|
||||
*/
|
||||
SpanKind Kind{SpanKind::Internal};
|
||||
/**
|
||||
* @brief Attributes associated with the span.
|
||||
*
|
||||
*/
|
||||
std::unique_ptr<AttributeSet> Attributes;
|
||||
|
||||
/**
|
||||
* @brief Parent for the newly created span.
|
||||
*/
|
||||
std::shared_ptr<Span> ParentSpan;
|
||||
};
|
||||
|
||||
/**
|
||||
* @brief Tracer - factory for creating span objects.
|
||||
*
|
||||
*/
|
||||
class Tracer {
|
||||
public:
|
||||
/**
|
||||
* @brief Create new Span object.
|
||||
*
|
||||
* @note There is no concept of a "current" span, each span created is a top level span,
|
||||
* unless the CreateSpanOptions has ParentSpan member, in which case the ParentSpan member
|
||||
* will be the parent of the newly created span.
|
||||
*
|
||||
* @param spanName The name of the span to create.
|
||||
* @param options Options to be used when creating the span.
|
||||
* @return std::shared_ptr<Azure::Core::Tracing::Span> Newly created span.
|
||||
*/
|
||||
virtual std::shared_ptr<Span> CreateSpan(
|
||||
std::string const& spanName,
|
||||
CreateSpanOptions const& options) const = 0;
|
||||
|
||||
virtual std::unique_ptr<AttributeSet> CreateAttributeSet() const = 0;
|
||||
virtual ~Tracer() = default;
|
||||
};
|
||||
}}}} // namespace Azure::Core::Tracing::_internal
|
|
@ -3,309 +3,60 @@
|
|||
|
||||
/**
|
||||
* @file
|
||||
* @brief Handling log messages from Azure SDK.
|
||||
* @brief Public TracerProvider type used to represent a tracer provider.
|
||||
*/
|
||||
|
||||
#pragma once
|
||||
|
||||
#include "azure/core/datetime.hpp"
|
||||
#include "azure/core/internal/extendable_enumeration.hpp"
|
||||
#include "azure/core/nullable.hpp"
|
||||
#include "azure/core/url.hpp"
|
||||
#include <array>
|
||||
#include <memory>
|
||||
#include <string>
|
||||
#include <vector>
|
||||
|
||||
// Forward declare Azure::Core::Http::Request to resolve an include file ordering problem.
|
||||
namespace Azure { namespace Core { namespace Http {
|
||||
class Request;
|
||||
}}} // namespace Azure::Core::Http
|
||||
|
||||
namespace Azure { namespace Core { namespace Tracing {
|
||||
|
||||
class TracerProvider;
|
||||
namespace _internal {
|
||||
|
||||
/** The set of attributes to be applied to a Span or Event.
|
||||
*
|
||||
* @details
|
||||
* An AttributeSet represents a set of attributes to be added to a span or
|
||||
* event.
|
||||
*
|
||||
* @note Note that AttributeSets do *NOT* take a copy of their input values,
|
||||
* it is the responsibility of the caller to ensure that the object remains
|
||||
* valid between when it is added to the AttributeSet and when it is added to
|
||||
* a span or event.
|
||||
*
|
||||
* OpenTelemetry property bags can hold:
|
||||
* - bool
|
||||
* - int32_t
|
||||
* - int64_t
|
||||
* - uint64_t
|
||||
* - double
|
||||
* - const char *
|
||||
* - std::string/std::string_view *** Not Implemented
|
||||
* - std::span<const bool> *** Not Implemented
|
||||
* - std::span<const int32_t> *** Not Implemented
|
||||
* - std::span<const int64_t> *** Not Implemented
|
||||
* - std::span<const uint32_t> *** Not Implemented
|
||||
* - std::span<const double> *** Not Implemented
|
||||
* - std::span<std::string/std::string_view> *** Not Implemented
|
||||
* - uint64_t (not fully supported) *** Not Implemented
|
||||
* - std::span<uint64_t> (not fully supported) *** Not Implemented
|
||||
* - std::span<const uint8_t> (not fully supported) *** Not Implemented.
|
||||
*
|
||||
*/
|
||||
class AttributeSet {
|
||||
public:
|
||||
/**
|
||||
* @brief Adds a Boolean attribute to the attribute set.
|
||||
*
|
||||
* @param attributeName Name of attribute to add.
|
||||
* @param value Value of attribute.
|
||||
*/
|
||||
virtual void AddAttribute(std::string const& attributeName, bool value) = 0;
|
||||
/**
|
||||
* @brief Adds a 32bit integer attribute to the attribute set.
|
||||
*
|
||||
* @param attributeName Name of attribute to add.
|
||||
* @param value Value of attribute.
|
||||
*/
|
||||
virtual void AddAttribute(std::string const& attributeName, int32_t value) = 0;
|
||||
/**
|
||||
* @brief Adds a 64bit integer attribute to the attribute set.
|
||||
*
|
||||
* @param attributeName Name of attribute to add.
|
||||
* @param value Value of attribute.
|
||||
*/
|
||||
virtual void AddAttribute(std::string const& attributeName, int64_t value) = 0;
|
||||
/**
|
||||
* @brief Adds an unsigned 64bit integer attribute to the attribute set.
|
||||
*
|
||||
* @param attributeName Name of attribute to add.
|
||||
* @param value Value of attribute.
|
||||
*/
|
||||
virtual void AddAttribute(std::string const& attributeName, uint64_t value) = 0;
|
||||
/**
|
||||
* @brief Adds a 64bit floating point attribute to the attribute set.
|
||||
*
|
||||
* @param attributeName Name of attribute to add.
|
||||
* @param value Value of attribute.
|
||||
*/
|
||||
virtual void AddAttribute(std::string const& attributeName, double value) = 0;
|
||||
/**
|
||||
* @brief Adds a C style string attribute to the attribute set.
|
||||
*
|
||||
* @param attributeName Name of attribute to add.
|
||||
* @param value Value of attribute.
|
||||
*/
|
||||
virtual void AddAttribute(std::string const& attributeName, const char* value) = 0;
|
||||
/**
|
||||
* @brief Adds a C++ string attribute to the attribute set.
|
||||
*
|
||||
* @param attributeName Name of attribute to add.
|
||||
* @param value Value of attribute.
|
||||
*/
|
||||
virtual void AddAttribute(std::string const& attributeName, std::string const& value) = 0;
|
||||
|
||||
/**
|
||||
* @brief destroys an AttributeSet - virtual destructor to enable base class users to
|
||||
* destroy derived classes.
|
||||
*/
|
||||
virtual ~AttributeSet() = default;
|
||||
};
|
||||
|
||||
/** @brief The Type of Span.
|
||||
*/
|
||||
class SpanKind final : public Azure::Core::_internal::ExtendableEnumeration<SpanKind> {
|
||||
public:
|
||||
explicit SpanKind(std::string const& kind) : ExtendableEnumeration(kind) {}
|
||||
SpanKind() = default;
|
||||
|
||||
/**
|
||||
* @brief Represents an "Internal" operation.
|
||||
*
|
||||
*/
|
||||
AZ_CORE_DLLEXPORT const static SpanKind Internal;
|
||||
/**
|
||||
* @brief Represents a request to a remote service.
|
||||
*
|
||||
*/
|
||||
AZ_CORE_DLLEXPORT const static SpanKind Client;
|
||||
/**
|
||||
* @brief Represents a span covering the server side handling of an API call.
|
||||
*
|
||||
*/
|
||||
AZ_CORE_DLLEXPORT const static SpanKind Server;
|
||||
/**
|
||||
* @brief Represents the initiator of an asynchronous request.
|
||||
*
|
||||
*/
|
||||
AZ_CORE_DLLEXPORT const static SpanKind Producer;
|
||||
/**
|
||||
* @brief Represents a span which describes a child of a producer request.
|
||||
*
|
||||
*/
|
||||
AZ_CORE_DLLEXPORT const static SpanKind Consumer;
|
||||
};
|
||||
|
||||
class Tracer;
|
||||
/**
|
||||
* @brief Represents the status of a span.
|
||||
* @brief Trace Provider - factory for creating Tracer objects.
|
||||
*/
|
||||
class SpanStatus final : public Azure::Core::_internal::ExtendableEnumeration<SpanStatus> {
|
||||
|
||||
public:
|
||||
explicit SpanStatus(std::string const& status) : ExtendableEnumeration(status) {}
|
||||
SpanStatus() = default;
|
||||
|
||||
/**
|
||||
* @brief The default status of a span.
|
||||
*/
|
||||
AZ_CORE_DLLEXPORT const static SpanStatus Unset;
|
||||
/**
|
||||
* @brief The operation has completed successfully.
|
||||
*/
|
||||
AZ_CORE_DLLEXPORT const static SpanStatus Ok;
|
||||
/**
|
||||
* @brief The operation contains an error.
|
||||
*/
|
||||
AZ_CORE_DLLEXPORT const static SpanStatus Error;
|
||||
};
|
||||
|
||||
/**
|
||||
* @brief Span - represents a span in tracing.
|
||||
*/
|
||||
class Span {
|
||||
class TracerProviderImpl {
|
||||
public:
|
||||
/**
|
||||
* @brief Signals that the span has now ended.
|
||||
* @brief Create a Tracer object
|
||||
*
|
||||
* @param name Name of the tracer object, typically the name of the Service client
|
||||
* (Azure.Storage.Blobs, for example)
|
||||
* @param version Version of the service client.
|
||||
* @return std::shared_ptr<Azure::Core::Tracing::Tracer>
|
||||
*/
|
||||
virtual void End(Azure::Nullable<Azure::DateTime> endTime = {}) = 0;
|
||||
virtual std::shared_ptr<Azure::Core::Tracing::_internal::Tracer> CreateTracer(
|
||||
std::string const& name,
|
||||
std::string const& version) const = 0;
|
||||
|
||||
/**
|
||||
* @brief Adds a set of attributes to the span.
|
||||
*
|
||||
* @param attributeToAdd Attributes to be added to the span.
|
||||
*/
|
||||
virtual void AddAttributes(AttributeSet const& attributeToAdd) = 0;
|
||||
|
||||
/**
|
||||
* @brief Adds a single string valued attribute to the span.
|
||||
*
|
||||
* @param attributeName Name of the attribute to add.
|
||||
* @param attributeValue value of the attribute.
|
||||
*/
|
||||
virtual void AddAttribute(std::string const& attributeName, std::string const& attributeValue)
|
||||
= 0;
|
||||
|
||||
/**
|
||||
* @brief Adds an event to the span.
|
||||
*
|
||||
* Add an Event to the span. An event is identified by a name and an optional set of
|
||||
* attributes associated with the event.
|
||||
*
|
||||
* @param eventName Name of the event to add.
|
||||
* @param eventAttributes Attributes associated with the event.
|
||||
*/
|
||||
virtual void AddEvent(std::string const& eventName, AttributeSet const& eventAttributes) = 0;
|
||||
|
||||
/**
|
||||
* @brief Adds an event to the span.
|
||||
*
|
||||
* Add an Event to the span. An event is identified by a name
|
||||
*
|
||||
* @param eventName Name of the event to add.
|
||||
*/
|
||||
virtual void AddEvent(std::string const& eventName) = 0;
|
||||
/**
|
||||
* @brief Records an exception occurring in the span.
|
||||
*
|
||||
* @param exception Exception which has occurred.
|
||||
*/
|
||||
virtual void AddEvent(std::exception const& exception) = 0;
|
||||
|
||||
/**
|
||||
* @brief Set the Status of the span
|
||||
*
|
||||
* @param status Updated status of the span.
|
||||
* @param description A description associated with the Status.
|
||||
*/
|
||||
virtual void SetStatus(SpanStatus const& status, std::string const& description = "") = 0;
|
||||
|
||||
/**
|
||||
* @brief Propogate information from the current span to the HTTP request headers.
|
||||
*
|
||||
* @param request HTTP Request to the service. If there is an active tracing span, this will
|
||||
* add required headers to the HTTP Request.
|
||||
*/
|
||||
virtual void PropagateToHttpHeaders(Azure::Core::Http::Request& request) = 0;
|
||||
virtual ~TracerProviderImpl() = default;
|
||||
};
|
||||
|
||||
/**
|
||||
* @brief Options used while creating a span.
|
||||
*
|
||||
*/
|
||||
struct CreateSpanOptions final
|
||||
struct TracerProviderImplGetter
|
||||
{
|
||||
/**
|
||||
* @brief The kind of span to be created.
|
||||
* @brief Returns a TracerProviderImpl from a TracerProvider object.
|
||||
*
|
||||
* @param provider The TracerProvider object.
|
||||
* @returns A TracerProviderImpl implementation.
|
||||
*/
|
||||
SpanKind Kind{SpanKind::Internal};
|
||||
/**
|
||||
* @brief Attributes associated with the span.
|
||||
*
|
||||
*/
|
||||
std::unique_ptr<AttributeSet> Attributes;
|
||||
|
||||
/**
|
||||
* @brief Parent for the newly created span.
|
||||
*/
|
||||
std::shared_ptr<Span> ParentSpan;
|
||||
static std::shared_ptr<TracerProviderImpl> TracerImplFromTracer(
|
||||
std::shared_ptr<TracerProvider> const& provider);
|
||||
};
|
||||
|
||||
/**
|
||||
* @brief Tracer - factory for creating span objects.
|
||||
*
|
||||
*/
|
||||
class Tracer {
|
||||
public:
|
||||
/**
|
||||
* @brief Create new Span object.
|
||||
*
|
||||
* @details Creates a new span object.
|
||||
*
|
||||
* @note There is no concept of a "current" span, each span created is a top level span,
|
||||
* unless the CreateSpanOptions has ParentSpan member, in which case the ParentSpan member
|
||||
* will be the parent of the newly created span.
|
||||
*
|
||||
* @param spanName The name of the span to create.
|
||||
* @param options Options to be used when creating the span.
|
||||
* @return std::shared_ptr<Azure::Core::Tracing::Span> Newly created span.
|
||||
*/
|
||||
virtual std::shared_ptr<Span> CreateSpan(
|
||||
std::string const& spanName,
|
||||
CreateSpanOptions const& options = {}) const = 0;
|
||||
|
||||
virtual std::unique_ptr<AttributeSet> CreateAttributeSet() const = 0;
|
||||
};
|
||||
} // namespace _internal
|
||||
|
||||
/**
|
||||
* @brief Trace Provider - factory for creating Tracer objects.
|
||||
*/
|
||||
class TracerProvider {
|
||||
public:
|
||||
/**
|
||||
* @brief Create a Tracer object
|
||||
*
|
||||
* @param name Name of the tracer object, typically the name of the Service client
|
||||
* (Azure.Storage.Blobs, for example)
|
||||
* @param version Version of the service client.
|
||||
* @return std::shared_ptr<Azure::Core::Tracing::Tracer>
|
||||
*/
|
||||
virtual std::shared_ptr<Azure::Core::Tracing::_internal::Tracer> CreateTracer(
|
||||
std::string const& name,
|
||||
std::string const& version = "") const = 0;
|
||||
class TracerProvider : private _internal::TracerProviderImpl {
|
||||
// Marked TracerImplFromTracer as friend so it can access private members in the class.
|
||||
friend std::shared_ptr<TracerProviderImpl>
|
||||
_internal::TracerProviderImplGetter::TracerImplFromTracer(
|
||||
std::shared_ptr<TracerProvider> const&);
|
||||
};
|
||||
|
||||
}}} // namespace Azure::Core::Tracing
|
||||
|
|
|
@ -13,7 +13,6 @@
|
|||
#include "azure/core/http/policies/policy.hpp"
|
||||
#include "azure/core/internal/tracing/service_tracing.hpp"
|
||||
#include "azure/core/platform.hpp"
|
||||
#include "azure/core/tracing/tracing.hpp"
|
||||
#include <cctype>
|
||||
#include <sstream>
|
||||
|
||||
|
|
|
@ -1,25 +1,15 @@
|
|||
// Copyright (c) Microsoft Corporation. All rights reserved.
|
||||
// SPDX-License-Identifier: MIT
|
||||
|
||||
#include "azure/core/tracing/tracing.hpp"
|
||||
#include "azure/core/context.hpp"
|
||||
#include "azure/core/http/policies/policy.hpp"
|
||||
#include "azure/core/internal/tracing/service_tracing.hpp"
|
||||
#include "azure/core/internal/tracing/tracing_impl.hpp"
|
||||
#include <cctype>
|
||||
#include <sstream>
|
||||
|
||||
namespace Azure { namespace Core { namespace Tracing { namespace _internal {
|
||||
|
||||
const SpanKind SpanKind::Internal("Internal");
|
||||
const SpanKind SpanKind::Client("Client");
|
||||
const SpanKind SpanKind::Consumer("Consumer");
|
||||
const SpanKind SpanKind::Producer("Producer");
|
||||
const SpanKind SpanKind::Server("Server");
|
||||
|
||||
const SpanStatus SpanStatus::Unset("Unset");
|
||||
const SpanStatus SpanStatus::Ok("Ok");
|
||||
const SpanStatus SpanStatus::Error("Error");
|
||||
|
||||
const TracingAttributes TracingAttributes::AzNamespace("az.namespace");
|
||||
const TracingAttributes TracingAttributes::ServiceRequestId("serviceRequestId");
|
||||
const TracingAttributes TracingAttributes::HttpUserAgent("http.user_agent");
|
||||
|
@ -30,6 +20,13 @@ namespace Azure { namespace Core { namespace Tracing { namespace _internal {
|
|||
|
||||
using Azure::Core::Context;
|
||||
|
||||
std::shared_ptr<TracerProviderImpl> TracerProviderImplGetter::TracerImplFromTracer(
|
||||
std::shared_ptr<TracerProvider> const& provider)
|
||||
{
|
||||
const auto pointer = static_cast<TracerProvider*>(provider.get());
|
||||
return std::shared_ptr<TracerProviderImpl>(provider, pointer);
|
||||
}
|
||||
|
||||
TracingContextFactory::TracingContext TracingContextFactory::CreateTracingContext(
|
||||
std::string const& methodName,
|
||||
Azure::Core::Context const& context) const
|
||||
|
|
|
@ -1,7 +1,7 @@
|
|||
// Copyright (c) Microsoft Corporation. All rights reserved.
|
||||
// SPDX-License-Identifier: MIT
|
||||
|
||||
#include "azure/core/tracing/tracing.hpp"
|
||||
#include "azure/core/internal/tracing/tracing_impl.hpp"
|
||||
#include <azure/core/internal/tracing/service_tracing.hpp>
|
||||
#include <gtest/gtest.h>
|
||||
|
||||
|
@ -18,13 +18,15 @@ TEST(TracingContextFactory, ServiceTraceEnums)
|
|||
spanKind = SpanKind::Internal;
|
||||
spanKind = SpanKind::Producer;
|
||||
spanKind = Azure::Core::Tracing::_internal::SpanKind::Server;
|
||||
std::string kindValue = spanKind.ToString();
|
||||
int i = static_cast<int>(spanKind);
|
||||
i += 1;
|
||||
}
|
||||
{
|
||||
SpanStatus spanStatus = SpanStatus::Unset;
|
||||
spanStatus = SpanStatus::Error;
|
||||
spanStatus = SpanStatus::Ok;
|
||||
std::string statusValue = spanStatus.ToString();
|
||||
int i = static_cast<int>(spanStatus);
|
||||
i += 1;
|
||||
}
|
||||
Azure::Core::Tracing::_internal::CreateSpanOptions options;
|
||||
options.Kind = SpanKind::Internal;
|
||||
|
|
Загрузка…
Ссылка в новой задаче