1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55
|
// Copyright The OpenTelemetry Authors
// SPDX-License-Identifier: Apache-2.0
#include <gtest/gtest.h>
#include <map>
#include <string>
#include <utility>
#include <vector>
#include "opentelemetry/common/key_value_iterable_view.h"
#include "opentelemetry/nostd/shared_ptr.h"
#include "opentelemetry/nostd/string_view.h"
#include "opentelemetry/sdk/trace/sampler.h"
#include "opentelemetry/sdk/trace/samplers/always_off.h"
#include "opentelemetry/trace/span_context.h"
#include "opentelemetry/trace/span_context_kv_iterable_view.h"
#include "opentelemetry/trace/span_metadata.h"
#include "opentelemetry/trace/trace_id.h"
#include "opentelemetry/trace/trace_state.h"
using opentelemetry::sdk::trace::AlwaysOffSampler;
using opentelemetry::sdk::trace::Decision;
using opentelemetry::trace::SpanContext;
namespace trace_api = opentelemetry::trace;
TEST(AlwaysOffSampler, ShouldSample)
{
AlwaysOffSampler sampler;
trace_api::TraceId trace_id;
trace_api::SpanKind span_kind = trace_api::SpanKind::kInternal;
using M = std::map<std::string, int>;
M m1 = {{}};
using L = std::vector<std::pair<SpanContext, std::map<std::string, std::string>>>;
L l1 = {{SpanContext(false, false), {}}, {SpanContext(false, false), {}}};
opentelemetry::common::KeyValueIterableView<M> view{m1};
trace_api::SpanContextKeyValueIterableView<L> links{l1};
auto sampling_result =
sampler.ShouldSample(SpanContext::GetInvalid(), trace_id, "", span_kind, view, links);
ASSERT_EQ(Decision::DROP, sampling_result.decision);
ASSERT_EQ(nullptr, sampling_result.attributes);
ASSERT_EQ("", sampling_result.trace_state->ToHeader());
}
TEST(AlwaysOffSampler, GetDescription)
{
AlwaysOffSampler sampler;
ASSERT_EQ("AlwaysOffSampler", sampler.GetDescription());
}
|