From 89ce9f7b17887890d1d7f8b55969a0a676b11420 Mon Sep 17 00:00:00 2001 From: Oliver Zhang Date: Wed, 17 Jun 2020 02:03:21 +0000 Subject: [PATCH 01/40] 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/40] 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/40] 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/40] 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/40] 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/40] 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/40] 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/40] 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/40] 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/40] 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/40] 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/40] 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/40] 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/40] 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/40] 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/40] 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/40] 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 11b4420bc1443ce372db67367d83d6339214850a Mon Sep 17 00:00:00 2001 From: Oliver Zhang Date: Thu, 18 Jun 2020 19:08:12 +0000 Subject: [PATCH 18/40] define functions --- .../sdk/trace/always_on_sampler.h | 53 +++++++++++++++++++ sdk/src/trace/always_on_sampler.cc | 28 ++++++++++ 2 files changed, 81 insertions(+) create mode 100644 sdk/include/opentelemetry/sdk/trace/always_on_sampler.h create mode 100644 sdk/src/trace/always_on_sampler.cc diff --git a/sdk/include/opentelemetry/sdk/trace/always_on_sampler.h b/sdk/include/opentelemetry/sdk/trace/always_on_sampler.h new file mode 100644 index 0000000000..bf4e959e1c --- /dev/null +++ b/sdk/include/opentelemetry/sdk/trace/always_on_sampler.h @@ -0,0 +1,53 @@ +#pragma once + +#include "opentelemetry/common/attribute_value.h" +#include "opentelemetry/sdk/common/atomic_shared_ptr.h" +#include "opentelemetry/sdk/trace/sampler.h" +#include "opentelemetry/trace/span.h" +#include "opentelemetry/trace/tracer.h" +#include "opentelemetry/version.h" + +#include + +OPENTELEMETRY_BEGIN_NAMESPACE +namespace sdk +{ +namespace trace +{ +class AlwaysOnSamplingResult final : public sdk::trace::SamplingResult +{ + Decision GetDecision() const noexcept override; + nostd::span> GetAttributes() const + noexcept override; +}; + +class AlwaysOnSampler final : public sdk::trace::Sampler +{ +public: + /** + * Default constructor + */ + AlwaysOnSampler() noexcept {} + /** + * Returned SamplingResult always has RECORD_AND_SAMPLED + * as the Decision + */ + std::shared_ptr ShouldSample( + const SpanContext *parent_context, + trace_api::TraceId trace_id, + nostd::string_view name, + trace_api::SpanKind span_kind, + nostd::span> + attributes) noexcept override; + + /** + * @return Description MUST be AlwaysOnSampler + */ + std::string GetDescription() const noexcept override; + +private: + opentelemetry::sdk::AtomicSharedPtr sampling_result_; +} +} // namespace trace +} // namespace sdk +OPENTELEMETRY_END_NAMESPACE diff --git a/sdk/src/trace/always_on_sampler.cc b/sdk/src/trace/always_on_sampler.cc new file mode 100644 index 0000000000..876e6f9587 --- /dev/null +++ b/sdk/src/trace/always_on_sampler.cc @@ -0,0 +1,28 @@ +#include "opentelemetry/sdk/trace/always_on_sampler.h" + +#include "opentelemetry/sdk/common/atomic_shared_ptr.h" +#include "opentelemetry/version.h" + +OPENTELEMETRY_BEGIN_NAMESPACE +namespace sdk +{ +namespace trace +{ +AlwaysOnSamplingResult::Decision AlwaysOnSamplingResult::GetDecision() const noexcept +{ + return +} + +AlwaysOnSampler::AlwaysOnSampler() noexcept + : sampling_result_(std::shared_ptr(new SamplingResult)) +{} +std::shared_ptr AlwaysOnSampler::ShouldSample( + const SpanContext *parent_context, + trace_api::TraceId trace_id, + nostd::string_view name, + trace_api::SpanKind span_kind, + nostd::span> attributes) noexcept +{} +} // namespace trace +} // namespace sdk +OPENTELEMETRY_END_NAMESPACE From a5fb523fb24e1d3750bcfb49f98017e953b17a61 Mon Sep 17 00:00:00 2001 From: Oliver Zhang Date: Fri, 19 Jun 2020 18:29:35 +0000 Subject: [PATCH 19/40] remove sampling result class --- sdk/include/opentelemetry/sdk/trace/always_on_sampler.h | 7 ------- 1 file changed, 7 deletions(-) diff --git a/sdk/include/opentelemetry/sdk/trace/always_on_sampler.h b/sdk/include/opentelemetry/sdk/trace/always_on_sampler.h index bf4e959e1c..a81d4c48d0 100644 --- a/sdk/include/opentelemetry/sdk/trace/always_on_sampler.h +++ b/sdk/include/opentelemetry/sdk/trace/always_on_sampler.h @@ -14,13 +14,6 @@ namespace sdk { namespace trace { -class AlwaysOnSamplingResult final : public sdk::trace::SamplingResult -{ - Decision GetDecision() const noexcept override; - nostd::span> GetAttributes() const - noexcept override; -}; - class AlwaysOnSampler final : public sdk::trace::Sampler { public: From fe817e5f33c889f3f24961f2425a92d095a34393 Mon Sep 17 00:00:00 2001 From: Oliver Zhang Date: Fri, 19 Jun 2020 19:13:42 +0000 Subject: [PATCH 20/40] add always on sampler --- .../sdk/trace/always_on_sampler.h | 10 +++----- sdk/src/trace/always_on_sampler.cc | 23 +++++++++++-------- 2 files changed, 16 insertions(+), 17 deletions(-) diff --git a/sdk/include/opentelemetry/sdk/trace/always_on_sampler.h b/sdk/include/opentelemetry/sdk/trace/always_on_sampler.h index a81d4c48d0..94eb03290f 100644 --- a/sdk/include/opentelemetry/sdk/trace/always_on_sampler.h +++ b/sdk/include/opentelemetry/sdk/trace/always_on_sampler.h @@ -25,22 +25,18 @@ class AlwaysOnSampler final : public sdk::trace::Sampler * Returned SamplingResult always has RECORD_AND_SAMPLED * as the Decision */ - std::shared_ptr ShouldSample( + SamplingResult ShouldSample( const SpanContext *parent_context, trace_api::TraceId trace_id, nostd::string_view name, trace_api::SpanKind span_kind, - nostd::span> - attributes) noexcept override; + const nostd::span &attributes) noexcept override; /** * @return Description MUST be AlwaysOnSampler */ std::string GetDescription() const noexcept override; - -private: - opentelemetry::sdk::AtomicSharedPtr sampling_result_; -} +}; } // namespace trace } // namespace sdk OPENTELEMETRY_END_NAMESPACE diff --git a/sdk/src/trace/always_on_sampler.cc b/sdk/src/trace/always_on_sampler.cc index 876e6f9587..139a42d32b 100644 --- a/sdk/src/trace/always_on_sampler.cc +++ b/sdk/src/trace/always_on_sampler.cc @@ -8,21 +8,24 @@ namespace sdk { namespace trace { -AlwaysOnSamplingResult::Decision AlwaysOnSamplingResult::GetDecision() const noexcept -{ - return -} +AlwaysOnSampler::AlwaysOnSampler() noexcept {} -AlwaysOnSampler::AlwaysOnSampler() noexcept - : sampling_result_(std::shared_ptr(new SamplingResult)) -{} -std::shared_ptr AlwaysOnSampler::ShouldSample( +/** + * Return RECORD_AND_SAMPLE and an empty set of attributes + */ +SamplingResult AlwaysOnSampler::ShouldSample( const SpanContext *parent_context, trace_api::TraceId trace_id, nostd::string_view name, trace_api::SpanKind span_kind, - nostd::span> attributes) noexcept -{} + const nostd::span &attributes) noexcept +{ + return + { + sdk::trace::Decision::RECORD_AND_SAMPLE, + std::unique_ptr>(new nostd::span()) + }; +} } // namespace trace } // namespace sdk OPENTELEMETRY_END_NAMESPACE From 78b5be06e1cae34501b6ba131ba0c853ca56fd44 Mon Sep 17 00:00:00 2001 From: Oliver Zhang Date: Fri, 19 Jun 2020 19:23:10 +0000 Subject: [PATCH 21/40] add function --- sdk/include/opentelemetry/sdk/trace/always_on_sampler.h | 4 ---- sdk/src/trace/always_on_sampler.cc | 7 +++++-- 2 files changed, 5 insertions(+), 6 deletions(-) diff --git a/sdk/include/opentelemetry/sdk/trace/always_on_sampler.h b/sdk/include/opentelemetry/sdk/trace/always_on_sampler.h index 94eb03290f..31902c5aa4 100644 --- a/sdk/include/opentelemetry/sdk/trace/always_on_sampler.h +++ b/sdk/include/opentelemetry/sdk/trace/always_on_sampler.h @@ -17,10 +17,6 @@ namespace trace class AlwaysOnSampler final : public sdk::trace::Sampler { public: - /** - * Default constructor - */ - AlwaysOnSampler() noexcept {} /** * Returned SamplingResult always has RECORD_AND_SAMPLED * as the Decision diff --git a/sdk/src/trace/always_on_sampler.cc b/sdk/src/trace/always_on_sampler.cc index 139a42d32b..74180d3282 100644 --- a/sdk/src/trace/always_on_sampler.cc +++ b/sdk/src/trace/always_on_sampler.cc @@ -8,8 +8,6 @@ namespace sdk { namespace trace { -AlwaysOnSampler::AlwaysOnSampler() noexcept {} - /** * Return RECORD_AND_SAMPLE and an empty set of attributes */ @@ -26,6 +24,11 @@ SamplingResult AlwaysOnSampler::ShouldSample( std::unique_ptr>(new nostd::span()) }; } + +std::string AlwaysOnSampler::GetDescription() const noexcept +{ + return std::string("AlwaysOnSampler"); +} } // namespace trace } // namespace sdk OPENTELEMETRY_END_NAMESPACE From 8d43a4aa264196fa2bed62adf08f34a57d37ac67 Mon Sep 17 00:00:00 2001 From: Oliver Zhang Date: Mon, 22 Jun 2020 15:15:08 +0000 Subject: [PATCH 22/40] 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 fff8bda9070fae3141437efb495ee9707b210f5c Mon Sep 17 00:00:00 2001 From: Oliver Zhang Date: Mon, 22 Jun 2020 17:21:09 +0000 Subject: [PATCH 23/40] add test --- sdk/test/trace/BUILD | 11 +++++++ sdk/test/trace/always_on_sampler_test.cc | 37 ++++++++++++++++++++++++ 2 files changed, 48 insertions(+) create mode 100644 sdk/test/trace/always_on_sampler_test.cc diff --git a/sdk/test/trace/BUILD b/sdk/test/trace/BUILD index 6748cde17f..8da0d4b02c 100644 --- a/sdk/test/trace/BUILD +++ b/sdk/test/trace/BUILD @@ -41,3 +41,14 @@ cc_test( "@com_google_googletest//:gtest_main", ], ) + +cc_test( + name = "always_on_sampler_test", + srcs = [ + "always_on_sampler_test.cc", + ], + deps = [ + "//sdk/src/trace", + "@com_google_googletest//:gtest_main", + ], +) diff --git a/sdk/test/trace/always_on_sampler_test.cc b/sdk/test/trace/always_on_sampler_test.cc new file mode 100644 index 0000000000..73ef8622b7 --- /dev/null +++ b/sdk/test/trace/always_on_sampler_test.cc @@ -0,0 +1,37 @@ +#include "opentelemetry/sdk/trace/always_on_sampler.h" +#include "opentelemetry/nostd/span.h" + +#include + +using namespace opentelemetry::sdk::trace; +using namespace opentelemetry::nostd; + +TEST(AlwaysOnSampler, ShouldSample) +{ + AlwaysOnSampler sampler; + + // A buffer of trace_id with no specific meaning + constexpr uint8_t buf[] = {0, 1, 2, 3, 4, 5, 6, 7, 0, 1, 2, 3, 4, 5, 6, 7}; + + trace_api::TraceId trace_id_invalid; + trace_api::TraceId trace_id_valid(buf); + + auto sampling_result = sampler.ShouldSample(nullptr, trace_id_invalid, "invalid trace id test", + trace_api::SpanKind::kServer, span()); + + ASSERT_EQ(Decision::RECORD_AND_SAMPLE, sampling_result.decision); + ASSERT_EQ(0, sampling_result.attributes->size()); + + sampling_result = sampler.ShouldSample(nullptr, trace_id_valid, "valid trace id test", + trace_api::SpanKind::kServer, span()); + + ASSERT_EQ(Decision::RECORD_AND_SAMPLE, sampling_result.decision); + ASSERT_EQ(0, sampling_result.attributes->size()); +} + +TEST(AlwaysOnSampler, GetDescription) +{ + AlwaysOnSampler sampler; + + ASSERT_EQ("AlwaysOnSampler", sampler.GetDescription()); +} \ No newline at end of file From 82ccca09d8d1bde404b9ad7c7c8ebe94e9517898 Mon Sep 17 00:00:00 2001 From: Oliver Zhang Date: Mon, 22 Jun 2020 17:25:35 +0000 Subject: [PATCH 24/40] minor syntax change --- sdk/include/opentelemetry/sdk/trace/always_on_sampler.h | 7 ------- sdk/src/trace/always_on_sampler.cc | 2 +- 2 files changed, 1 insertion(+), 8 deletions(-) diff --git a/sdk/include/opentelemetry/sdk/trace/always_on_sampler.h b/sdk/include/opentelemetry/sdk/trace/always_on_sampler.h index 31902c5aa4..fcca41c247 100644 --- a/sdk/include/opentelemetry/sdk/trace/always_on_sampler.h +++ b/sdk/include/opentelemetry/sdk/trace/always_on_sampler.h @@ -1,13 +1,6 @@ #pragma once -#include "opentelemetry/common/attribute_value.h" -#include "opentelemetry/sdk/common/atomic_shared_ptr.h" #include "opentelemetry/sdk/trace/sampler.h" -#include "opentelemetry/trace/span.h" -#include "opentelemetry/trace/tracer.h" -#include "opentelemetry/version.h" - -#include OPENTELEMETRY_BEGIN_NAMESPACE namespace sdk diff --git a/sdk/src/trace/always_on_sampler.cc b/sdk/src/trace/always_on_sampler.cc index 74180d3282..8c60ec4c3c 100644 --- a/sdk/src/trace/always_on_sampler.cc +++ b/sdk/src/trace/always_on_sampler.cc @@ -27,7 +27,7 @@ SamplingResult AlwaysOnSampler::ShouldSample( std::string AlwaysOnSampler::GetDescription() const noexcept { - return std::string("AlwaysOnSampler"); + return "AlwaysOnSampler"; } } // namespace trace } // namespace sdk From 249e5be33ebe2e576fa65f15fb3065d093314e31 Mon Sep 17 00:00:00 2001 From: Oliver Zhang Date: Mon, 22 Jun 2020 17:37:06 +0000 Subject: [PATCH 25/40] Revert "minor syntax change" This reverts commit 82ccca09d8d1bde404b9ad7c7c8ebe94e9517898. --- sdk/include/opentelemetry/sdk/trace/always_on_sampler.h | 7 +++++++ sdk/src/trace/always_on_sampler.cc | 2 +- 2 files changed, 8 insertions(+), 1 deletion(-) diff --git a/sdk/include/opentelemetry/sdk/trace/always_on_sampler.h b/sdk/include/opentelemetry/sdk/trace/always_on_sampler.h index fcca41c247..31902c5aa4 100644 --- a/sdk/include/opentelemetry/sdk/trace/always_on_sampler.h +++ b/sdk/include/opentelemetry/sdk/trace/always_on_sampler.h @@ -1,6 +1,13 @@ #pragma once +#include "opentelemetry/common/attribute_value.h" +#include "opentelemetry/sdk/common/atomic_shared_ptr.h" #include "opentelemetry/sdk/trace/sampler.h" +#include "opentelemetry/trace/span.h" +#include "opentelemetry/trace/tracer.h" +#include "opentelemetry/version.h" + +#include OPENTELEMETRY_BEGIN_NAMESPACE namespace sdk diff --git a/sdk/src/trace/always_on_sampler.cc b/sdk/src/trace/always_on_sampler.cc index 8c60ec4c3c..74180d3282 100644 --- a/sdk/src/trace/always_on_sampler.cc +++ b/sdk/src/trace/always_on_sampler.cc @@ -27,7 +27,7 @@ SamplingResult AlwaysOnSampler::ShouldSample( std::string AlwaysOnSampler::GetDescription() const noexcept { - return "AlwaysOnSampler"; + return std::string("AlwaysOnSampler"); } } // namespace trace } // namespace sdk From d9ddf89ffd14516ebcd3158e11d6ce26edde1eec Mon Sep 17 00:00:00 2001 From: Oliver Zhang Date: Mon, 22 Jun 2020 17:57:56 +0000 Subject: [PATCH 26/40] add CMake rule --- sdk/test/trace/CMakeLists.txt | 2 +- sdk/test/trace/always_on_sampler_test.cc | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/sdk/test/trace/CMakeLists.txt b/sdk/test/trace/CMakeLists.txt index 5bca38440a..e332fa633b 100644 --- a/sdk/test/trace/CMakeLists.txt +++ b/sdk/test/trace/CMakeLists.txt @@ -1,5 +1,5 @@ foreach(testname tracer_provider_test span_data_test simple_processor_test - tracer_test) + tracer_test always_on_sampler_test) add_executable(${testname} "${testname}.cc") target_link_libraries(${testname} ${GTEST_BOTH_LIBRARIES} ${CMAKE_THREAD_LIBS_INIT} opentelemetry_trace) diff --git a/sdk/test/trace/always_on_sampler_test.cc b/sdk/test/trace/always_on_sampler_test.cc index 73ef8622b7..c9f1dfb4eb 100644 --- a/sdk/test/trace/always_on_sampler_test.cc +++ b/sdk/test/trace/always_on_sampler_test.cc @@ -34,4 +34,4 @@ TEST(AlwaysOnSampler, GetDescription) AlwaysOnSampler sampler; ASSERT_EQ("AlwaysOnSampler", sampler.GetDescription()); -} \ No newline at end of file +} From 620056cab9a94ba78c542a258a55a2a19b74e123 Mon Sep 17 00:00:00 2001 From: Oliver Zhang Date: Mon, 22 Jun 2020 18:16:01 +0000 Subject: [PATCH 27/40] add CMake rule --- sdk/src/trace/CMakeLists.txt | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/sdk/src/trace/CMakeLists.txt b/sdk/src/trace/CMakeLists.txt index 455665be68..b8cd56a0d2 100644 --- a/sdk/src/trace/CMakeLists.txt +++ b/sdk/src/trace/CMakeLists.txt @@ -1 +1 @@ -add_library(opentelemetry_trace tracer_provider.cc tracer.cc span.cc) +add_library(opentelemetry_trace tracer_provider.cc tracer.cc span.cc always_on_sampler.cc) From cddfc4e8e691c3d263fc4a5da244dd11110974f2 Mon Sep 17 00:00:00 2001 From: Oliver Zhang Date: Tue, 23 Jun 2020 23:24:29 +0000 Subject: [PATCH 28/40] update struct --- .../opentelemetry/sdk/trace/always_on_sampler.h | 2 +- sdk/include/opentelemetry/sdk/trace/sampler.h | 2 +- sdk/src/trace/always_on_sampler.cc | 10 ++-------- sdk/test/trace/always_on_sampler_test.cc | 2 +- 4 files changed, 5 insertions(+), 11 deletions(-) diff --git a/sdk/include/opentelemetry/sdk/trace/always_on_sampler.h b/sdk/include/opentelemetry/sdk/trace/always_on_sampler.h index 31902c5aa4..2fdf81f883 100644 --- a/sdk/include/opentelemetry/sdk/trace/always_on_sampler.h +++ b/sdk/include/opentelemetry/sdk/trace/always_on_sampler.h @@ -26,7 +26,7 @@ class AlwaysOnSampler final : public sdk::trace::Sampler trace_api::TraceId trace_id, nostd::string_view name, trace_api::SpanKind span_kind, - const nostd::span &attributes) noexcept override; + const KeyValueIterable &attributes) noexcept override; /** * @return Description MUST be AlwaysOnSampler diff --git a/sdk/include/opentelemetry/sdk/trace/sampler.h b/sdk/include/opentelemetry/sdk/trace/sampler.h index 2cf24b4b40..2ff10c0bb9 100644 --- a/sdk/include/opentelemetry/sdk/trace/sampler.h +++ b/sdk/include/opentelemetry/sdk/trace/sampler.h @@ -38,7 +38,7 @@ struct SamplingResult { Decision decision; // A set of span Attributes that will also be added to the Span. Can be nullptr. - std::unique_ptr> attributes; + std::unique_ptr> attributes; }; /** diff --git a/sdk/src/trace/always_on_sampler.cc b/sdk/src/trace/always_on_sampler.cc index 74180d3282..b547da10e7 100644 --- a/sdk/src/trace/always_on_sampler.cc +++ b/sdk/src/trace/always_on_sampler.cc @@ -1,6 +1,4 @@ #include "opentelemetry/sdk/trace/always_on_sampler.h" - -#include "opentelemetry/sdk/common/atomic_shared_ptr.h" #include "opentelemetry/version.h" OPENTELEMETRY_BEGIN_NAMESPACE @@ -16,13 +14,9 @@ SamplingResult AlwaysOnSampler::ShouldSample( trace_api::TraceId trace_id, nostd::string_view name, trace_api::SpanKind span_kind, - const nostd::span &attributes) noexcept + const KeyValueIterable &attributes) noexcept { - return - { - sdk::trace::Decision::RECORD_AND_SAMPLE, - std::unique_ptr>(new nostd::span()) - }; + return{sdk::trace::Decision::RECORD_AND_SAMPLE, nullptr}; } std::string AlwaysOnSampler::GetDescription() const noexcept diff --git a/sdk/test/trace/always_on_sampler_test.cc b/sdk/test/trace/always_on_sampler_test.cc index c9f1dfb4eb..94ef0b0b61 100644 --- a/sdk/test/trace/always_on_sampler_test.cc +++ b/sdk/test/trace/always_on_sampler_test.cc @@ -26,7 +26,7 @@ TEST(AlwaysOnSampler, ShouldSample) trace_api::SpanKind::kServer, span()); ASSERT_EQ(Decision::RECORD_AND_SAMPLE, sampling_result.decision); - ASSERT_EQ(0, sampling_result.attributes->size()); + ASSERT_EQ(nullptr, sampling_result.attributes); } TEST(AlwaysOnSampler, GetDescription) From 9bd90ca4b0bea7894ce99926efd8b18c25979fb7 Mon Sep 17 00:00:00 2001 From: Oliver Zhang Date: Tue, 23 Jun 2020 23:31:07 +0000 Subject: [PATCH 29/40] update imports' --- sdk/include/opentelemetry/sdk/trace/always_on_sampler.h | 2 +- sdk/include/opentelemetry/sdk/trace/sampler.h | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/sdk/include/opentelemetry/sdk/trace/always_on_sampler.h b/sdk/include/opentelemetry/sdk/trace/always_on_sampler.h index 2fdf81f883..dd6462fb57 100644 --- a/sdk/include/opentelemetry/sdk/trace/always_on_sampler.h +++ b/sdk/include/opentelemetry/sdk/trace/always_on_sampler.h @@ -26,7 +26,7 @@ class AlwaysOnSampler final : public sdk::trace::Sampler trace_api::TraceId trace_id, nostd::string_view name, trace_api::SpanKind span_kind, - const KeyValueIterable &attributes) noexcept override; + const trace_api::KeyValueIterable &attributes) noexcept override; /** * @return Description MUST be AlwaysOnSampler diff --git a/sdk/include/opentelemetry/sdk/trace/sampler.h b/sdk/include/opentelemetry/sdk/trace/sampler.h index 2ff10c0bb9..5db444020c 100644 --- a/sdk/include/opentelemetry/sdk/trace/sampler.h +++ b/sdk/include/opentelemetry/sdk/trace/sampler.h @@ -70,7 +70,7 @@ class Sampler trace_api::TraceId trace_id, nostd::string_view name, trace_api::SpanKind span_kind, - const KeyValueIterable &attributes) noexcept = 0; + const trace_api::KeyValueIterable &attributes) noexcept = 0; /** * Returns the sampler name or short description with the configuration. From db4b68ba0bc0540e01cbca9b9a320e96a0e83e13 Mon Sep 17 00:00:00 2001 From: Oliver Zhang Date: Tue, 23 Jun 2020 23:33:36 +0000 Subject: [PATCH 30/40] update namespace --- sdk/src/trace/always_on_sampler.cc | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/sdk/src/trace/always_on_sampler.cc b/sdk/src/trace/always_on_sampler.cc index b547da10e7..7e50b6752b 100644 --- a/sdk/src/trace/always_on_sampler.cc +++ b/sdk/src/trace/always_on_sampler.cc @@ -14,7 +14,7 @@ SamplingResult AlwaysOnSampler::ShouldSample( trace_api::TraceId trace_id, nostd::string_view name, trace_api::SpanKind span_kind, - const KeyValueIterable &attributes) noexcept + const trace_api::KeyValueIterable &attributes) noexcept { return{sdk::trace::Decision::RECORD_AND_SAMPLE, nullptr}; } From 36a2c85f2fb7a47a563804b77e8970d9054870fb Mon Sep 17 00:00:00 2001 From: Oliver Zhang Date: Tue, 23 Jun 2020 23:57:39 +0000 Subject: [PATCH 31/40] modify test file --- sdk/test/trace/always_on_sampler_test.cc | 12 ++++++++---- 1 file changed, 8 insertions(+), 4 deletions(-) diff --git a/sdk/test/trace/always_on_sampler_test.cc b/sdk/test/trace/always_on_sampler_test.cc index 94ef0b0b61..f2fdd036e5 100644 --- a/sdk/test/trace/always_on_sampler_test.cc +++ b/sdk/test/trace/always_on_sampler_test.cc @@ -2,6 +2,7 @@ #include "opentelemetry/nostd/span.h" #include +#include using namespace opentelemetry::sdk::trace; using namespace opentelemetry::nostd; @@ -15,15 +16,18 @@ TEST(AlwaysOnSampler, ShouldSample) trace_api::TraceId trace_id_invalid; trace_api::TraceId trace_id_valid(buf); + std::map key_value_container; - auto sampling_result = sampler.ShouldSample(nullptr, trace_id_invalid, "invalid trace id test", - trace_api::SpanKind::kServer, span()); + auto sampling_result = sampler.ShouldSample( + nullptr, trace_id_invalid, "invalid trace id test", trace_api::SpanKind::kServer, + trace_api::KeyValueIterableView>(key_value_container)); ASSERT_EQ(Decision::RECORD_AND_SAMPLE, sampling_result.decision); ASSERT_EQ(0, sampling_result.attributes->size()); - sampling_result = sampler.ShouldSample(nullptr, trace_id_valid, "valid trace id test", - trace_api::SpanKind::kServer, span()); + sampling_result = sampler.ShouldSample( + nullptr, trace_id_valid, "valid trace id test", trace_api::SpanKind::kServer, + trace_api::KeyValueIterableView>(key_value_container)); ASSERT_EQ(Decision::RECORD_AND_SAMPLE, sampling_result.decision); ASSERT_EQ(nullptr, sampling_result.attributes); From f392e2f7ca826346d305a3755ffeb36e4d4eea40 Mon Sep 17 00:00:00 2001 From: Oliver Zhang Date: Wed, 24 Jun 2020 00:00:19 +0000 Subject: [PATCH 32/40] modify test case --- sdk/test/trace/always_on_sampler_test.cc | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/sdk/test/trace/always_on_sampler_test.cc b/sdk/test/trace/always_on_sampler_test.cc index f2fdd036e5..34dc072bb2 100644 --- a/sdk/test/trace/always_on_sampler_test.cc +++ b/sdk/test/trace/always_on_sampler_test.cc @@ -16,18 +16,18 @@ TEST(AlwaysOnSampler, ShouldSample) trace_api::TraceId trace_id_invalid; trace_api::TraceId trace_id_valid(buf); - std::map key_value_container; + std::map key_value_container; auto sampling_result = sampler.ShouldSample( nullptr, trace_id_invalid, "invalid trace id test", trace_api::SpanKind::kServer, - trace_api::KeyValueIterableView>(key_value_container)); + trace_api::KeyValueIterableView>(key_value_container)); ASSERT_EQ(Decision::RECORD_AND_SAMPLE, sampling_result.decision); ASSERT_EQ(0, sampling_result.attributes->size()); sampling_result = sampler.ShouldSample( nullptr, trace_id_valid, "valid trace id test", trace_api::SpanKind::kServer, - trace_api::KeyValueIterableView>(key_value_container)); + trace_api::KeyValueIterableView>(key_value_container)); ASSERT_EQ(Decision::RECORD_AND_SAMPLE, sampling_result.decision); ASSERT_EQ(nullptr, sampling_result.attributes); From a555daa424530a7874d12f24174f18fb4af47d59 Mon Sep 17 00:00:00 2001 From: Oliver Zhang Date: Wed, 24 Jun 2020 00:04:51 +0000 Subject: [PATCH 33/40] modify test case --- sdk/test/trace/always_on_sampler_test.cc | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/sdk/test/trace/always_on_sampler_test.cc b/sdk/test/trace/always_on_sampler_test.cc index 34dc072bb2..8060cf263e 100644 --- a/sdk/test/trace/always_on_sampler_test.cc +++ b/sdk/test/trace/always_on_sampler_test.cc @@ -16,14 +16,14 @@ TEST(AlwaysOnSampler, ShouldSample) trace_api::TraceId trace_id_invalid; trace_api::TraceId trace_id_valid(buf); - std::map key_value_container; + std::map key_value_container = {{"key", 0}}; auto sampling_result = sampler.ShouldSample( nullptr, trace_id_invalid, "invalid trace id test", trace_api::SpanKind::kServer, trace_api::KeyValueIterableView>(key_value_container)); ASSERT_EQ(Decision::RECORD_AND_SAMPLE, sampling_result.decision); - ASSERT_EQ(0, sampling_result.attributes->size()); + ASSERT_EQ(nullptr, sampling_result.attributes); sampling_result = sampler.ShouldSample( nullptr, trace_id_valid, "valid trace id test", trace_api::SpanKind::kServer, From 54db68ee078bd0b1c3d5a5b421d19ab4d149278b Mon Sep 17 00:00:00 2001 From: Oliver Zhang Date: Wed, 24 Jun 2020 00:08:15 +0000 Subject: [PATCH 34/40] remove extra header files --- sdk/include/opentelemetry/sdk/trace/always_on_sampler.h | 2 -- 1 file changed, 2 deletions(-) diff --git a/sdk/include/opentelemetry/sdk/trace/always_on_sampler.h b/sdk/include/opentelemetry/sdk/trace/always_on_sampler.h index dd6462fb57..68d24bf528 100644 --- a/sdk/include/opentelemetry/sdk/trace/always_on_sampler.h +++ b/sdk/include/opentelemetry/sdk/trace/always_on_sampler.h @@ -1,9 +1,7 @@ #pragma once -#include "opentelemetry/common/attribute_value.h" #include "opentelemetry/sdk/common/atomic_shared_ptr.h" #include "opentelemetry/sdk/trace/sampler.h" -#include "opentelemetry/trace/span.h" #include "opentelemetry/trace/tracer.h" #include "opentelemetry/version.h" From 543ece9ecf36d5d9ee134775252030c6d12b88ee Mon Sep 17 00:00:00 2001 From: Oliver Zhang Date: Wed, 24 Jun 2020 14:37:27 +0000 Subject: [PATCH 35/40] change to inline function --- .../sdk/trace/always_on_sampler.h | 36 ------------------- sdk/include/opentelemetry/sdk/trace/sampler.h | 24 +++++++++++++ sdk/src/trace/always_on_sampler.cc | 28 --------------- sdk/test/trace/always_on_sampler_test.cc | 2 +- 4 files changed, 25 insertions(+), 65 deletions(-) delete mode 100644 sdk/include/opentelemetry/sdk/trace/always_on_sampler.h delete mode 100644 sdk/src/trace/always_on_sampler.cc diff --git a/sdk/include/opentelemetry/sdk/trace/always_on_sampler.h b/sdk/include/opentelemetry/sdk/trace/always_on_sampler.h deleted file mode 100644 index 68d24bf528..0000000000 --- a/sdk/include/opentelemetry/sdk/trace/always_on_sampler.h +++ /dev/null @@ -1,36 +0,0 @@ -#pragma once - -#include "opentelemetry/sdk/common/atomic_shared_ptr.h" -#include "opentelemetry/sdk/trace/sampler.h" -#include "opentelemetry/trace/tracer.h" -#include "opentelemetry/version.h" - -#include - -OPENTELEMETRY_BEGIN_NAMESPACE -namespace sdk -{ -namespace trace -{ -class AlwaysOnSampler final : public sdk::trace::Sampler -{ -public: - /** - * Returned SamplingResult always has RECORD_AND_SAMPLED - * as the Decision - */ - SamplingResult ShouldSample( - const SpanContext *parent_context, - trace_api::TraceId trace_id, - nostd::string_view name, - trace_api::SpanKind span_kind, - const trace_api::KeyValueIterable &attributes) noexcept override; - - /** - * @return Description MUST be AlwaysOnSampler - */ - std::string GetDescription() const noexcept override; -}; -} // namespace trace -} // namespace sdk -OPENTELEMETRY_END_NAMESPACE diff --git a/sdk/include/opentelemetry/sdk/trace/sampler.h b/sdk/include/opentelemetry/sdk/trace/sampler.h index 5db444020c..32a67ec7d2 100644 --- a/sdk/include/opentelemetry/sdk/trace/sampler.h +++ b/sdk/include/opentelemetry/sdk/trace/sampler.h @@ -80,6 +80,30 @@ class Sampler */ virtual std::string GetDescription() const noexcept = 0; }; + +class AlwaysOnSampler final : public sdk::trace::Sampler +{ +public: + /** + * Returned SamplingResult always has RECORD_AND_SAMPLED + * as the Decision + */ + inline SamplingResult ShouldSample( + const SpanContext *parent_context, + trace_api::TraceId trace_id, + nostd::string_view name, + trace_api::SpanKind span_kind, + const trace_api::KeyValueIterable &attributes) noexcept override { + return{sdk::trace::Decision::RECORD_AND_SAMPLE, nullptr}; + } + + /** + * @return Description MUST be AlwaysOnSampler + */ + inline std::string GetDescription() const noexcept override { + return "AlwaysOnSampler"; + } +}; } // namespace trace } // namespace sdk OPENTELEMETRY_END_NAMESPACE diff --git a/sdk/src/trace/always_on_sampler.cc b/sdk/src/trace/always_on_sampler.cc deleted file mode 100644 index 7e50b6752b..0000000000 --- a/sdk/src/trace/always_on_sampler.cc +++ /dev/null @@ -1,28 +0,0 @@ -#include "opentelemetry/sdk/trace/always_on_sampler.h" -#include "opentelemetry/version.h" - -OPENTELEMETRY_BEGIN_NAMESPACE -namespace sdk -{ -namespace trace -{ -/** - * Return RECORD_AND_SAMPLE and an empty set of attributes - */ -SamplingResult AlwaysOnSampler::ShouldSample( - const SpanContext *parent_context, - trace_api::TraceId trace_id, - nostd::string_view name, - trace_api::SpanKind span_kind, - const trace_api::KeyValueIterable &attributes) noexcept -{ - return{sdk::trace::Decision::RECORD_AND_SAMPLE, nullptr}; -} - -std::string AlwaysOnSampler::GetDescription() const noexcept -{ - return std::string("AlwaysOnSampler"); -} -} // namespace trace -} // namespace sdk -OPENTELEMETRY_END_NAMESPACE diff --git a/sdk/test/trace/always_on_sampler_test.cc b/sdk/test/trace/always_on_sampler_test.cc index 8060cf263e..9463340ca6 100644 --- a/sdk/test/trace/always_on_sampler_test.cc +++ b/sdk/test/trace/always_on_sampler_test.cc @@ -1,4 +1,4 @@ -#include "opentelemetry/sdk/trace/always_on_sampler.h" +#include "opentelemetry/sdk/trace/sampler.h" #include "opentelemetry/nostd/span.h" #include From 03002b614484850f2ee1511826ff5154ac8f4485 Mon Sep 17 00:00:00 2001 From: Oliver Zhang Date: Wed, 24 Jun 2020 14:50:18 +0000 Subject: [PATCH 36/40] change cmake --- sdk/src/trace/CMakeLists.txt | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/sdk/src/trace/CMakeLists.txt b/sdk/src/trace/CMakeLists.txt index b8cd56a0d2..455665be68 100644 --- a/sdk/src/trace/CMakeLists.txt +++ b/sdk/src/trace/CMakeLists.txt @@ -1 +1 @@ -add_library(opentelemetry_trace tracer_provider.cc tracer.cc span.cc always_on_sampler.cc) +add_library(opentelemetry_trace tracer_provider.cc tracer.cc span.cc) From 1a621e4f397e044489733dcfb5332f576f35a113 Mon Sep 17 00:00:00 2001 From: Oliver Zhang Date: Thu, 25 Jun 2020 17:41:47 +0000 Subject: [PATCH 37/40] change bazel version --- .bazelversion | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/.bazelversion b/.bazelversion index 944880fa15..15a2799817 100644 --- a/.bazelversion +++ b/.bazelversion @@ -1 +1 @@ -3.2.0 +3.3.0 From b08e544f6aab7103cfdf8adf8acbf604518bebd2 Mon Sep 17 00:00:00 2001 From: Oliver Zhang Date: Mon, 29 Jun 2020 14:11:21 +0000 Subject: [PATCH 38/40] move sampler to separate folder --- sdk/include/opentelemetry/sdk/trace/sampler.h | 24 ----------- .../sdk/trace/samplers/always_on.h | 40 +++++++++++++++++++ sdk/test/trace/always_on_sampler_test.cc | 4 +- 3 files changed, 43 insertions(+), 25 deletions(-) create mode 100644 sdk/include/opentelemetry/sdk/trace/samplers/always_on.h diff --git a/sdk/include/opentelemetry/sdk/trace/sampler.h b/sdk/include/opentelemetry/sdk/trace/sampler.h index 74e734b53b..93599b18e7 100644 --- a/sdk/include/opentelemetry/sdk/trace/sampler.h +++ b/sdk/include/opentelemetry/sdk/trace/sampler.h @@ -80,30 +80,6 @@ class Sampler */ virtual std::string GetDescription() const noexcept = 0; }; - -class AlwaysOnSampler final : public sdk::trace::Sampler -{ -public: - /** - * Returned SamplingResult always has RECORD_AND_SAMPLED - * as the Decision - */ - inline SamplingResult ShouldSample( - const SpanContext *parent_context, - trace_api::TraceId trace_id, - nostd::string_view name, - trace_api::SpanKind span_kind, - const trace_api::KeyValueIterable &attributes) noexcept override { - return{sdk::trace::Decision::RECORD_AND_SAMPLE, nullptr}; - } - - /** - * @return Description MUST be AlwaysOnSampler - */ - inline std::string GetDescription() const noexcept override { - return "AlwaysOnSampler"; - } -}; } // namespace trace } // namespace sdk OPENTELEMETRY_END_NAMESPACE diff --git a/sdk/include/opentelemetry/sdk/trace/samplers/always_on.h b/sdk/include/opentelemetry/sdk/trace/samplers/always_on.h new file mode 100644 index 0000000000..40e28a68a5 --- /dev/null +++ b/sdk/include/opentelemetry/sdk/trace/samplers/always_on.h @@ -0,0 +1,40 @@ +#pragma once + +#include "opentelemetry/sdk/trace/sampler.h" + +OPENTELEMETRY_BEGIN_NAMESPACE +namespace sdk +{ +namespace trace +{ +namespace trace_api = opentelemetry::trace; +/** + * The always on sampler is a default sampler + */ +class AlwaysOnSampler : public Sampler +{ +public: + /** + * @return Always return Decision RECORD_AND_SAMPLE + */ + SamplingResult ShouldSample( + const SpanContext * /*parent_context*/, + trace_api::TraceId /*trace_id*/, + nostd::string_view /*name*/, + trace_api::SpanKind /*span_kind*/, + const trace_api::KeyValueIterable & /*attributes*/) noexcept override + { + return{Decision::RECORD_AND_SAMPLE, nullptr}; + } + + /** + * @return Description MUST be AlwaysOnSampler + */ + std::string GetDescription() const noexcept override + { + return "AlwaysOnSampler"; + } +}; +} // namespace trace +} // namespace sdk +OPENTELEMETRY_END_NAMESPACE diff --git a/sdk/test/trace/always_on_sampler_test.cc b/sdk/test/trace/always_on_sampler_test.cc index 9463340ca6..bba3327d86 100644 --- a/sdk/test/trace/always_on_sampler_test.cc +++ b/sdk/test/trace/always_on_sampler_test.cc @@ -1,4 +1,4 @@ -#include "opentelemetry/sdk/trace/sampler.h" +#include "opentelemetry/sdk/trace/samplers/always_on.h" #include "opentelemetry/nostd/span.h" #include @@ -18,6 +18,7 @@ TEST(AlwaysOnSampler, ShouldSample) trace_api::TraceId trace_id_valid(buf); std::map key_value_container = {{"key", 0}}; + // Test with invalid (empty) trace id and empty parent context auto sampling_result = sampler.ShouldSample( nullptr, trace_id_invalid, "invalid trace id test", trace_api::SpanKind::kServer, trace_api::KeyValueIterableView>(key_value_container)); @@ -25,6 +26,7 @@ TEST(AlwaysOnSampler, ShouldSample) ASSERT_EQ(Decision::RECORD_AND_SAMPLE, sampling_result.decision); ASSERT_EQ(nullptr, sampling_result.attributes); + // Test with a valid trace id and empty parent context sampling_result = sampler.ShouldSample( nullptr, trace_id_valid, "valid trace id test", trace_api::SpanKind::kServer, trace_api::KeyValueIterableView>(key_value_container)); From a200940a1e6ba573f1151042be20a072d530aafc Mon Sep 17 00:00:00 2001 From: Oliver Zhang Date: Mon, 29 Jun 2020 14:13:29 +0000 Subject: [PATCH 39/40] format --- sdk/include/opentelemetry/sdk/trace/sampler.h | 4 ++-- .../sdk/trace/samplers/always_on.h | 22 ++++++++----------- sdk/test/trace/always_on_sampler_test.cc | 2 +- 3 files changed, 12 insertions(+), 16 deletions(-) diff --git a/sdk/include/opentelemetry/sdk/trace/sampler.h b/sdk/include/opentelemetry/sdk/trace/sampler.h index 93599b18e7..27071b458c 100644 --- a/sdk/include/opentelemetry/sdk/trace/sampler.h +++ b/sdk/include/opentelemetry/sdk/trace/sampler.h @@ -17,7 +17,7 @@ namespace trace namespace trace_api = opentelemetry::trace; /** - * A sampling Decision for a Span to be created. + * A sampling Decision for a Span to be created. */ enum class Decision { @@ -31,7 +31,7 @@ enum class Decision }; /** - * The output of ShouldSample. + * The output of ShouldSample. * It contains a sampling Decision and a set of Span Attributes. */ struct SamplingResult diff --git a/sdk/include/opentelemetry/sdk/trace/samplers/always_on.h b/sdk/include/opentelemetry/sdk/trace/samplers/always_on.h index 40e28a68a5..4817361d88 100644 --- a/sdk/include/opentelemetry/sdk/trace/samplers/always_on.h +++ b/sdk/include/opentelemetry/sdk/trace/samplers/always_on.h @@ -9,7 +9,7 @@ namespace trace { namespace trace_api = opentelemetry::trace; /** - * The always on sampler is a default sampler + * The always on sampler is a default sampler which always return Decision::RECORD_AND_SAMPLE */ class AlwaysOnSampler : public Sampler { @@ -17,23 +17,19 @@ class AlwaysOnSampler : public Sampler /** * @return Always return Decision RECORD_AND_SAMPLE */ - SamplingResult ShouldSample( - const SpanContext * /*parent_context*/, - trace_api::TraceId /*trace_id*/, - nostd::string_view /*name*/, - trace_api::SpanKind /*span_kind*/, - const trace_api::KeyValueIterable & /*attributes*/) noexcept override + SamplingResult ShouldSample(const SpanContext * /*parent_context*/, + trace_api::TraceId /*trace_id*/, + nostd::string_view /*name*/, + trace_api::SpanKind /*span_kind*/, + const trace_api::KeyValueIterable & /*attributes*/) noexcept override { - return{Decision::RECORD_AND_SAMPLE, nullptr}; + return {Decision::RECORD_AND_SAMPLE, nullptr}; } - + /** * @return Description MUST be AlwaysOnSampler */ - std::string GetDescription() const noexcept override - { - return "AlwaysOnSampler"; - } + std::string GetDescription() const noexcept override { return "AlwaysOnSampler"; } }; } // namespace trace } // namespace sdk diff --git a/sdk/test/trace/always_on_sampler_test.cc b/sdk/test/trace/always_on_sampler_test.cc index bba3327d86..a933cd0073 100644 --- a/sdk/test/trace/always_on_sampler_test.cc +++ b/sdk/test/trace/always_on_sampler_test.cc @@ -1,5 +1,5 @@ -#include "opentelemetry/sdk/trace/samplers/always_on.h" #include "opentelemetry/nostd/span.h" +#include "opentelemetry/sdk/trace/samplers/always_on.h" #include #include From 04340b4071ce90b4b481033fce1bd7cd7b421dd0 Mon Sep 17 00:00:00 2001 From: Oliver Zhang Date: Mon, 29 Jun 2020 17:27:44 +0000 Subject: [PATCH 40/40] add inline keyword --- sdk/include/opentelemetry/sdk/trace/samplers/always_on.h | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/sdk/include/opentelemetry/sdk/trace/samplers/always_on.h b/sdk/include/opentelemetry/sdk/trace/samplers/always_on.h index 4817361d88..e50d15829f 100644 --- a/sdk/include/opentelemetry/sdk/trace/samplers/always_on.h +++ b/sdk/include/opentelemetry/sdk/trace/samplers/always_on.h @@ -17,7 +17,7 @@ class AlwaysOnSampler : public Sampler /** * @return Always return Decision RECORD_AND_SAMPLE */ - SamplingResult ShouldSample(const SpanContext * /*parent_context*/, + inline SamplingResult ShouldSample(const SpanContext * /*parent_context*/, trace_api::TraceId /*trace_id*/, nostd::string_view /*name*/, trace_api::SpanKind /*span_kind*/, @@ -29,7 +29,7 @@ class AlwaysOnSampler : public Sampler /** * @return Description MUST be AlwaysOnSampler */ - std::string GetDescription() const noexcept override { return "AlwaysOnSampler"; } + inline std::string GetDescription() const noexcept override { return "AlwaysOnSampler"; } }; } // namespace trace } // namespace sdk