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

Implement basic OTLP Recordable #127

Merged
merged 26 commits into from
Jul 2, 2020
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
26 commits
Select commit Hold shift + click to select a range
99e3672
Add basic recordable functions
nadiaciobanu Jun 22, 2020
e326783
Add start time
nadiaciobanu Jun 23, 2020
bb8b215
Add duration and ids
nadiaciobanu Jun 23, 2020
257d03a
Add recordable test
nadiaciobanu Jun 23, 2020
249b308
Move SetIds to its own test
nadiaciobanu Jun 24, 2020
b85b49a
Fix SetIds by not converting to hex
nadiaciobanu Jun 24, 2020
78cf8e0
Reformat tests
nadiaciobanu Jun 24, 2020
a53e871
Fix Recordable instantiation in test
nadiaciobanu Jun 24, 2020
91f454a
Merge branch 'master' into basic-otlp-recordable
nadiaciobanu Jun 24, 2020
ce61e40
Update code for new function (SetAttribute)
nadiaciobanu Jun 24, 2020
11ce576
Fix undefined reference error
nadiaciobanu Jun 24, 2020
bc98b81
Fix memory leak
nadiaciobanu Jun 25, 2020
a61c01f
Address review comments
nadiaciobanu Jun 25, 2020
afa17f1
Update Bazel version for MacOS check
nadiaciobanu Jun 25, 2020
4b16157
Address additional review comments
nadiaciobanu Jun 25, 2020
4b41538
Add recordable_test to CMakeLists
nadiaciobanu Jun 26, 2020
91f55b6
Fix CMakeList
nadiaciobanu Jun 26, 2020
1ac3883
Fix CMakeLists by using opentelemetry_trace
nadiaciobanu Jun 26, 2020
f2e7430
Link test with proper library
nadiaciobanu Jun 29, 2020
5ffea5a
Link to proto object library
nadiaciobanu Jun 29, 2020
7a21795
Add protobuf dependency
nadiaciobanu Jun 29, 2020
bbbca02
Merge branch 'master' into basic-otlp-recordable
nadiaciobanu Jun 30, 2020
b9e135b
Simplify namespaces in test
nadiaciobanu Jun 30, 2020
60373bc
Merge branch 'master' into basic-otlp-recordable
nadiaciobanu Jul 2, 2020
bc0f953
Merge branch 'master' into basic-otlp-recordable
nadiaciobanu Jul 2, 2020
053b7f9
Merge branch 'basic-otlp-recordable' of https://github.com/nadiacioba…
nadiaciobanu Jul 2, 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
9 changes: 9 additions & 0 deletions exporters/otlp/BUILD
Original file line number Diff line number Diff line change
Expand Up @@ -28,3 +28,12 @@ cc_library(
"@com_github_opentelemetry_proto//:trace_proto_cc",
],
)

cc_test(
nadiaciobanu marked this conversation as resolved.
Show resolved Hide resolved
name = "recordable_test",
srcs = ["recordable_test.cc"],
deps = [
":recordable",
"@com_google_googletest//:gtest_main",
],
)
8 changes: 8 additions & 0 deletions exporters/otlp/CMakeLists.txt
Original file line number Diff line number Diff line change
@@ -1,3 +1,11 @@
add_library(opentelemetry_exporter_otprotocol recordable.cc)
target_link_libraries(opentelemetry_exporter_otprotocol
$<TARGET_OBJECTS:opentelemetry_proto>)

