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

fix: issue 368- consistent namespace scope resolution #1008

Merged
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
24 commits
Select commit Hold shift + click to select a range
b253a20
fix-368: Consistent NameSpace Scope Resolution in .cc files
PaurushGarg Sep 29, 2021
4cab069
Adding back the + signs that got deleted automatically
PaurushGarg Sep 29, 2021
3902577
Merge branch 'open-telemetry:main' into fix_368_consistent_namespace_…
PaurushGarg Sep 29, 2021
92467ab
adding + symbol back that got removed by git push
PaurushGarg Sep 29, 2021
40e0853
Merge branch 'fix_368_consistent_namespace_scope_resolution' of githu…
PaurushGarg Sep 29, 2021
39551a2
Merge branch 'main' into fix_368_consistent_namespace_scope_resolution
PaurushGarg Oct 4, 2021
3cc863b
Merge branch 'open-telemetry:main' into fix_368_consistent_namespace_…
PaurushGarg Oct 4, 2021
d29acdb
Removing errors related to logs/metrics test
PaurushGarg Oct 5, 2021
98d4f9f
Formatted files using format.sh
PaurushGarg Oct 5, 2021
29f9601
Reversing changes in kv_properties_test.cc
PaurushGarg Oct 5, 2021
c191c2f
Removing with OTLP exporter errors
PaurushGarg Oct 5, 2021
d7dc0b7
Removing Errors
PaurushGarg Oct 5, 2021
7491cb6
Merge branch 'main' into fix_368_consistent_namespace_scope_resolution
PaurushGarg Oct 11, 2021
b90ae15
Removing with and without OTLP exporter errors
PaurushGarg Oct 11, 2021
b04e37e
Resolving error of with and without OTLP Exporter
PaurushGarg Oct 11, 2021
2f759de
Resolving with OTLP errors
PaurushGarg Oct 11, 2021
92af458
Resolved merge conflicts
PaurushGarg Nov 8, 2021
e67a6df
Fixing the review comments on consistent namespace of sdk and namespa…
PaurushGarg Nov 8, 2021
23d99c3
Fixing the review comments on consistent namespace of sdk and namespa…
PaurushGarg Nov 8, 2021
04bfe70
Removed errors
PaurushGarg Nov 8, 2021
27e7d8b
Fixing the errors
PaurushGarg Nov 13, 2021
13a7259
Removing Errors
PaurushGarg Nov 15, 2021
692ac34
Merge branch 'main' into fix_368_consistent_namespace_scope_resolution
PaurushGarg Nov 15, 2021
2a1d460
Merge branch 'main' into fix_368_consistent_namespace_scope_resolution
PaurushGarg Nov 15, 2021
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: 2 additions & 0 deletions api/include/opentelemetry/trace/noop.h
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,8 @@

#include <memory>

namespace trace_api = opentelemetry::trace;

