forked from open-telemetry/opentelemetry-specification
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Plug the SpanProcessor into the Tracer implementation (open-telemetry#65
- Loading branch information
Johannes Tax
authored
May 5, 2020
1 parent
8683fbf
commit 132aca1
Showing
17 changed files
with
337 additions
and
150 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,71 @@ | ||
#pragma once | ||
|
||
#include <atomic> | ||
#include <memory> | ||
#include "opentelemetry/version.h" | ||
|
||
OPENTELEMETRY_BEGIN_NAMESPACE | ||
namespace sdk | ||
{ | ||
/** | ||
* A wrapper to provide atomic shared pointers. | ||
* | ||
* This wrapper relies on std::atomic for gcc 4.8 and C++20, while using | ||
* specializations of std::atomic_store and std::atomic_load in all other | ||
* instances. | ||
*/ | ||
#if __cplusplus > 201703L | ||
template <class T> | ||
class AtomicSharedPtr | ||
{ | ||
public: | ||
explicit AtomicSharedPtr(std::shared_ptr<T> ptr) noexcept : ptr_{std::move(ptr)} {} | ||
|
||
void store(const std::shared_ptr<T> &other) noexcept | ||
{ | ||
ptr_.store(other, std::memory_order_release); | ||
} | ||
|
||
std::shared_ptr<T> load() const noexcept { return ptr_.load(std::memory_order_acquire); } | ||
|
||
private: | ||
std::atomic<std::shared_ptr<T>> ptr_; | ||
}; | ||
#elif (__GNUC__ == 4 && (__GNUC_MINOR__ >= 8)) | ||
template <class T> | ||
class AtomicSharedPtr | ||
{ | ||
public: | ||
explicit AtomicSharedPtr(std::shared_ptr<T> ptr) noexcept | ||
: ptr_{new std::shared_ptr<T>(std::move(ptr))} | ||
{} | ||
|
||
~AtomicSharedPtr() noexcept { delete ptr_.load(std::memory_order_acquire); } | ||
|
||
void store(const std::shared_ptr<T> &other) noexcept | ||
{ | ||
ptr_.store(new std::shared_ptr<T>(other), std::memory_order_release); | ||
} | ||
|
||
std::shared_ptr<T> load() const noexcept { return *ptr_.load(std::memory_order_acquire); } | ||
|
||
private: | ||
std::atomic<std::shared_ptr<T> *> ptr_; | ||
}; | ||
#else | ||
template <class T> | ||
class AtomicSharedPtr | ||
{ | ||
public: | ||
explicit AtomicSharedPtr(std::shared_ptr<T> ptr) noexcept : ptr_{std::move(ptr)} {} | ||
|
||
void store(const std::shared_ptr<T> &other) noexcept { std::atomic_store(&ptr_, other); } | ||
|
||
std::shared_ptr<T> load() const noexcept { return std::atomic_load(&ptr_); } | ||
|
||
private: | ||
std::shared_ptr<T> ptr_; | ||
}; | ||
#endif | ||
} // namespace sdk | ||
OPENTELEMETRY_END_NAMESPACE |
30 changes: 0 additions & 30 deletions
30
sdk/include/opentelemetry/sdk/trace/default_tracer_provider.h
This file was deleted.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,51 @@ | ||
#pragma once | ||
|
||
#include "opentelemetry/sdk/common/atomic_shared_ptr.h" | ||
#include "opentelemetry/sdk/trace/processor.h" | ||
#include "opentelemetry/trace/tracer.h" | ||
#include "opentelemetry/version.h" | ||
|
||
#include <memory> | ||
|
||
OPENTELEMETRY_BEGIN_NAMESPACE | ||
namespace sdk | ||
{ | ||
namespace trace | ||
{ | ||
class Tracer final : public trace_api::Tracer, public std::enable_shared_from_this<Tracer> | ||
{ | ||
public: | ||
/** | ||
* Initialize a new tracer. | ||
* @param processor The span processor for this tracer. This must not be a | ||
* nullptr. | ||
*/ | ||
explicit Tracer(std::shared_ptr<SpanProcessor> processor) noexcept : processor_{processor} {} | ||
|
||
/** | ||
* Set the span processor associated with this tracer. | ||
* @param processor The new span processor for this tracer. This must not be | ||
* a nullptr. | ||
*/ | ||
void SetProcessor(std::shared_ptr<SpanProcessor> processor) noexcept; | ||
|
||
/** | ||
* Obtain the span processor associated with this tracer. | ||
* @return The span processor for this tracer. | ||
*/ | ||
std::shared_ptr<SpanProcessor> GetProcessor() const noexcept; | ||
|
||
nostd::unique_ptr<trace_api::Span> StartSpan( | ||
nostd::string_view name, | ||
const trace_api::StartSpanOptions &options = {}) noexcept override; | ||
|
||
void ForceFlushWithMicroseconds(uint64_t timeout) noexcept override; | ||
|
||
void CloseWithMicroseconds(uint64_t timeout) noexcept override; | ||
|
||
private: | ||
opentelemetry::sdk::AtomicSharedPtr<SpanProcessor> processor_; | ||
}; | ||
} // namespace trace | ||
} // namespace sdk | ||
OPENTELEMETRY_END_NAMESPACE |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,50 @@ | ||
#pragma once | ||
|
||
#include <map> | ||
#include <memory> | ||
#include <string> | ||
|
||
#include "opentelemetry/nostd/shared_ptr.h" | ||
#include "opentelemetry/sdk/trace/processor.h" | ||
#include "opentelemetry/sdk/trace/tracer.h" | ||
#include "opentelemetry/trace/tracer_provider.h" | ||
|
||
OPENTELEMETRY_BEGIN_NAMESPACE | ||
namespace sdk | ||
{ | ||
namespace trace | ||
{ | ||
class TracerProvider final : public opentelemetry::trace::TracerProvider | ||
{ | ||
public: | ||
/** | ||
* Initialize a new tracer provider. | ||
* @param processor The span processor for this tracer provider. This must | ||
* not be a nullptr. | ||
*/ | ||
explicit TracerProvider(std::shared_ptr<SpanProcessor> processor) noexcept; | ||
|
||
opentelemetry::nostd::shared_ptr<opentelemetry::trace::Tracer> GetTracer( | ||
nostd::string_view library_name, | ||
nostd::string_view library_version = "") noexcept override; | ||
|
||
/** | ||
* Set the span processor associated with this tracer provider. | ||
* @param processor The new span processor for this tracer provider. This | ||
* must not be a nullptr. | ||
*/ | ||
void SetProcessor(std::shared_ptr<SpanProcessor> processor) noexcept; | ||
|
||
/** | ||
* Obtain the span processor associated with this tracer provider. | ||
* @return The span processor for this tracer provider. | ||
*/ | ||
std::shared_ptr<SpanProcessor> GetProcessor() const noexcept; | ||
|
||
private: | ||
opentelemetry::sdk::AtomicSharedPtr<SpanProcessor> processor_; | ||
opentelemetry::nostd::shared_ptr<opentelemetry::trace::Tracer> tracer_; | ||
}; | ||
} // namespace trace | ||
} // namespace sdk | ||
OPENTELEMETRY_END_NAMESPACE |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1 +1 @@ | ||
add_library(opentelemetry_trace default_tracer_provider.cc tracer.cc span.cc) | ||
add_library(opentelemetry_trace tracer_provider.cc tracer.cc span.cc) |
This file was deleted.
Oops, something went wrong.
This file was deleted.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file was deleted.
Oops, something went wrong.
Oops, something went wrong.