add_executable(recordable_test recordable_test.cc)
target_link_libraries(recordable_test
${GTEST_BOTH_LIBRARIES}
${CMAKE_THREAD_LIBS_INIT}
opentelemetry_exporter_otprotocol
protobuf::libprotobuf)
gtest_add_tests(TARGET recordable_test TEST_PREFIX exporter. TEST_LIST recordable_test)
29 changes: 29 additions & 0 deletions exporters/otlp/recordable.cc
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,23 @@ namespace exporter
{
namespace otlp
{
void Recordable::SetIds(trace::TraceId trace_id,
trace::SpanId span_id,
trace::SpanId parent_span_id) noexcept
{
span_.set_trace_id(reinterpret_cast<const char *>(trace_id.Id().data()), trace::TraceId::kSize);
span_.set_span_id(reinterpret_cast<const char *>(span_id.Id().data()), trace::SpanId::kSize);
span_.set_parent_span_id(reinterpret_cast<const char *>(parent_span_id.Id().data()),
trace::SpanId::kSize);
}

void Recordable::SetAttribute(nostd::string_view key,
const opentelemetry::common::AttributeValue &&value) noexcept
{
(void)key;
(void)value;
}

void Recordable::AddEvent(nostd::string_view name, core::SystemTimestamp timestamp) noexcept
{
(void)name;
Expand All @@ -20,6 +37,18 @@ void Recordable::SetName(nostd::string_view name) noexcept
{
span_.set_name(name.data(), name.size());
}

void Recordable::SetStartTime(opentelemetry::core::SystemTimestamp start_time) noexcept
{
const uint64_t nano_unix_time = start_time.time_since_epoch().count();
span_.set_start_time_unixnano(nano_unix_time);
}

void Recordable::SetDuration(std::chrono::nanoseconds duration) noexcept
{
const uint64_t unix_end_time = span_.start_time_unixnano() + duration.count();
span_.set_end_time_unixnano(unix_end_time);
}
} // namespace otlp
} // namespace exporter
OPENTELEMETRY_END_NAMESPACE
12 changes: 11 additions & 1 deletion exporters/otlp/recordable.h
Original file line number Diff line number Diff line change
Expand Up @@ -14,13 +14,23 @@ class Recordable final : public sdk::trace::Recordable
public:
const proto::trace::v1::Span &span() const noexcept { return span_; }

// sdk::trace::Recordable
void SetIds(trace::TraceId trace_id,
trace::SpanId span_id,
trace::SpanId parent_span_id) noexcept override;

void SetAttribute(nostd::string_view key,
const opentelemetry::common::AttributeValue &&value) noexcept override;

void AddEvent(nostd::string_view name, core::SystemTimestamp timestamp) noexcept override;

void SetStatus(trace::CanonicalCode code, nostd::string_view description) noexcept override;

void SetName(nostd::string_view name) noexcept override;

void SetStartTime(opentelemetry::core::SystemTimestamp start_time) noexcept override;

void SetDuration(std::chrono::nanoseconds duration) noexcept override;

private:
proto::trace::v1::Span span_;
};
Expand Down
73 changes: 73 additions & 0 deletions exporters/otlp/recordable_test.cc
Original file line number Diff line number Diff line change
@@ -0,0 +1,73 @@
#include "exporters/otlp/recordable.h"

#include <gtest/gtest.h>

OPENTELEMETRY_BEGIN_NAMESPACE
namespace exporter
{
namespace otlp
{
TEST(Recordable, SetIds)
{
const trace::TraceId trace_id(
std::array<const uint8_t, trace::TraceId::kSize>(
{0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 1}));

const trace::SpanId span_id(
std::array<const uint8_t, trace::SpanId::kSize>(
{0, 0, 0, 0, 0, 0, 0, 2}));

const trace::SpanId parent_span_id(
std::array<const uint8_t, trace::SpanId::kSize>(
{0, 0, 0, 0, 0, 0, 0, 3}));

Recordable rec;

rec.SetIds(trace_id, span_id, parent_span_id);

EXPECT_EQ(rec.span().trace_id(),
std::string(reinterpret_cast<const char *>(trace_id.Id().data()), trace::TraceId::kSize));
EXPECT_EQ(rec.span().span_id(),
std::string(reinterpret_cast<const char *>(span_id.Id().data()), trace::SpanId::kSize));
EXPECT_EQ(rec.span().parent_span_id(),
std::string(reinterpret_cast<const char *>(parent_span_id.Id().data()), trace::SpanId::kSize));
}

TEST(Recordable, SetName)
{
Recordable rec;
nostd::string_view name = "TestSpan";
rec.SetName(name);
EXPECT_EQ(rec.span().name(), name);
}

TEST(Recordable, SetStartTime)
{
Recordable rec;
std::chrono::system_clock::time_point start_time = std::chrono::system_clock::now();
core::SystemTimestamp start_timestamp(start_time);

uint64_t unix_start =
std::chrono::duration_cast<std::chrono::nanoseconds>(start_time.time_since_epoch()).count();

rec.SetStartTime(start_timestamp);
EXPECT_EQ(rec.span().start_time_unixnano(), unix_start);
}

TEST(Recordable, SetDuration)
{
Recordable rec;
// Start time is 0
core::SystemTimestamp start_timestamp;

std::chrono::nanoseconds duration(10);
uint64_t unix_end = duration.count();

rec.SetStartTime(start_timestamp);
rec.SetDuration(duration);

EXPECT_EQ(rec.span().end_time_unixnano(), unix_end);
}
} // namespace otlp
} // namespace exporter
OPENTELEMETRY_END_NAMESPACE