From 89ce9f7b17887890d1d7f8b55969a0a676b11420 Mon Sep 17 00:00:00 2001 From: Oliver Zhang Date: Wed, 17 Jun 2020 02:03:21 +0000 Subject: [PATCH 01/23] add sampler header file --- sdk/include/opentelemetry/sdk/trace/sampler.h | 56 +++++++++++++++++++ 1 file changed, 56 insertions(+) create mode 100644 sdk/include/opentelemetry/sdk/trace/sampler.h diff --git a/sdk/include/opentelemetry/sdk/trace/sampler.h b/sdk/include/opentelemetry/sdk/trace/sampler.h new file mode 100644 index 0000000000..cb884cc14b --- /dev/null +++ b/sdk/include/opentelemetry/sdk/trace/sampler.h @@ -0,0 +1,56 @@ +#pragma once + +#include "opentelemetry/version.h" +#include "opentelemetry/common/attribute_value.h" + +#include +#include +#include + +OPENTELEMETRY_BEGIN_NAMESPACE +namespace sdk +{ +namespace trace +{ +class Sampler +{ +public: + /** + * Initialize a new tracer. + * @param processor The span processor for this tracer. This must not be a + * nullptr. + */ + virtual Decision shouldSample(); + + /** + * Returns the description of this {@code Sampler}. This may be displayed on debug pages or in the + * logs. + * + *

