forked from open-telemetry/opentelemetry-cpp
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Always Off Sampler (open-telemetry#125)
- Loading branch information
1 parent
268d59c
commit 6b428a3
Showing
5 changed files
with
84 additions
and
2 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1 +1 @@ | ||
3.2.0 | ||
3.3.0 |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,41 @@ | ||
#pragma once | ||
|
||
#include "opentelemetry/sdk/trace/sampler.h" | ||
|
||
OPENTELEMETRY_BEGIN_NAMESPACE | ||
namespace sdk | ||
{ | ||
namespace trace | ||
{ | ||
namespace trace_api = opentelemetry::trace; | ||
/** | ||
* The always off sampler always returns NOT_RECORD, effectively disabling | ||
* tracing functionality. | ||
*/ | ||
class AlwaysOffSampler : public Sampler | ||
{ | ||
public: | ||
/** | ||
* @return Returns NOT_RECORD always | ||
*/ | ||
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::NOT_RECORD, nullptr }; | ||
} | ||
|
||
/** | ||
* @return Description MUST be AlwaysOffSampler | ||
*/ | ||
std::string GetDescription() const noexcept override | ||
{ | ||
return "AlwaysOffSampler"; | ||
} | ||
}; | ||
} // namespace trace | ||
} // namespace sdk | ||
OPENTELEMETRY_END_NAMESPACE |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,30 @@ | ||
#include "opentelemetry/sdk/trace/samplers/always_off.h" | ||
|
||
#include <gtest/gtest.h> | ||
|
||
using opentelemetry::sdk::trace::AlwaysOffSampler; | ||
using opentelemetry::sdk::trace::Decision; | ||
|
||
TEST(AlwaysOffSampler, ShouldSample) | ||
{ | ||
AlwaysOffSampler sampler; | ||
|
||
opentelemetry::trace::TraceId trace_id; | ||
opentelemetry::trace::SpanKind span_kind = opentelemetry::trace::SpanKind::kInternal; | ||
|
||
using M = std::map<std::string, int>; | ||
M m1 = {{}}; | ||
opentelemetry::trace::KeyValueIterableView<M> view{m1}; | ||
|
||
auto sampling_result = sampler.ShouldSample(nullptr, trace_id, "", span_kind, view); | ||
|
||
ASSERT_EQ(Decision::NOT_RECORD, sampling_result.decision); | ||
ASSERT_EQ(nullptr, sampling_result.attributes); | ||
} | ||
|
||
TEST(AlwaysOffSampler, GetDescription) | ||
{ | ||
AlwaysOffSampler sampler; | ||
|
||
ASSERT_EQ("AlwaysOffSampler", sampler.GetDescription()); | ||
} |