Skip to content

Commit

Permalink
add Decision enum
Browse files Browse the repository at this point in the history
  • Loading branch information
Oliver Zhang committed Jun 17, 2020
1 parent 7b20dc1 commit b206ced
Showing 1 changed file with 23 additions and 5 deletions.
28 changes: 23 additions & 5 deletions sdk/include/opentelemetry/sdk/trace/sampler.h
Original file line number Diff line number Diff line change
@@ -1,6 +1,8 @@
#pragma once

#include "opentelemetry/common/attribute_value.h"
#include "opentelemetry/nostd/string_view.h"
#include "opentelemetry/sdk/common/atomic_shared_ptr.h"
#include "opentelemetry/trace/span.h"
#include "opentelemetry/trace/trace_id.h"
#include "opentelemetry/trace/tracer.h"
Expand All @@ -18,26 +20,33 @@ namespace trace
namespace trace_api = opentelemetry::trace;
class Sampler
{
private:
// Placeholder
class SpanContext
{};

public:
virtual ~Sampler() = default;
/**
* Called during Span creation to make a sampling decision.
*
* @param parentContext TODO: the parent span's SpanContext. null if this is a root
* @param parent_context TODO: the parent span's SpanContext. null if this is a root
* span.
* @param traceId the TraceId for the new Span. This will be identical to that in
* the parentContext, unless this is a root span.
* @param name the name of the new Span.
* @param parentLinks TODO: the parentLinks associated with the new Span.
* @param spanKind the trace_api::SpanKind of the Span.
* @param attributes list of AttributeValue with their keys.
* @param attributes TODO: current map is a placeholder.
* list of AttributeValue with their keys.
* @return sampling decision whether span should be sampled or not.
* @since 0.1.0
*/

virtual SamplingResult ShouldSample(
std::shared_ptr<SpanContext> parent_context,
trace_api::TraceId trace_id,
std::string name,
nostd::string_view name,
trace_api::SpanKind span_kind,
std::map<std::string, common::AttributeValue> attributes) noexcept = 0;

Expand All @@ -54,6 +63,14 @@ class Sampler

class SamplingResult
{
private:
enum Decision
{
NOT_RECORD,
RECORD,
RECORD_AND_SAMPLE
};

public:
// TODO: add Decision enum
virtual ~SamplingResult() = default;
Expand All @@ -62,15 +79,16 @@ class SamplingResult
*
* @return TODO: Decision.
*/
virtual bool GetDecision();
virtual Decision GetDecision() const noexcept = 0;

/**
* Return attributes which will be attached to the span.
*
* TODO: Change return value to nostd::span<std::pair<nostd::string_view, common::AttributeValue>>
* @return attributes added to span. These attributes should be added to the span only for root
* span or when sampling decision isSampled() changes from false to true.
*/
virtual std::map<std::string, common::AttributeValue> GetAttributes();
virtual std::map<std::string, common::AttributeValue> GetAttributes() const noexcept = 0;
};
} // namespace trace
} // namespace sdk
Expand Down

0 comments on commit b206ced

Please sign in to comment.