Example: "ProbabilitySampler{0.000100}" + * + * @return the description of this {@code Sampler}. + */ + virtual std::string getDescription(); +}; + +class Decision +{ +public: + /** + * Return sampling decision whether span should be sampled or not. + * + * @return sampling decision. + */ + virtual bool isSampled(); + + /** + * Return tags which will be attached to the span. + * + * @return attributes added to span. These attributes should be added to the span only for root + * span or when sampling decision {@link #isSampled()} changes from false to true. + */ + virtual std::map getAttributes(); +}; +} // namespace trace +} // namespace sdk +OPENTELEMETRY_END_NAMESPACE From e65cf5c20745e4235d883e3d3223804e10e73dc5 Mon Sep 17 00:00:00 2001 From: Oliver Zhang Date: Wed, 17 Jun 2020 02:51:09 +0000 Subject: [PATCH 02/23] add param and comments --- sdk/include/opentelemetry/sdk/trace/sampler.h | 44 ++++++++++++++----- 1 file changed, 33 insertions(+), 11 deletions(-) diff --git a/sdk/include/opentelemetry/sdk/trace/sampler.h b/sdk/include/opentelemetry/sdk/trace/sampler.h index cb884cc14b..784628a529 100644 --- a/sdk/include/opentelemetry/sdk/trace/sampler.h +++ b/sdk/include/opentelemetry/sdk/trace/sampler.h @@ -1,10 +1,13 @@ #pragma once -#include "opentelemetry/version.h" #include "opentelemetry/common/attribute_value.h" +#include "opentelemetry/trace/span.h" +#include "opentelemetry/trace/trace_id.h" +#include "opentelemetry/trace/tracer.h" +#include "opentelemetry/version.h" -#include #include +#include #include OPENTELEMETRY_BEGIN_NAMESPACE @@ -12,15 +15,31 @@ namespace sdk { namespace trace { +namespace trace_api = opentelemetry::trace; class Sampler { public: + virtual ~Sampler() = default; /** - * Initialize a new tracer. - * @param processor The span processor for this tracer. This must not be a - * nullptr. + * Called during Span creation to make a sampling decision. + * + * @param parentContext 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. + * @return sampling decision whether span should be sampled or not. + * @since 0.1.0 */ - virtual Decision shouldSample(); + + virtual Decision shouldSample( + trace_api::TraceId trace_id, + std::string name, + trace_api::SpanKind span_kind, + std::map attributes) noexcept = 0; /** * Returns the description of this {@code Sampler}. This may be displayed on debug pages or in the @@ -36,6 +55,7 @@ class Sampler class Decision { public: + virtual ~Decision() = default; /** * Return sampling decision whether span should be sampled or not. * @@ -44,13 +64,15 @@ class Decision virtual bool isSampled(); /** - * Return tags which will be attached to the span. - * - * @return attributes added to span. These attributes should be added to the span only for root - * span or when sampling decision {@link #isSampled()} changes from false to true. - */ + * Return tags which will be attached to the span. + * + * @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 getAttributes(); }; + +class } // namespace trace } // namespace sdk OPENTELEMETRY_END_NAMESPACE From 7b20dc1aa4408195e4bfe461577b4fc69e1ff299 Mon Sep 17 00:00:00 2001 From: Oliver Zhang Date: Wed, 17 Jun 2020 15:07:57 +0000 Subject: [PATCH 03/23] change class definition --- sdk/include/opentelemetry/sdk/trace/sampler.h | 19 +++++++++---------- 1 file changed, 9 insertions(+), 10 deletions(-) diff --git a/sdk/include/opentelemetry/sdk/trace/sampler.h b/sdk/include/opentelemetry/sdk/trace/sampler.h index 784628a529..22ec6d52f1 100644 --- a/sdk/include/opentelemetry/sdk/trace/sampler.h +++ b/sdk/include/opentelemetry/sdk/trace/sampler.h @@ -35,7 +35,7 @@ class Sampler * @since 0.1.0 */ - virtual Decision shouldSample( + virtual SamplingResult ShouldSample( trace_api::TraceId trace_id, std::string name, trace_api::SpanKind span_kind, @@ -49,30 +49,29 @@ class Sampler * * @return the description of this {@code Sampler}. */ - virtual std::string getDescription(); + virtual std::string GetDescription() const noexcept = 0; }; -class Decision +class SamplingResult { public: - virtual ~Decision() = default; + // TODO: add Decision enum + virtual ~SamplingResult() = default; /** * Return sampling decision whether span should be sampled or not. * - * @return sampling decision. + * @return TODO: Decision. */ - virtual bool isSampled(); + virtual bool GetDecision(); /** - * Return tags which will be attached to the span. + * Return attributes which will be attached to the span. * * @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 getAttributes(); + virtual std::map GetAttributes(); }; - -class } // namespace trace } // namespace sdk OPENTELEMETRY_END_NAMESPACE From 81cb054318fdd54414cbd69069917795ceee680b Mon Sep 17 00:00:00 2001 From: Oliver Zhang Date: Wed, 17 Jun 2020 17:22:53 +0000 Subject: [PATCH 04/23] add Decision enum --- sdk/include/opentelemetry/sdk/trace/sampler.h | 6 ++++-- 1 file changed, 4 insertions(+), 2 deletions(-) diff --git a/sdk/include/opentelemetry/sdk/trace/sampler.h b/sdk/include/opentelemetry/sdk/trace/sampler.h index 22ec6d52f1..8d21b7cc5f 100644 --- a/sdk/include/opentelemetry/sdk/trace/sampler.h +++ b/sdk/include/opentelemetry/sdk/trace/sampler.h @@ -54,6 +54,8 @@ class Sampler class SamplingResult { +private: + enum Decision {NOT_RECORD, RECORD, RECORD_AND_SAMPLE}; public: // TODO: add Decision enum virtual ~SamplingResult() = default; @@ -62,7 +64,7 @@ class SamplingResult * * @return TODO: Decision. */ - virtual bool GetDecision(); + virtual Decision GetDecision() const noexcept = 0; /** * Return attributes which will be attached to the span. @@ -70,7 +72,7 @@ class SamplingResult * @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 GetAttributes(); + virtual std::map GetAttributes() const noexcept = 0; }; } // namespace trace } // namespace sdk From b206ced0cd0c7508c4ee732341c47fdd5fb9262f Mon Sep 17 00:00:00 2001 From: Oliver Zhang Date: Wed, 17 Jun 2020 17:22:53 +0000 Subject: [PATCH 05/23] add Decision enum --- sdk/include/opentelemetry/sdk/trace/sampler.h | 28 +++++++++++++++---- 1 file changed, 23 insertions(+), 5 deletions(-) diff --git a/sdk/include/opentelemetry/sdk/trace/sampler.h b/sdk/include/opentelemetry/sdk/trace/sampler.h index 22ec6d52f1..374c333acd 100644 --- a/sdk/include/opentelemetry/sdk/trace/sampler.h +++ b/sdk/include/opentelemetry/sdk/trace/sampler.h @@ -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" @@ -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 parent_context, trace_api::TraceId trace_id, - std::string name, + nostd::string_view name, trace_api::SpanKind span_kind, std::map attributes) noexcept = 0; @@ -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; @@ -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> * @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 GetAttributes(); + virtual std::map GetAttributes() const noexcept = 0; }; } // namespace trace } // namespace sdk From 279ef0e470e86a1a2fd273472384e7c6f2b0676b Mon Sep 17 00:00:00 2001 From: Oliver Zhang Date: Wed, 17 Jun 2020 19:51:41 +0000 Subject: [PATCH 06/23] minor tweaks --- sdk/include/opentelemetry/sdk/trace/sampler.h | 36 ++++++++----------- 1 file changed, 15 insertions(+), 21 deletions(-) diff --git a/sdk/include/opentelemetry/sdk/trace/sampler.h b/sdk/include/opentelemetry/sdk/trace/sampler.h index c64e46525c..b333aa3406 100644 --- a/sdk/include/opentelemetry/sdk/trace/sampler.h +++ b/sdk/include/opentelemetry/sdk/trace/sampler.h @@ -1,8 +1,8 @@ #pragma once #include "opentelemetry/common/attribute_value.h" -#include "opentelemetry/nostd/string_view.h" #include "opentelemetry/nostd/span.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" @@ -31,16 +31,16 @@ class Sampler /** * 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 + * @param parent_context TODO: a shared pointer of the SpanContext of a parent Span. + * null if this is a root span. + * @param trace_id 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. * list of AttributeValue with their keys. - * @return sampling decision whether span should be sampled or not. + * @param links TODO: Collection of links that will be associated with the Span to be created. + * @return sampling result whether span should be sampled or not. * @since 0.1.0 */ @@ -52,44 +52,38 @@ class Sampler nostd::span> attributes) noexcept = 0; /** - * Returns the description of this {@code Sampler}. This may be displayed on debug pages or in the - * logs. + * Returns the sampler name or short description with the configuration. + * This may be displayed on debug pages or in the logs. * - *

