Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add sampler header file #118

Merged
merged 31 commits into from
Jun 23, 2020
Merged
Changes from 8 commits
Commits
Show all changes
31 commits
Select commit Hold shift + click to select a range
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
96 changes: 96 additions & 0 deletions sdk/include/opentelemetry/sdk/trace/sampler.h
Original file line number Diff line number Diff line change
@@ -0,0 +1,96 @@
#pragma once

#include "opentelemetry/common/attribute_value.h"
#include "opentelemetry/nostd/string_view.h"
#include "opentelemetry/nostd/span.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"
#include "opentelemetry/version.h"
ziqizh marked this conversation as resolved.
Show resolved Hide resolved

#include <map>
#include <memory>
#include <string>

OPENTELEMETRY_BEGIN_NAMESPACE
namespace sdk
{
namespace trace
{
namespace trace_api = opentelemetry::trace;
class Sampler
ziqizh marked this conversation as resolved.
Show resolved Hide resolved
pyohannes marked this conversation as resolved.
Show resolved Hide resolved
{
private:
// Placeholder
class SpanContext
{};

public:
virtual ~Sampler() = default;
/**
* Called during Span creation to make a sampling decision.
*
* @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 TODO: current map is a placeholder.
ziqizh marked this conversation as resolved.
Show resolved Hide resolved
* list of AttributeValue with their keys.
* @return sampling decision whether span should be sampled or not.
* @since 0.1.0
*/

virtual SamplingResult ShouldSample(
ziqizh marked this conversation as resolved.
Show resolved Hide resolved
std::shared_ptr<SpanContext> parent_context,
ziqizh marked this conversation as resolved.
Show resolved Hide resolved
trace_api::TraceId trace_id,
nostd::string_view name,
trace_api::SpanKind span_kind,
nostd::span<std::pair<nostd::string_view, common::AttributeValue>> attributes) noexcept = 0;

/**
* Returns the description of this {@code Sampler}. This may be displayed on debug pages or in the
* logs.
*
* <p>Example: "ProbabilitySampler{0.000100}"
*
* @return the description of this {@code Sampler}.
*/
virtual std::string GetDescription() const noexcept = 0;
};

class SamplingResult
ziqizh marked this conversation as resolved.
Show resolved Hide resolved
{
private:
enum Decision
ziqizh marked this conversation as resolved.
Show resolved Hide resolved
{
NOT_RECORD,
RECORD,
RECORD_AND_SAMPLE
ziqizh marked this conversation as resolved.
Show resolved Hide resolved
};

public:
// TODO: add Decision enum
virtual ~SamplingResult() = default;
/**
* Return sampling decision whether span should be sampled or not.
*
* @return TODO: Decision.
*/
virtual Decision GetDecision() const noexcept = 0;
ziqizh marked this conversation as resolved.
Show resolved Hide resolved

/**
* 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 nostd::span<std::pair<nostd::string_view, common::AttributeValue>> GetAttributes() const noexcept = 0;
};
} // namespace trace
} // namespace sdk
OPENTELEMETRY_END_NAMESPACE