Skip to content
New issue

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

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

Already on GitHub? Sign in to your account

Always Off Sampler #125

Merged
merged 40 commits into from
Jun 26, 2020
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
40 commits
Select commit Hold shift + click to select a range
b5d066d
minor fix
Jun 23, 2020
abba0e3
modify namespace
Jun 24, 2020
641f18a
add sampler header file
Jun 17, 2020
850b463
add param and comments
Jun 17, 2020
66a079c
change class definition
Jun 17, 2020
e454c10
add Decision enum
Jun 17, 2020
692b1a9
add Decision enum
Jun 17, 2020
ae423f0
minor tweaks
Jun 17, 2020
1bf4267
add sampler header file
Jun 17, 2020
71534c9
add param and comments
Jun 17, 2020
9e6d9f4
change class definition
Jun 17, 2020
358da8d
add Decision enum
Jun 17, 2020
b31c615
add Decision enum
Jun 17, 2020
d2713a0
minor tweaks
Jun 17, 2020
f00f02d
Add AlwaysOffSampler header file
nholbrook Jun 19, 2020
d1e27ae
Add AlwaysOffSampler
nholbrook Jun 22, 2020
65efdb4
Updated Decision enum usage
nholbrook Jun 22, 2020
099061a
Add AlwaysOffSampler test
nholbrook Jun 22, 2020
b913858
Move test order for improved readability
nholbrook Jun 22, 2020
719be66
Fixed various syntax issues
nholbrook Jun 22, 2020
d2a6a55
Add test to BUILD
nholbrook Jun 23, 2020
90bd031
Update AlwaysOffSampler to new sampler spec
nholbrook Jun 23, 2020
b04a0c1
Update AlwaysOffSampler tests
nholbrook Jun 23, 2020
139d09d
Fix typo with test name
nholbrook Jun 23, 2020
1930b63
Add AlwaysOnSampler to cmake file
nholbrook Jun 23, 2020
33564d4
Modify AlwaysOffSampler to set attributes to nullptr
nholbrook Jun 23, 2020
99631fe
Fix sampler test
nholbrook Jun 23, 2020
7332c4f
Update data type
nholbrook Jun 24, 2020
69050ed
Update AlwaysOffSampler unit test
nholbrook Jun 24, 2020
e6295f9
Fix AlwaysOffSampler unit test
nholbrook Jun 24, 2020
fc12f51
Move AlwaysOffSampler implementation to header file
nholbrook Jun 24, 2020
7b100cb
Remove file reference from cmake file
nholbrook Jun 24, 2020
298b5b2
Update bazel version to 3.3.0
nholbrook Jun 25, 2020
6cf3542
Add newline at end of files
nholbrook Jun 26, 2020
61c95a9
Reformat to unname unused parameters
nholbrook Jun 26, 2020
51de9bc
Merge branch 'master' into nholbrook/always-off-sampler
nholbrook Jun 26, 2020
788e326
Revert sampler changes
nholbrook Jun 26, 2020
13e522b
Add newline at end of file
nholbrook Jun 26, 2020
e822c2b
Move AlwaysOffSampler
nholbrook Jun 26, 2020
a3f1cab
Update sampler import
nholbrook Jun 26, 2020
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion .bazelversion
Original file line number Diff line number Diff line change
@@ -1 +1 @@
3.2.0
3.3.0
41 changes: 41 additions & 0 deletions sdk/include/opentelemetry/sdk/trace/samplers/always_off.h
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
11 changes: 11 additions & 0 deletions sdk/test/trace/BUILD
Original file line number Diff line number Diff line change
Expand Up @@ -41,3 +41,14 @@ cc_test(
"@com_google_googletest//:gtest_main",
],
)

cc_test(
name = "always_off_sampler_test",
srcs = [
"always_off_sampler_test.cc"
],
deps = [
"//sdk/src/trace",
"@com_google_googletest//:gtest_main",
]
)
2 changes: 1 addition & 1 deletion sdk/test/trace/CMakeLists.txt
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
foreach(testname tracer_provider_test span_data_test simple_processor_test
tracer_test)
tracer_test always_off_sampler_test)
add_executable(${testname} "${testname}.cc")
target_link_libraries(${testname} ${GTEST_BOTH_LIBRARIES}
${CMAKE_THREAD_LIBS_INIT} opentelemetry_trace)
Expand Down
30 changes: 30 additions & 0 deletions sdk/test/trace/always_off_sampler_test.cc
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());
}