Example: "ProbabilitySampler{0.000100}" - * - * @return the description of this {@code Sampler}. + * @return the description of this Sampler. */ virtual std::string GetDescription() const noexcept = 0; }; class SamplingResult { -private: +public: enum Decision { NOT_RECORD, RECORD, RECORD_AND_SAMPLE }; - -public: - // TODO: add Decision enum virtual ~SamplingResult() = default; /** - * Return sampling decision whether span should be sampled or not. + * Return sampling decision. * - * @return TODO: Decision. + * @return Decision. */ virtual Decision GetDecision() const noexcept = 0; /** * Return attributes which will be attached to the span. * - * TODO: Change return value to nostd::span> - * @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. + * @return the immutable list of attributes added to span. */ - virtual nostd::span> GetAttributes() const noexcept = 0; + virtual nostd::span> GetAttributes() const + noexcept = 0; }; } // namespace trace } // namespace sdk From bc14502fc93e4091ee614f7636cc19d1e89e118b Mon Sep 17 00:00:00 2001 From: Oliver Zhang Date: Wed, 17 Jun 2020 02:03:21 +0000 Subject: [PATCH 07/23] add sampler header file --- sdk/include/opentelemetry/sdk/trace/sampler.h | 56 +++++++++++++++++++ 1 file changed, 56 insertions(+) create mode 100644 sdk/include/opentelemetry/sdk/trace/sampler.h diff --git a/sdk/include/opentelemetry/sdk/trace/sampler.h b/sdk/include/opentelemetry/sdk/trace/sampler.h new file mode 100644 index 0000000000..cb884cc14b --- /dev/null +++ b/sdk/include/opentelemetry/sdk/trace/sampler.h @@ -0,0 +1,56 @@ +#pragma once + +#include "opentelemetry/version.h" +#include "opentelemetry/common/attribute_value.h" + +#include +#include +#include + +OPENTELEMETRY_BEGIN_NAMESPACE +namespace sdk +{ +namespace trace +{ +class Sampler +{ +public: + /** + * Initialize a new tracer. + * @param processor The span processor for this tracer. This must not be a + * nullptr. + */ + virtual Decision shouldSample(); + + /** + * Returns the description of this {@code Sampler}. This may be displayed on debug pages or in the + * logs. + * + *

Example: "ProbabilitySampler{0.000100}" + * + * @return the description of this {@code Sampler}. + */ + virtual std::string getDescription(); +}; + +class Decision +{ +public: + /** + * Return sampling decision whether span should be sampled or not. + * + * @return sampling decision. + */ + virtual bool isSampled(); + + /** + * Return tags which will be attached to the span. + * + * @return attributes added to span. These attributes should be added to the span only for root + * span or when sampling decision {@link #isSampled()} changes from false to true. + */ + virtual std::map getAttributes(); +}; +} // namespace trace +} // namespace sdk +OPENTELEMETRY_END_NAMESPACE From f705b3567042114e017f0577c7c2f980ce9d36b1 Mon Sep 17 00:00:00 2001 From: Oliver Zhang Date: Wed, 17 Jun 2020 02:51:09 +0000 Subject: [PATCH 08/23] add param and comments --- sdk/include/opentelemetry/sdk/trace/sampler.h | 44 ++++++++++++++----- 1 file changed, 33 insertions(+), 11 deletions(-) diff --git a/sdk/include/opentelemetry/sdk/trace/sampler.h b/sdk/include/opentelemetry/sdk/trace/sampler.h index cb884cc14b..784628a529 100644 --- a/sdk/include/opentelemetry/sdk/trace/sampler.h +++ b/sdk/include/opentelemetry/sdk/trace/sampler.h @@ -1,10 +1,13 @@ #pragma once -#include "opentelemetry/version.h" #include "opentelemetry/common/attribute_value.h" +#include "opentelemetry/trace/span.h" +#include "opentelemetry/trace/trace_id.h" +#include "opentelemetry/trace/tracer.h" +#include "opentelemetry/version.h" -#include #include +#include #include OPENTELEMETRY_BEGIN_NAMESPACE @@ -12,15 +15,31 @@ namespace sdk { namespace trace { +namespace trace_api = opentelemetry::trace; class Sampler { public: + virtual ~Sampler() = default; /** - * Initialize a new tracer. - * @param processor The span processor for this tracer. This must not be a - * nullptr. + * Called during Span creation to make a sampling decision. + * + * @param parentContext 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. + * @return sampling decision whether span should be sampled or not. + * @since 0.1.0 */ - virtual Decision shouldSample(); + + virtual Decision shouldSample( + trace_api::TraceId trace_id, + std::string name, + trace_api::SpanKind span_kind, + std::map attributes) noexcept = 0; /** * Returns the description of this {@code Sampler}. This may be displayed on debug pages or in the @@ -36,6 +55,7 @@ class Sampler class Decision { public: + virtual ~Decision() = default; /** * Return sampling decision whether span should be sampled or not. * @@ -44,13 +64,15 @@ class Decision virtual bool isSampled(); /** - * Return tags which will be attached to the span. - * - * @return attributes added to span. These attributes should be added to the span only for root - * span or when sampling decision {@link #isSampled()} changes from false to true. - */ + * Return tags which will be attached to the span. + * + * @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 getAttributes(); }; + +class } // namespace trace } // namespace sdk OPENTELEMETRY_END_NAMESPACE From 8111e930f38f543c30c7bb9f5d734935e2b8ff9f Mon Sep 17 00:00:00 2001 From: Oliver Zhang Date: Wed, 17 Jun 2020 15:07:57 +0000 Subject: [PATCH 09/23] change class definition --- sdk/include/opentelemetry/sdk/trace/sampler.h | 19 +++++++++---------- 1 file changed, 9 insertions(+), 10 deletions(-) diff --git a/sdk/include/opentelemetry/sdk/trace/sampler.h b/sdk/include/opentelemetry/sdk/trace/sampler.h index 784628a529..22ec6d52f1 100644 --- a/sdk/include/opentelemetry/sdk/trace/sampler.h +++ b/sdk/include/opentelemetry/sdk/trace/sampler.h @@ -35,7 +35,7 @@ class Sampler * @since 0.1.0 */ - virtual Decision shouldSample( + virtual SamplingResult ShouldSample( trace_api::TraceId trace_id, std::string name, trace_api::SpanKind span_kind, @@ -49,30 +49,29 @@ class Sampler * * @return the description of this {@code Sampler}. */ - virtual std::string getDescription(); + virtual std::string GetDescription() const noexcept = 0; }; -class Decision +class SamplingResult { public: - virtual ~Decision() = default; + // TODO: add Decision enum + virtual ~SamplingResult() = default; /** * Return sampling decision whether span should be sampled or not. * - * @return sampling decision. + * @return TODO: Decision. */ - virtual bool isSampled(); + virtual bool GetDecision(); /** - * Return tags which will be attached to the span. + * Return attributes which will be attached to the span. * * @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 getAttributes(); + virtual std::map GetAttributes(); }; - -class } // namespace trace } // namespace sdk OPENTELEMETRY_END_NAMESPACE From e4ac2503565cb0c14b1ffa8da45ef03440017863 Mon Sep 17 00:00:00 2001 From: Oliver Zhang Date: Wed, 17 Jun 2020 17:22:53 +0000 Subject: [PATCH 10/23] add Decision enum --- sdk/include/opentelemetry/sdk/trace/sampler.h | 28 +++++++++++++++---- 1 file changed, 23 insertions(+), 5 deletions(-) diff --git a/sdk/include/opentelemetry/sdk/trace/sampler.h b/sdk/include/opentelemetry/sdk/trace/sampler.h index 22ec6d52f1..374c333acd 100644 --- a/sdk/include/opentelemetry/sdk/trace/sampler.h +++ b/sdk/include/opentelemetry/sdk/trace/sampler.h @@ -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" @@ -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 parent_context, trace_api::TraceId trace_id, - std::string name, + nostd::string_view name, trace_api::SpanKind span_kind, std::map attributes) noexcept = 0; @@ -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; @@ -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> * @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 GetAttributes(); + virtual std::map GetAttributes() const noexcept = 0; }; } // namespace trace } // namespace sdk From 48d46959ef2c77aef772727e3d8f5a1a129ce3f6 Mon Sep 17 00:00:00 2001 From: Oliver Zhang Date: Wed, 17 Jun 2020 17:22:53 +0000 Subject: [PATCH 11/23] add Decision enum --- sdk/include/opentelemetry/sdk/trace/sampler.h | 5 +---- 1 file changed, 1 insertion(+), 4 deletions(-) diff --git a/sdk/include/opentelemetry/sdk/trace/sampler.h b/sdk/include/opentelemetry/sdk/trace/sampler.h index 374c333acd..dee3d7a2ce 100644 --- a/sdk/include/opentelemetry/sdk/trace/sampler.h +++ b/sdk/include/opentelemetry/sdk/trace/sampler.h @@ -63,16 +63,13 @@ class Sampler class SamplingResult { -private: +public: enum Decision { NOT_RECORD, RECORD, RECORD_AND_SAMPLE }; - -public: - // TODO: add Decision enum virtual ~SamplingResult() = default; /** * Return sampling decision whether span should be sampled or not. From 7c4ac5a36ce457098f48823d2828ac9d6b1391e4 Mon Sep 17 00:00:00 2001 From: Oliver Zhang Date: Wed, 17 Jun 2020 19:51:41 +0000 Subject: [PATCH 12/23] minor tweaks --- sdk/include/opentelemetry/sdk/trace/sampler.h | 30 +++++++++---------- 1 file changed, 14 insertions(+), 16 deletions(-) diff --git a/sdk/include/opentelemetry/sdk/trace/sampler.h b/sdk/include/opentelemetry/sdk/trace/sampler.h index dee3d7a2ce..52ee1f7824 100644 --- a/sdk/include/opentelemetry/sdk/trace/sampler.h +++ b/sdk/include/opentelemetry/sdk/trace/sampler.h @@ -1,6 +1,7 @@ #pragma once #include "opentelemetry/common/attribute_value.h" +#include "opentelemetry/nostd/span.h" #include "opentelemetry/nostd/string_view.h" #include "opentelemetry/sdk/common/atomic_shared_ptr.h" #include "opentelemetry/trace/span.h" @@ -30,16 +31,16 @@ class Sampler /** * 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 + * @param parent_context TODO: a shared pointer of the SpanContext of a parent Span. + * null if this is a root span. + * @param trace_id 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. * list of AttributeValue with their keys. - * @return sampling decision whether span should be sampled or not. + * @param links TODO: Collection of links that will be associated with the Span to be created. + * @return sampling result whether span should be sampled or not. * @since 0.1.0 */ @@ -51,12 +52,10 @@ class Sampler std::map attributes) noexcept = 0; /** - * Returns the description of this {@code Sampler}. This may be displayed on debug pages or in the - * logs. + * Returns the sampler name or short description with the configuration. + * This may be displayed on debug pages or in the logs. * - *