OPENTELEMETRY_BEGIN_NAMESPACE
namespace trace
{
Expand Down
20 changes: 9 additions & 11 deletions api/include/opentelemetry/trace/span_context.h
Original file line number Diff line number Diff line change
Expand Up @@ -12,8 +12,6 @@
OPENTELEMETRY_BEGIN_NAMESPACE
namespace trace
{
namespace trace_api = opentelemetry::trace;

/* SpanContext contains the state that must propagate to child Spans and across
* process boundaries. It contains TraceId and SpanId, TraceFlags, TraceState
* and whether it was propagated from a remote parent.
Expand All @@ -31,7 +29,7 @@ class SpanContext final
SpanContext(bool sampled_flag, bool is_remote)
: trace_id_(),
span_id_(),
trace_flags_(trace_api::TraceFlags((uint8_t)sampled_flag)),
trace_flags_(opentelemetry::trace::TraceFlags((uint8_t)sampled_flag)),
is_remote_(is_remote),
trace_state_(TraceState::GetDefault())
{}
Expand All @@ -54,16 +52,16 @@ class SpanContext final
bool IsValid() const noexcept { return trace_id_.IsValid() && span_id_.IsValid(); }

// @returns the trace_flags associated with this span_context
const trace_api::TraceFlags &trace_flags() const noexcept { return trace_flags_; }
const opentelemetry::trace::TraceFlags &trace_flags() const noexcept { return trace_flags_; }

// @returns the trace_id associated with this span_context
const trace_api::TraceId &trace_id() const noexcept { return trace_id_; }
const opentelemetry::trace::TraceId &trace_id() const noexcept { return trace_id_; }

// @returns the span_id associated with this span_context
const trace_api::SpanId &span_id() const noexcept { return span_id_; }
const opentelemetry::trace::SpanId &span_id() const noexcept { return span_id_; }

// @returns the trace_state associated with this span_context
const nostd::shared_ptr<trace_api::TraceState> trace_state() const noexcept
const nostd::shared_ptr<opentelemetry::trace::TraceState> trace_state() const noexcept
{
return trace_state_;
}
Expand All @@ -88,11 +86,11 @@ class SpanContext final
bool IsSampled() const noexcept { return trace_flags_.IsSampled(); }

private:
trace_api::TraceId trace_id_;
trace_api::SpanId span_id_;
trace_api::TraceFlags trace_flags_;
opentelemetry::trace::TraceId trace_id_;
opentelemetry::trace::SpanId span_id_;
opentelemetry::trace::TraceFlags trace_flags_;
bool is_remote_;
nostd::shared_ptr<trace_api::TraceState> trace_state_;
nostd::shared_ptr<opentelemetry::trace::TraceState> trace_state_;
};
} // namespace trace
OPENTELEMETRY_END_NAMESPACE
14 changes: 7 additions & 7 deletions api/test/_metrics/meter_provider_test.cc
Original file line number Diff line number Diff line change
Expand Up @@ -9,14 +9,14 @@
using opentelemetry::metrics::Meter;
using opentelemetry::metrics::MeterProvider;
using opentelemetry::metrics::Provider;
namespace nostd = opentelemetry::nostd;

class TestProvider : public MeterProvider
{
opentelemetry::nostd::shared_ptr<Meter> GetMeter(
opentelemetry::nostd::string_view library_name,
opentelemetry::nostd::string_view library_version) override
nostd::shared_ptr<Meter> GetMeter(nostd::string_view library_name,
nostd::string_view library_version) override
{
return opentelemetry::nostd::shared_ptr<Meter>(nullptr);
return nostd::shared_ptr<Meter>(nullptr);
}
};

Expand All @@ -28,16 +28,16 @@ TEST(Provider, GetMeterProviderDefault)

TEST(Provider, SetMeterProvider)
{
auto tf = opentelemetry::nostd::shared_ptr<MeterProvider>(new TestProvider());
auto tf = nostd::shared_ptr<MeterProvider>(new TestProvider());
Provider::SetMeterProvider(tf);
ASSERT_EQ(tf, Provider::GetMeterProvider());
}

TEST(Provider, MultipleMeterProviders)
{
auto tf = opentelemetry::nostd::shared_ptr<MeterProvider>(new TestProvider());
auto tf = nostd::shared_ptr<MeterProvider>(new TestProvider());
Provider::SetMeterProvider(tf);
auto tf2 = opentelemetry::nostd::shared_ptr<MeterProvider>(new TestProvider());
auto tf2 = nostd::shared_ptr<MeterProvider>(new TestProvider());
Provider::SetMeterProvider(tf2);

ASSERT_NE(Provider::GetMeterProvider(), tf);
Expand Down
6 changes: 3 additions & 3 deletions api/test/context/propagation/composite_propagator_test.cc
Original file line number Diff line number Diff line change
Expand Up @@ -118,7 +118,7 @@ TEST_F(CompositePropagatorTest, Inject)
return true;
});
EXPECT_EQ(fields.size(), 3);
EXPECT_EQ(fields[0], opentelemetry::trace::propagation::kTraceParent);
EXPECT_EQ(fields[1], opentelemetry::trace::propagation::kTraceState);
EXPECT_EQ(fields[2], opentelemetry::trace::propagation::kB3CombinedHeader);
EXPECT_EQ(fields[0], trace::propagation::kTraceParent);
EXPECT_EQ(fields[1], trace::propagation::kTraceState);
EXPECT_EQ(fields[2], trace::propagation::kB3CombinedHeader);
}
17 changes: 10 additions & 7 deletions api/test/logs/logger_test.cc
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,9 @@ using opentelemetry::logs::Severity;
using opentelemetry::nostd::shared_ptr;
using opentelemetry::nostd::span;
using opentelemetry::nostd::string_view;
namespace common = opentelemetry::common;
namespace nostd = opentelemetry::nostd;
namespace trace = opentelemetry::trace;

// Check that the default logger is a noop logger instance
TEST(Logger, GetLoggerDefault)
Expand Down Expand Up @@ -72,17 +75,17 @@ TEST(Logger, LogMethodOverloads)
// Define a basic Logger class
class TestLogger : public Logger
{
const opentelemetry::nostd::string_view GetName() noexcept override { return "test logger"; }
const nostd::string_view GetName() noexcept override { return "test logger"; }

void Log(Severity severity,
string_view name,
string_view body,
const opentelemetry::common::KeyValueIterable &resource,
const opentelemetry::common::KeyValueIterable &attributes,
opentelemetry::trace::TraceId trace_id,
opentelemetry::trace::SpanId span_id,
opentelemetry::trace::TraceFlags trace_flags,
opentelemetry::common::SystemTimestamp timestamp) noexcept override
const common::KeyValueIterable &resource,
const common::KeyValueIterable &attributes,
trace::TraceId trace_id,
trace::SpanId span_id,
trace::TraceFlags trace_flags,
common::SystemTimestamp timestamp) noexcept override
{}
};

Expand Down
25 changes: 12 additions & 13 deletions api/test/nostd/utility_test.cc
Original file line number Diff line number Diff line change
Expand Up @@ -9,13 +9,15 @@

#include <gtest/gtest.h>

namespace nostd = opentelemetry::nostd;

template <class T>
auto IsDataCallable(const T &t) -> decltype(opentelemetry::nostd::data(t), std::true_type{});
auto IsDataCallable(const T &t) -> decltype(nostd::data(t), std::true_type{});

std::false_type IsDataCallable(...);

template <class T>
auto IsSizeCallable(const T &t) -> decltype(opentelemetry::nostd::size(t), std::true_type{});
auto IsSizeCallable(const T &t) -> decltype(nostd::size(t), std::true_type{});

std::false_type IsSizeCallable(...);

Expand All @@ -27,9 +29,9 @@ TEST(UtilityTest, Data)
int x = 0;
std::ignore = x;

EXPECT_EQ(opentelemetry::nostd::data(v), v.data());
EXPECT_EQ(opentelemetry::nostd::data(array), array);
EXPECT_EQ(opentelemetry::nostd::data(list), list.begin());
EXPECT_EQ(nostd::data(v), v.data());
EXPECT_EQ(nostd::data(array), array);
EXPECT_EQ(nostd::data(list), list.begin());
EXPECT_FALSE(decltype(IsDataCallable(x)){});
}

Expand All @@ -40,18 +42,15 @@ TEST(UtilityTest, Size)
int x = 0;
std::ignore = x;

EXPECT_EQ(opentelemetry::nostd::size(v), v.size());
EXPECT_EQ(opentelemetry::nostd::size(array), 3);
EXPECT_EQ(nostd::size(v), v.size());
EXPECT_EQ(nostd::size(array), 3);

EXPECT_FALSE(decltype(IsSizeCallable(x)){});
}

TEST(UtilityTest, MakeIndexSequence)
{
EXPECT_TRUE((std::is_same<opentelemetry::nostd::make_index_sequence<0>,
opentelemetry::nostd::index_sequence<>>::value));
EXPECT_TRUE((std::is_same<opentelemetry::nostd::make_index_sequence<1>,
opentelemetry::nostd::index_sequence<0>>::value));
EXPECT_TRUE((std::is_same<opentelemetry::nostd::make_index_sequence<2>,
opentelemetry::nostd::index_sequence<0, 1>>::value));
EXPECT_TRUE((std::is_same<nostd::make_index_sequence<0>, nostd::index_sequence<>>::value));
EXPECT_TRUE((std::is_same<nostd::make_index_sequence<1>, nostd::index_sequence<0>>::value));
EXPECT_TRUE((std::is_same<nostd::make_index_sequence<2>, nostd::index_sequence<0, 1>>::value));
}
2 changes: 1 addition & 1 deletion api/test/trace/noop_test.cc
Original file line number Diff line number Diff line change
Expand Up @@ -36,7 +36,7 @@ TEST(NoopTest, UseNoopTracers)

EXPECT_EQ(s1->IsRecording(), false);

s1->SetStatus(opentelemetry::trace::StatusCode::kUnset, "span unset");
s1->SetStatus(trace_api::StatusCode::kUnset, "span unset");

s1->UpdateName("test_name");

Expand Down
4 changes: 2 additions & 2 deletions api/test/trace/propagation/http_text_format_test.cc
Original file line number Diff line number Diff line change
Expand Up @@ -206,6 +206,6 @@ TEST(GlobalPropagator, SetAndGet)
return true;
});
EXPECT_EQ(fields.size(), 2);
EXPECT_EQ(fields[0], opentelemetry::trace::propagation::kTraceParent);
EXPECT_EQ(fields[1], opentelemetry::trace::propagation::kTraceState);
EXPECT_EQ(fields[0], trace::propagation::kTraceParent);
EXPECT_EQ(fields[1], trace::propagation::kTraceState);
}
13 changes: 7 additions & 6 deletions api/test/trace/provider_test.cc
Original file line number Diff line number Diff line change
Expand Up @@ -10,14 +10,15 @@ using opentelemetry::trace::Provider;
using opentelemetry::trace::Tracer;
using opentelemetry::trace::TracerProvider;

namespace nostd = opentelemetry::nostd;

class TestProvider : public TracerProvider
{
opentelemetry::nostd::shared_ptr<Tracer> GetTracer(
opentelemetry::nostd::string_view library_name,
opentelemetry::nostd::string_view library_version,
opentelemetry::nostd::string_view schema_url) override
nostd::shared_ptr<Tracer> GetTracer(nostd::string_view library_name,
nostd::string_view library_version,
nostd::string_view schema_url) override
{
return opentelemetry::nostd::shared_ptr<Tracer>(nullptr);
return nostd::shared_ptr<Tracer>(nullptr);
}
};

Expand All @@ -29,7 +30,7 @@ TEST(Provider, GetTracerProviderDefault)

TEST(Provider, SetTracerProvider)
{
auto tf = opentelemetry::nostd::shared_ptr<TracerProvider>(new TestProvider());
auto tf = nostd::shared_ptr<TracerProvider>(new TestProvider());
Provider::SetTracerProvider(tf);
ASSERT_EQ(tf, Provider::GetTracerProvider());
}
7 changes: 4 additions & 3 deletions api/test/trace/span_benchmark.cc
Original file line number Diff line number Diff line change
Expand Up @@ -14,13 +14,14 @@
using opentelemetry::trace::SpanContext;
namespace trace_api = opentelemetry::trace;
namespace nostd = opentelemetry::nostd;
namespace context = opentelemetry::context;

namespace
{

std::shared_ptr<opentelemetry::trace::Tracer> initTracer()
std::shared_ptr<trace_api::Tracer> initTracer()
{
return std::shared_ptr<opentelemetry::trace::Tracer>(new trace_api::NoopTracer());
return std::shared_ptr<trace_api::Tracer>(new trace_api::NoopTracer());
}

// Test to measure performance for span creation
Expand Down Expand Up @@ -108,7 +109,7 @@ void BM_SpanCreationWitContextPropagation(benchmark::State &state)

while (state.KeepRunning())
{
auto current_ctx = opentelemetry::context::RuntimeContext::GetCurrent();
auto current_ctx = context::RuntimeContext::GetCurrent();
auto outer_span_context = SpanContext(trace_id, span_id, trace_api::TraceFlags(), false);
auto outer_span =
nostd::shared_ptr<trace_api::Span>(new trace_api::DefaultSpan(outer_span_context));
Expand Down
5 changes: 3 additions & 2 deletions api/test/trace/span_context_test.cc
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@
#include <gtest/gtest.h>

using opentelemetry::trace::SpanContext;
namespace trace_api = opentelemetry::trace;

TEST(SpanContextTest, IsSampled)
{
Expand Down Expand Up @@ -49,6 +50,6 @@ TEST(SpanContextTest, Invalid)
EXPECT_FALSE(s1.IsValid());

// Test that trace id and span id are invalid
EXPECT_EQ(s1.trace_id(), opentelemetry::trace::TraceId());
EXPECT_EQ(s1.span_id(), opentelemetry::trace::SpanId());
EXPECT_EQ(s1.trace_id(), trace_api::TraceId());
EXPECT_EQ(s1.span_id(), trace_api::SpanId());
}
31 changes: 17 additions & 14 deletions examples/batch/main.cc
Original file line number Diff line number Diff line change
Expand Up @@ -10,19 +10,23 @@
#include <chrono>
#include <thread>

constexpr int kNumSpans = 10;
constexpr int kNumSpans = 10;
namespace trace_api = opentelemetry::trace;
namespace resource = opentelemetry::sdk::resource;
namespace exporter_trace = opentelemetry::exporter::trace;
namespace trace_sdk = opentelemetry::sdk::trace;
namespace nostd = opentelemetry::nostd;

namespace
{

void initTracer()
{
auto exporter = std::unique_ptr<sdktrace::SpanExporter>(
new opentelemetry::exporter::trace::OStreamSpanExporter);
auto exporter = std::unique_ptr<trace_sdk::SpanExporter>(new exporter_trace::OStreamSpanExporter);

// CONFIGURE BATCH SPAN PROCESSOR PARAMETERS

sdktrace::BatchSpanProcessorOptions options{};
trace_sdk::BatchSpanProcessorOptions options{};
// We make the queue size `KNumSpans`*2+5 because when the queue is half full, a preemptive notif
// is sent to start an export call, which we want to avoid in this simple example.
options.max_queue_size = kNumSpans * 2 + 5;
Expand All @@ -31,22 +35,21 @@ void initTracer()
// We export `kNumSpans` after every `schedule_delay_millis` milliseconds.
options.max_export_batch_size = kNumSpans;

opentelemetry::sdk::resource::ResourceAttributes attributes = {{"service", "test_service"},
{"version", (uint32_t)1}};
auto resource = opentelemetry::sdk::resource::Resource::Create(attributes);
resource::ResourceAttributes attributes = {{"service", "test_service"}, {"version", (uint32_t)1}};
auto resource = resource::Resource::Create(attributes);

auto processor = std::unique_ptr<sdktrace::SpanProcessor>(
new sdktrace::BatchSpanProcessor(std::move(exporter), options));
auto processor = std::unique_ptr<trace_sdk::SpanProcessor>(
new trace_sdk::BatchSpanProcessor(std::move(exporter), options));

auto provider = nostd::shared_ptr<opentelemetry::trace::TracerProvider>(
new sdktrace::TracerProvider(std::move(processor), resource));
auto provider = nostd::shared_ptr<trace_api::TracerProvider>(
new trace_sdk::TracerProvider(std::move(processor), resource));
// Set the global trace provider.
opentelemetry::trace::Provider::SetTracerProvider(provider);
trace_api::Provider::SetTracerProvider(provider);
}

nostd::shared_ptr<opentelemetry::trace::Tracer> get_tracer()
nostd::shared_ptr<trace_api::Tracer> get_tracer()
{
auto provider = opentelemetry::trace::Provider::GetTracerProvider();
auto provider = trace_api::Provider::GetTracerProvider();
return provider->GetTracer("foo_library");
}

Expand Down
Loading