-
Notifications
You must be signed in to change notification settings - Fork 423
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Attempt to allow multiple span processors.
- Migrate SpanProcessor to use `ExportableSpan` - `ExportableSpan` has a registry of `Recordable`s denoated from processors - `ExportableSpan` replaces `Recordable` in `Span` implementation for now - Do some gymnastics around unique_ptr + ownership - Update SDK tests (exporters/ext tests still borked) - For now, `ExportableSpan` has shared ptr reference to originating Tracer. TBD on whether this stays.
- Loading branch information
Showing
12 changed files
with
438 additions
and
87 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
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,73 @@ | ||
#pragma once | ||
|
||
#include "opentelemetry/sdk/trace/recordable.h" | ||
#include "opentelemetry/sdk/trace/tracer.h" | ||
|
||
OPENTELEMETRY_BEGIN_NAMESPACE | ||
namespace sdk | ||
{ | ||
namespace trace | ||
{ | ||
|
||
class SpanExporter; | ||
|
||
/** | ||
* A representation of only information used to export spans. | ||
* | ||
* Unlike `sdk::Span`, this simply tracks the originating recorable + Tracer which generated | ||
* a span. Additionally it delegates Recordable calls to underlying recordadble interfaces. | ||
*/ | ||
class ExportableSpan : public Recordable | ||
{ | ||
public: | ||
explicit ExportableSpan(std::shared_ptr<Tracer> tracer); | ||
virtual ~ExportableSpan(); | ||
|
||
|
||
/** | ||
* Constructs a new unique Exportable span which extracts any exportable associated | ||
* with a given processor. | ||
* | ||
* Note: This is used to coordinate exportable span in a mulit-span processor. | ||
*/ | ||
std::unique_ptr<ExportableSpan> ReleaseExportableSpanFor(const SpanProcessor& processor) noexcept; | ||
/** | ||
* Registers a recordable for a given processor that this span should write data into. | ||
*/ | ||
void RegisterRecordableFor(const SpanProcessor& processor, std::unique_ptr<Recordable> recordable) noexcept; | ||
/** | ||
* Releases ownership of the originally registered recordable. | ||
*/ | ||
std::unique_ptr<Recordable> ReleaseRecordableFor(const SpanProcessor& processor) noexcept; | ||
|
||
|
||
Tracer &GetTracer() { return *tracer_; } | ||
// Note: used in MultiSpanProcessor, clean this up... | ||
std::shared_ptr<Tracer> ShareTracer() { return tracer_; } | ||
|
||
// Recordable Interface | ||
void SetIds(opentelemetry::trace::TraceId trace_id, | ||
opentelemetry::trace::SpanId span_id, | ||
opentelemetry::trace::SpanId parent_span_id) noexcept override; | ||
void SetAttribute(nostd::string_view key, | ||
const opentelemetry::common::AttributeValue &value) noexcept override; | ||
void AddEvent(nostd::string_view name, | ||
core::SystemTimestamp timestamp, | ||
const opentelemetry::common::KeyValueIterable &attributes) noexcept override; | ||
void AddLink(const opentelemetry::trace::SpanContext &span_context, | ||
const opentelemetry::common::KeyValueIterable &attributes) noexcept override; | ||
void SetStatus(opentelemetry::trace::StatusCode code, | ||
nostd::string_view description) noexcept override; | ||
void SetName(nostd::string_view name) noexcept override; | ||
void SetSpanKind(opentelemetry::trace::SpanKind span_kind) noexcept override; | ||
void SetStartTime(opentelemetry::core::SystemTimestamp start_time) noexcept override; | ||
void SetDuration(std::chrono::nanoseconds duration) noexcept override; | ||
private: | ||
std::shared_ptr<Tracer> tracer_; | ||
// TODO - more efficient data structure | ||
std::map<std::size_t, std::unique_ptr<Recordable>> recordables_; | ||
}; | ||
|
||
} // namespace trace | ||
} // namespace sdk | ||
OPENTELEMETRY_END_NAMESPACE |
91 changes: 91 additions & 0 deletions
91
sdk/include/opentelemetry/sdk/trace/multi_span_processor.h
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,91 @@ | ||
#pragma once | ||
|
||
#include "opentelemetry/sdk/common/circular_buffer.h" | ||
#include "opentelemetry/sdk/trace/exporter.h" | ||
#include "opentelemetry/sdk/trace/processor.h" | ||
|
||
#include <atomic> | ||
#include <condition_variable> | ||
#include <thread> | ||
|
||
OPENTELEMETRY_BEGIN_NAMESPACE | ||
namespace sdk | ||
{ | ||
|
||
namespace trace | ||
{ | ||
|
||
/** Instantiation options. */ | ||
struct MultiSpanProcessorOptions {}; | ||
|
||
/** | ||
* This is an implementation of the SpanProcessor which aggregates across an in-order list of | ||
* other span processors. | ||
*/ | ||
class MultiSpanProcessor : public SpanProcessor | ||
{ | ||
public: | ||
/** | ||
* Creates a batch span processor by configuring the specified exporter and other parameters | ||
* as per the official, language-agnostic opentelemetry specs. | ||
* | ||
* @param exporter - The backend exporter to pass the ended spans to. | ||
* @param options - The batch SpanProcessor options. | ||
*/ | ||
MultiSpanProcessor(std::vector<std::unique_ptr<SpanProcessor>> processors, | ||
const MultiSpanProcessorOptions &options = {}); | ||
|
||
/** | ||
* Registeres any needed `Recordable`s for a given span. | ||
*/ | ||
void RegisterRecordable(ExportableSpan& span) noexcept override; | ||
|
||
/** | ||
* Called when a span is started. | ||
* | ||
* NOTE: This method is a no-op. | ||
* | ||
* @param span - The span that just started | ||
* @param parent_context - The parent context of the span that just started | ||
*/ | ||
void OnStart(ExportableSpan &span, | ||
const opentelemetry::trace::SpanContext &parent_context) noexcept override; | ||
|
||
/** | ||
* Called when a span ends. | ||
* | ||
* @param span - A recordable for a span that just ended | ||
*/ | ||
void OnEnd(std::unique_ptr<ExportableSpan> &&span) noexcept override; | ||
|
||
/** | ||
* Export all ended spans that have not been exported yet. | ||
* | ||
* NOTE: Timeout functionality not supported yet. | ||
*/ | ||
bool ForceFlush(std::chrono::microseconds timeout) noexcept override; | ||
|
||
/** | ||
* Shuts down the processor and does any cleanup required. Completely drains the buffer/queue of | ||
* all its ended spans and passes them to the exporter. Any subsequent calls to OnStart, OnEnd, | ||
* ForceFlush or Shutdown will return immediately without doing anything. | ||
* | ||
* NOTE: Timeout functionality not supported yet. | ||
*/ | ||
bool Shutdown(std::chrono::microseconds timeout) noexcept override; | ||
|
||
/** | ||
* Class destructor which invokes the Shutdown() method. The Shutdown() method is supposed to be | ||
* invoked when the Tracer is shutdown (as per other languages), but the C++ Tracer only takes | ||
* shared ownership of the processor, and thus doesn't call Shutdown (as the processor might be | ||
* shared with other Tracers). | ||
*/ | ||
~MultiSpanProcessor(); | ||
|
||
private: | ||
std::vector<std::unique_ptr<SpanProcessor>> processors_; | ||
}; | ||
|
||
} // 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
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
Oops, something went wrong.