Example: "ProbabilitySampler{0.000100}" - * - * @return the description of this {@code Sampler}. + * @return the description of this Sampler. */ virtual std::string GetDescription() const noexcept = 0; }; @@ -72,20 +71,19 @@ class SamplingResult }; virtual ~SamplingResult() = default; /** - * Return sampling decision whether span should be sampled or not. + * Return sampling decision. * - * @return TODO: Decision. + * @return Decision. */ virtual Decision GetDecision() const noexcept = 0; /** * Return attributes which will be attached to the span. * - * TODO: Change return value to nostd::span> - * @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. + * @return the immutable list of attributes added to span. */ - virtual std::map GetAttributes() const noexcept = 0; + virtual nostd::span> GetAttributes() const + noexcept = 0; }; } // namespace trace } // namespace sdk From 503edb698cd176e5660035a5db64aaf232254e7d Mon Sep 17 00:00:00 2001 From: Oliver Zhang Date: Thu, 18 Jun 2020 19:11:45 +0000 Subject: [PATCH 13/23] change enum to enum class --- sdk/include/opentelemetry/sdk/trace/sampler.h | 28 +++++++++---------- 1 file changed, 13 insertions(+), 15 deletions(-) diff --git a/sdk/include/opentelemetry/sdk/trace/sampler.h b/sdk/include/opentelemetry/sdk/trace/sampler.h index 40600e6a00..da1ab6ae74 100644 --- a/sdk/include/opentelemetry/sdk/trace/sampler.h +++ b/sdk/include/opentelemetry/sdk/trace/sampler.h @@ -19,21 +19,21 @@ namespace sdk namespace trace { namespace trace_api = opentelemetry::trace; +/** + * NOT_RECORD - IsRecording() == false, + * span will not be recorded and all events and attributes will be dropped. + * RECORD - IsRecording() == true, but Sampled flag MUST NOT be set. + * RECORD_AND_SAMPLED - IsRecording() == true AND Sampled flag` MUST be set. + */ +enum class Decision +{ + NOT_RECORD, + RECORD, + RECORD_AND_SAMPLE +}; class SamplingResult { public: - /** - * NOT_RECORD - IsRecording() == false, - * span will not be recorded and all events and attributes will be dropped. - * RECORD - IsRecording() == true, but Sampled flag MUST NOT be set. - * RECORD_AND_SAMPLED - IsRecording() == true AND Sampled flag` MUST be set. - */ - enum Decision - { - NOT_RECORD, - RECORD, - RECORD_AND_SAMPLE - }; virtual ~SamplingResult() = default; /** * Return sampling decision. @@ -53,12 +53,10 @@ class SamplingResult class Sampler { -private: +public: // Placeholder class SpanContext {}; - -public: virtual ~Sampler() = default; /** * Called during Span creation to make a sampling decision. From 7c204b816526dd0f9149a70f16a297a811d6392f Mon Sep 17 00:00:00 2001 From: Oliver Zhang Date: Fri, 19 Jun 2020 15:06:38 +0000 Subject: [PATCH 14/23] change sampling result to struct --- sdk/include/opentelemetry/sdk/trace/sampler.h | 36 ++++++------------- 1 file changed, 11 insertions(+), 25 deletions(-) diff --git a/sdk/include/opentelemetry/sdk/trace/sampler.h b/sdk/include/opentelemetry/sdk/trace/sampler.h index da1ab6ae74..b817d226f5 100644 --- a/sdk/include/opentelemetry/sdk/trace/sampler.h +++ b/sdk/include/opentelemetry/sdk/trace/sampler.h @@ -20,7 +20,7 @@ namespace trace { namespace trace_api = opentelemetry::trace; /** - * NOT_RECORD - IsRecording() == false, + * NOT_RECORD - IsRecording() == false, * span will not be recorded and all events and attributes will be dropped. * RECORD - IsRecording() == true, but Sampled flag MUST NOT be set. * RECORD_AND_SAMPLED - IsRecording() == true AND Sampled flag` MUST be set. @@ -31,24 +31,11 @@ enum class Decision RECORD, RECORD_AND_SAMPLE }; -class SamplingResult -{ -public: - virtual ~SamplingResult() = default; - /** - * Return sampling decision. - * - * @return Decision. - */ - virtual Decision GetDecision() const noexcept = 0; - /** - * Return attributes which will be attached to the span. - * - * @return the immutable list of attributes added to span. - */ - virtual nostd::span> GetAttributes() const - noexcept = 0; +struct SamplingResult +{ + Decision decision; + std::unique_ptr> attributes; }; class Sampler @@ -61,28 +48,27 @@ class Sampler /** * Called during Span creation to make a sampling decision. * - * @param parent_context TODO: a shared pointer of the SpanContext of a parent Span. + * @param parent_context TODO: a shared pointer of the SpanContext of a parent Span. * null if this is a root span. * @param trace_id 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 spanKind the trace_api::SpanKind of the Span. - * @param attributes TODO: current map is a placeholder. - * list of AttributeValue with their keys. + * @param attributes TODO: list of AttributeValue with their keys. * @param links TODO: Collection of links that will be associated with the Span to be created. * @return sampling result whether span should be sampled or not. * @since 0.1.0 */ - virtual std::shared_ptr ShouldSample( - const SpanContext* parent_context, + virtual SamplingResult ShouldSample( + const SpanContext *parent_context, trace_api::TraceId trace_id, nostd::string_view name, trace_api::SpanKind span_kind, - nostd::span> attributes) noexcept = 0; + nostd::span attributes) noexcept = 0; /** - * Returns the sampler name or short description with the configuration. + * Returns the sampler name or short description with the configuration. * This may be displayed on debug pages or in the logs. * * @return the description of this Sampler. From 6d4632beccd25d223e6fb0d8c09dfd69de4e27ef Mon Sep 17 00:00:00 2001 From: Oliver Zhang Date: Fri, 19 Jun 2020 18:37:23 +0000 Subject: [PATCH 15/23] change param --- sdk/include/opentelemetry/sdk/trace/sampler.h | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/sdk/include/opentelemetry/sdk/trace/sampler.h b/sdk/include/opentelemetry/sdk/trace/sampler.h index b817d226f5..6c2e77c079 100644 --- a/sdk/include/opentelemetry/sdk/trace/sampler.h +++ b/sdk/include/opentelemetry/sdk/trace/sampler.h @@ -54,7 +54,7 @@ class Sampler * the parentContext, unless this is a root span. * @param name the name of the new Span. * @param spanKind the trace_api::SpanKind of the Span. - * @param attributes TODO: list of AttributeValue with their keys. + * @param attributes list of AttributeValue with their keys. * @param links TODO: Collection of links that will be associated with the Span to be created. * @return sampling result whether span should be sampled or not. * @since 0.1.0 @@ -65,7 +65,7 @@ class Sampler trace_api::TraceId trace_id, nostd::string_view name, trace_api::SpanKind span_kind, - nostd::span attributes) noexcept = 0; + const nostd::span &attributes) noexcept = 0; /** * Returns the sampler name or short description with the configuration. From 71f8d9d6e245abc07f6fd50e3e555d75c98a8898 Mon Sep 17 00:00:00 2001 From: Oliver Zhang Date: Fri, 19 Jun 2020 18:50:07 +0000 Subject: [PATCH 16/23] add AttributeKeyValue placeholder --- sdk/include/opentelemetry/sdk/trace/sampler.h | 17 ++++++++++++++--- 1 file changed, 14 insertions(+), 3 deletions(-) diff --git a/sdk/include/opentelemetry/sdk/trace/sampler.h b/sdk/include/opentelemetry/sdk/trace/sampler.h index 6c2e77c079..ab490571e0 100644 --- a/sdk/include/opentelemetry/sdk/trace/sampler.h +++ b/sdk/include/opentelemetry/sdk/trace/sampler.h @@ -32,10 +32,20 @@ enum class Decision RECORD_AND_SAMPLE }; +/** + * A placeholder for common::AttributeKeyValue + * A key/value pair that can be used to set attributes. + */ +struct AttributeKeyValue { + nostd::string_view key; + AttributeValue value; +}; + struct SamplingResult { Decision decision; - std::unique_ptr> attributes; + // TODO: Change AttributeKeyValue to common::AttributeKeyValue + std::unique_ptr> attributes; }; class Sampler @@ -54,7 +64,8 @@ class Sampler * the parentContext, unless this is a root span. * @param name the name of the new Span. * @param spanKind the trace_api::SpanKind of the Span. - * @param attributes list of AttributeValue with their keys. + * @param attributes // TODO: Change AttributeKeyValue to common::AttributeKeyValue + * list of AttributeValue with their keys. * @param links TODO: Collection of links that will be associated with the Span to be created. * @return sampling result whether span should be sampled or not. * @since 0.1.0 @@ -65,7 +76,7 @@ class Sampler trace_api::TraceId trace_id, nostd::string_view name, trace_api::SpanKind span_kind, - const nostd::span &attributes) noexcept = 0; + const nostd::span &attributes) noexcept = 0; /** * Returns the sampler name or short description with the configuration. From 590be00fa409efbbd4c947344400c149734b202a Mon Sep 17 00:00:00 2001 From: Oliver Zhang Date: Fri, 19 Jun 2020 19:20:51 +0000 Subject: [PATCH 17/23] add namespace --- sdk/include/opentelemetry/sdk/trace/sampler.h | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/sdk/include/opentelemetry/sdk/trace/sampler.h b/sdk/include/opentelemetry/sdk/trace/sampler.h index ab490571e0..abe02fc6de 100644 --- a/sdk/include/opentelemetry/sdk/trace/sampler.h +++ b/sdk/include/opentelemetry/sdk/trace/sampler.h @@ -38,7 +38,7 @@ enum class Decision */ struct AttributeKeyValue { nostd::string_view key; - AttributeValue value; + common::AttributeValue value; }; struct SamplingResult From 8d43a4aa264196fa2bed62adf08f34a57d37ac67 Mon Sep 17 00:00:00 2001 From: Oliver Zhang Date: Mon, 22 Jun 2020 15:15:08 +0000 Subject: [PATCH 18/23] style fix --- sdk/include/opentelemetry/sdk/trace/sampler.h | 5 ++--- 1 file changed, 2 insertions(+), 3 deletions(-) diff --git a/sdk/include/opentelemetry/sdk/trace/sampler.h b/sdk/include/opentelemetry/sdk/trace/sampler.h index abe02fc6de..81a9ef9d52 100644 --- a/sdk/include/opentelemetry/sdk/trace/sampler.h +++ b/sdk/include/opentelemetry/sdk/trace/sampler.h @@ -52,8 +52,7 @@ class Sampler { public: // Placeholder - class SpanContext - {}; + class SpanContext; virtual ~Sampler() = default; /** * Called during Span creation to make a sampling decision. @@ -64,7 +63,7 @@ class Sampler * the parentContext, unless this is a root span. * @param name the name of the new Span. * @param spanKind the trace_api::SpanKind of the Span. - * @param attributes // TODO: Change AttributeKeyValue to common::AttributeKeyValue + * @param attributes TODO: Change AttributeKeyValue to common::AttributeKeyValue * list of AttributeValue with their keys. * @param links TODO: Collection of links that will be associated with the Span to be created. * @return sampling result whether span should be sampled or not. From 0f1e88deac48010a784c1ed5d0b9859a41281253 Mon Sep 17 00:00:00 2001 From: Oliver Zhang Date: Mon, 22 Jun 2020 23:31:06 +0000 Subject: [PATCH 19/23] minor change --- sdk/include/opentelemetry/sdk/trace/sampler.h | 41 +++++++------------ 1 file changed, 14 insertions(+), 27 deletions(-) diff --git a/sdk/include/opentelemetry/sdk/trace/sampler.h b/sdk/include/opentelemetry/sdk/trace/sampler.h index 81a9ef9d52..856a970733 100644 --- a/sdk/include/opentelemetry/sdk/trace/sampler.h +++ b/sdk/include/opentelemetry/sdk/trace/sampler.h @@ -3,10 +3,8 @@ #include "opentelemetry/common/attribute_value.h" #include "opentelemetry/nostd/span.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" #include "opentelemetry/version.h" #include @@ -19,45 +17,35 @@ namespace sdk namespace trace { namespace trace_api = opentelemetry::trace; -/** - * NOT_RECORD - IsRecording() == false, - * span will not be recorded and all events and attributes will be dropped. - * RECORD - IsRecording() == true, but Sampled flag MUST NOT be set. - * RECORD_AND_SAMPLED - IsRecording() == true AND Sampled flag` MUST be set. - */ + enum class Decision { + // IsRecording() == false, span will not be recorded and all events and attributes will be + // dropped. NOT_RECORD, + // IsRecording() == true, but Sampled flag MUST NOT be set. RECORD, + // IsRecording() == true AND Sampled flag` MUST be set. RECORD_AND_SAMPLE }; -/** - * A placeholder for common::AttributeKeyValue - * A key/value pair that can be used to set attributes. - */ -struct AttributeKeyValue { - nostd::string_view key; - common::AttributeValue value; -}; - struct SamplingResult { Decision decision; - // TODO: Change AttributeKeyValue to common::AttributeKeyValue - std::unique_ptr> attributes; + // A set of span Attributes that will also be added to the Span + std::unique_ptr> attributes; }; class Sampler { public: - // Placeholder + // TODO: Remove this placeholder with real class class SpanContext; virtual ~Sampler() = default; /** * Called during Span creation to make a sampling decision. * - * @param parent_context TODO: a shared pointer of the SpanContext of a parent Span. + * @param parent_context a const pointer of the SpanContext of a parent Span. * null if this is a root span. * @param trace_id the TraceId for the new Span. This will be identical to that in * the parentContext, unless this is a root span. @@ -70,12 +58,11 @@ class Sampler * @since 0.1.0 */ - virtual SamplingResult ShouldSample( - const SpanContext *parent_context, - trace_api::TraceId trace_id, - nostd::string_view name, - trace_api::SpanKind span_kind, - const nostd::span &attributes) noexcept = 0; + virtual SamplingResult ShouldSample(const SpanContext *parent_context, + trace_api::TraceId trace_id, + nostd::string_view name, + trace_api::SpanKind span_kind, + const KeyValueIterable &attributes) noexcept = 0; /** * Returns the sampler name or short description with the configuration. From 205d4688dda9653d97348ea15c84e3ae07713152 Mon Sep 17 00:00:00 2001 From: Oliver Zhang Date: Mon, 22 Jun 2020 23:32:11 +0000 Subject: [PATCH 20/23] minor change --- sdk/include/opentelemetry/sdk/trace/sampler.h | 2 -- 1 file changed, 2 deletions(-) diff --git a/sdk/include/opentelemetry/sdk/trace/sampler.h b/sdk/include/opentelemetry/sdk/trace/sampler.h index 856a970733..1173e27fd7 100644 --- a/sdk/include/opentelemetry/sdk/trace/sampler.h +++ b/sdk/include/opentelemetry/sdk/trace/sampler.h @@ -1,8 +1,6 @@ #pragma once #include "opentelemetry/common/attribute_value.h" -#include "opentelemetry/nostd/span.h" -#include "opentelemetry/nostd/string_view.h" #include "opentelemetry/trace/span.h" #include "opentelemetry/trace/trace_id.h" #include "opentelemetry/version.h" From 8ecce7e7d1f02c7298f074c95d4b768569212466 Mon Sep 17 00:00:00 2001 From: Oliver Zhang Date: Tue, 23 Jun 2020 18:15:39 +0000 Subject: [PATCH 21/23] add comments --- sdk/include/opentelemetry/sdk/trace/sampler.h | 16 +++++++++++++--- 1 file changed, 13 insertions(+), 3 deletions(-) diff --git a/sdk/include/opentelemetry/sdk/trace/sampler.h b/sdk/include/opentelemetry/sdk/trace/sampler.h index 1173e27fd7..c28fac3ac2 100644 --- a/sdk/include/opentelemetry/sdk/trace/sampler.h +++ b/sdk/include/opentelemetry/sdk/trace/sampler.h @@ -16,10 +16,13 @@ namespace trace { namespace trace_api = opentelemetry::trace; +/** + * A sampling Decision for a Span to be created. + */ enum class Decision { // IsRecording() == false, span will not be recorded and all events and attributes will be - // dropped. + // dropped. NOT_RECORD, // IsRecording() == true, but Sampled flag MUST NOT be set. RECORD, @@ -27,6 +30,10 @@ enum class Decision RECORD_AND_SAMPLE }; +/** + * The output of ShouldSample. + * it contains a sampling Decision and a set of span Attributes. + */ struct SamplingResult { Decision decision; @@ -34,6 +41,10 @@ struct SamplingResult std::unique_ptr> attributes; }; +/** + * Sampler interface allows users to create custom samplers which will return a sampling + * SamplingResult based on information that is typically available just before the Span was created. + */ class Sampler { public: @@ -49,8 +60,7 @@ class Sampler * the parentContext, unless this is a root span. * @param name the name of the new Span. * @param spanKind the trace_api::SpanKind of the Span. - * @param attributes TODO: Change AttributeKeyValue to common::AttributeKeyValue - * list of AttributeValue with their keys. + * @param attributes list of AttributeValue with their keys. * @param links TODO: Collection of links that will be associated with the Span to be created. * @return sampling result whether span should be sampled or not. * @since 0.1.0 From 885c7b48548b857e6ef3a980acf932cca4020c25 Mon Sep 17 00:00:00 2001 From: Oliver Zhang Date: Tue, 23 Jun 2020 18:31:54 +0000 Subject: [PATCH 22/23] add comments --- sdk/include/opentelemetry/sdk/trace/sampler.h | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/sdk/include/opentelemetry/sdk/trace/sampler.h b/sdk/include/opentelemetry/sdk/trace/sampler.h index c28fac3ac2..1d79674fb9 100644 --- a/sdk/include/opentelemetry/sdk/trace/sampler.h +++ b/sdk/include/opentelemetry/sdk/trace/sampler.h @@ -32,7 +32,7 @@ enum class Decision /** * The output of ShouldSample. - * it contains a sampling Decision and a set of span Attributes. + * It contains a sampling Decision and a set of Span Attributes. */ struct SamplingResult { @@ -42,7 +42,7 @@ struct SamplingResult }; /** - * Sampler interface allows users to create custom samplers which will return a sampling + * The Sampler interface allows users to create custom samplers which will return a * SamplingResult based on information that is typically available just before the Span was created. */ class Sampler From 15f2b2a7111ccaa9c9cb6e3a9df4c47cbfa53528 Mon Sep 17 00:00:00 2001 From: Oliver Zhang Date: Tue, 23 Jun 2020 18:47:48 +0000 Subject: [PATCH 23/23] add comments --- sdk/include/opentelemetry/sdk/trace/sampler.h | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/sdk/include/opentelemetry/sdk/trace/sampler.h b/sdk/include/opentelemetry/sdk/trace/sampler.h index 1d79674fb9..2cf24b4b40 100644 --- a/sdk/include/opentelemetry/sdk/trace/sampler.h +++ b/sdk/include/opentelemetry/sdk/trace/sampler.h @@ -37,7 +37,7 @@ enum class Decision struct SamplingResult { Decision decision; - // A set of span Attributes that will also be added to the Span + // A set of span Attributes that will also be added to the Span. Can be nullptr. std::unique_ptr> attributes; };