From 3503d72e7f5d404281a192ee801b7d17fdf69111 Mon Sep 17 00:00:00 2001 From: Ryan Burn Date: Mon, 2 Mar 2020 23:25:43 -0800 Subject: [PATCH 01/44] Start Recorder api --- sdk/src/{opentelemetry => }/context/TBD | 0 .../distributedcontext/TBD | 0 sdk/src/{opentelemetry => }/internal/TBD | 0 sdk/src/{opentelemetry => }/logs/TBD | 0 sdk/src/{opentelemetry => }/metrics/TBD | 0 sdk/src/opentelemetry/trace/tracer_handle.h | 27 ----------------- sdk/src/{opentelemetry => }/resource/TBD | 0 sdk/src/trace/BUILD | 24 +++++++++++++++ sdk/src/trace/recordable.h | 29 +++++++++++++++++++ sdk/src/trace/recorder.h | 22 ++++++++++++++ sdk/src/trace/span.cc | 19 ++++++++++++ sdk/src/trace/span.h | 25 ++++++++++++++++ sdk/src/trace/tracer.cc | 19 ++++++++++++ sdk/src/trace/tracer.h | 28 ++++++++++++++++++ 14 files changed, 166 insertions(+), 27 deletions(-) rename sdk/src/{opentelemetry => }/context/TBD (100%) rename sdk/src/{opentelemetry => }/distributedcontext/TBD (100%) rename sdk/src/{opentelemetry => }/internal/TBD (100%) rename sdk/src/{opentelemetry => }/logs/TBD (100%) rename sdk/src/{opentelemetry => }/metrics/TBD (100%) delete mode 100644 sdk/src/opentelemetry/trace/tracer_handle.h rename sdk/src/{opentelemetry => }/resource/TBD (100%) create mode 100644 sdk/src/trace/BUILD create mode 100644 sdk/src/trace/recordable.h create mode 100644 sdk/src/trace/recorder.h create mode 100644 sdk/src/trace/span.cc create mode 100644 sdk/src/trace/span.h create mode 100644 sdk/src/trace/tracer.cc create mode 100644 sdk/src/trace/tracer.h diff --git a/sdk/src/opentelemetry/context/TBD b/sdk/src/context/TBD similarity index 100% rename from sdk/src/opentelemetry/context/TBD rename to sdk/src/context/TBD diff --git a/sdk/src/opentelemetry/distributedcontext/TBD b/sdk/src/distributedcontext/TBD similarity index 100% rename from sdk/src/opentelemetry/distributedcontext/TBD rename to sdk/src/distributedcontext/TBD diff --git a/sdk/src/opentelemetry/internal/TBD b/sdk/src/internal/TBD similarity index 100% rename from sdk/src/opentelemetry/internal/TBD rename to sdk/src/internal/TBD diff --git a/sdk/src/opentelemetry/logs/TBD b/sdk/src/logs/TBD similarity index 100% rename from sdk/src/opentelemetry/logs/TBD rename to sdk/src/logs/TBD diff --git a/sdk/src/opentelemetry/metrics/TBD b/sdk/src/metrics/TBD similarity index 100% rename from sdk/src/opentelemetry/metrics/TBD rename to sdk/src/metrics/TBD diff --git a/sdk/src/opentelemetry/trace/tracer_handle.h b/sdk/src/opentelemetry/trace/tracer_handle.h deleted file mode 100644 index 15d5a29953..0000000000 --- a/sdk/src/opentelemetry/trace/tracer_handle.h +++ /dev/null @@ -1,27 +0,0 @@ -#pragma once - -#include "opentelemetry/plugin/tracer_handle.h" - -namespace opentelemetry -{ -namespace sdk -{ -namespace trace -{ -namespace api = opentelemetry::trace; - -class TracerHandle final : public plugin::TracerHandle -{ -public: - explicit TracerHandle(std::shared_ptr tracer) noexcept : tracer_{std::move(tracer)} - {} - - // opentelemetry::plugin::TracerHandle - api::Tracer &tracer() const noexcept override { return tracer_; } - -private: - std::shared_ptr tracer_; -}; -} // namespace trace -} // namespace sdk -} // namespace opentelemetry diff --git a/sdk/src/opentelemetry/resource/TBD b/sdk/src/resource/TBD similarity index 100% rename from sdk/src/opentelemetry/resource/TBD rename to sdk/src/resource/TBD diff --git a/sdk/src/trace/BUILD b/sdk/src/trace/BUILD new file mode 100644 index 0000000000..997958e41e --- /dev/null +++ b/sdk/src/trace/BUILD @@ -0,0 +1,24 @@ +# Copyright 2019, OpenTelemetry Authors +# +# Licensed under the Apache License, Version 2.0 (the "License"); +# you may not use this file except in compliance with the License. +# You may obtain a copy of the License at +# +# http://www.apache.org/licenses/LICENSE-2.0 +# +# Unless required by applicable law or agreed to in writing, software +# distributed under the License is distributed on an "AS IS" BASIS, +# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +# See the License for the specific language governing permissions and +# limitations under the License. + +package(default_visibility = ["//visibility:public"]) + +cc_library( + name = "trace", + hdrs = glob(["**/*.h"]), + srcs = glob(["**/*.cc"]), + deps = [ + "//api", + ], +) diff --git a/sdk/src/trace/recordable.h b/sdk/src/trace/recordable.h new file mode 100644 index 0000000000..25a1f4ca1c --- /dev/null +++ b/sdk/src/trace/recordable.h @@ -0,0 +1,29 @@ +#pragma once + +#include "opentelemetry/core/timestamp.h" +#include "opentelemetry/nostd/string_view.h" +#include "opentelemetry/trace/canonical_code.h" + +namespace opentelemetry +{ +namespace sdk { +namespace trace +{ +namespace trace_api = opentelemetry::trace; + +class Recordable +{ +public: + virtual ~Recordable() = default; + + virtual void AddEvent(nostd::string_view name, + std::chrono::nanoseconds time_since_epoch) noexcept = 0; + + virtual void SetStatus(trace_api::CanonicalCode code, + nostd::string_view description) noexcept = 0; + + virtual void SetName(nostd::string_view name) noexcept = 0; +}; +} // namespace trace +} // namespace sdk +} // namespace opentelemetry diff --git a/sdk/src/trace/recorder.h b/sdk/src/trace/recorder.h new file mode 100644 index 0000000000..9823257bea --- /dev/null +++ b/sdk/src/trace/recorder.h @@ -0,0 +1,22 @@ +#pragma once + +#include "opentelemetry/trace/trace_id.h" +#include "opentelemetry/trace/span_id.h" +#include "sdk/src/trace/recordable.h" + +namespace opentelemetry +{ +namespace sdk { +namespace trace +{ +class Recorder { + public: + virtual ~Recorder() = default; + + virtual std::unique_ptr MakeRecordable() noexcept = 0; + + virtual void Record(std::unique_ptr&& recordable) noexcept = 0; +}; +} // namespace trace +} // namespace sdk +} // namespace opentelemetry diff --git a/sdk/src/trace/span.cc b/sdk/src/trace/span.cc new file mode 100644 index 0000000000..85254ff27e --- /dev/null +++ b/sdk/src/trace/span.cc @@ -0,0 +1,19 @@ +#include "sdk/src/trace/span.h" + +namespace opentelemetry +{ +namespace sdk +{ +namespace trace +{ +Span::Span(std::shared_ptr &&tracer, + nostd::string_view name, + const trace_api::StartSpanOptions &options) noexcept + : tracer_{std::move(tracer)}, recordable_{tracer_->recorder().MakeRecordable()} +{ + (void)name; + (void)options; +} +} // namespace trace +} // namespace sdk +} // namespace opentelemetry diff --git a/sdk/src/trace/span.h b/sdk/src/trace/span.h new file mode 100644 index 0000000000..3ffc97e608 --- /dev/null +++ b/sdk/src/trace/span.h @@ -0,0 +1,25 @@ +#pragma once + +#include "sdk/src/trace/tracer.h" + +#include + +namespace opentelemetry { +namespace sdk { +namespace trace { +namespace trace_api = opentelemetry::trace; + +class Span final : public trace_api::Span { + public: + explicit Span(std::shared_ptr &&tracer, + nostd::string_view name, + const trace_api::StartSpanOptions &options) noexcept; + + private: + std::shared_ptr tracer_; + std::mutex mutex_; + std::unique_ptr recordable_; +}; +} // namespace trace +} // namespace sdk +} // namespace opentelemetry diff --git a/sdk/src/trace/tracer.cc b/sdk/src/trace/tracer.cc new file mode 100644 index 0000000000..18808f19d2 --- /dev/null +++ b/sdk/src/trace/tracer.cc @@ -0,0 +1,19 @@ +#include "sdk/src/trace/tracer.h" + +namespace opentelemetry +{ +namespace sdk +{ +namespace trace +{ +nostd::unique_ptr Tracer::StartSpan( + nostd::string_view name, + const trace_api::StartSpanOptions &options) noexcept +{ + (void)name; + (void)options; + return nullptr; +} +} // namespace trace +} // namespace sdk +} // namespace opentelemetry diff --git a/sdk/src/trace/tracer.h b/sdk/src/trace/tracer.h new file mode 100644 index 0000000000..aee93ab45f --- /dev/null +++ b/sdk/src/trace/tracer.h @@ -0,0 +1,28 @@ +#pragma once + +#include "opentelemetry/trace/tracer.h" +#include "sdk/src/trace/recorder.h" + +#include + +namespace opentelemetry { +namespace sdk { +namespace trace { +class Tracer final : public trace_api::Tracer, public std::enable_shared_from_this +{ +public: + explicit Tracer(std::unique_ptr &&recorder) noexcept : recorder_{std::move(recorder)} {} + + Recorder &recorder() const noexcept { return *recorder_; } + + // trace_api::Tracer + nostd::unique_ptr StartSpan( + nostd::string_view name, + const trace_api::StartSpanOptions &options = {}) noexcept override; + +private: + std::unique_ptr recorder_; +}; +} // namespace trace +} // namespace sdk +} // namespace opentelemetry From 79b4f1d5cf546312090f734835b6a623f0d7759d Mon Sep 17 00:00:00 2001 From: Ryan Burn Date: Mon, 2 Mar 2020 23:43:52 -0800 Subject: [PATCH 02/44] Fill out Span api --- sdk/src/trace/span.cc | 35 +++++++++++++++++++++++++++++++ sdk/src/trace/span.h | 49 ++++++++++++++++++++++++++++++------------- 2 files changed, 69 insertions(+), 15 deletions(-) diff --git a/sdk/src/trace/span.cc b/sdk/src/trace/span.cc index 85254ff27e..533745e56b 100644 --- a/sdk/src/trace/span.cc +++ b/sdk/src/trace/span.cc @@ -14,6 +14,41 @@ Span::Span(std::shared_ptr &&tracer, (void)name; (void)options; } + +void Span::AddEvent(nostd::string_view name) noexcept +{ + (void)name; +} + +void Span::AddEvent(nostd::string_view name, core::SystemTimestamp timestamp) noexcept +{ + (void)name; + (void)timestamp; +} + +void Span::AddEvent(nostd::string_view name, core::SteadyTimestamp timestamp) noexcept +{ + (void)name; + (void)timestamp; +} + +void Span::SetStatus(trace_api::CanonicalCode code, nostd::string_view description) noexcept +{ + (void)code; + (void)description; +} + +void Span::UpdateName(nostd::string_view name) noexcept +{ + (void)name; +} + +void Span::End() noexcept {} + +bool Span::IsRecording() const noexcept +{ + return true; +} } // namespace trace } // namespace sdk } // namespace opentelemetry diff --git a/sdk/src/trace/span.h b/sdk/src/trace/span.h index 3ffc97e608..5240562c3b 100644 --- a/sdk/src/trace/span.h +++ b/sdk/src/trace/span.h @@ -4,22 +4,41 @@ #include -namespace opentelemetry { -namespace sdk { -namespace trace { +namespace opentelemetry +{ +namespace sdk +{ +namespace trace +{ namespace trace_api = opentelemetry::trace; -class Span final : public trace_api::Span { - public: - explicit Span(std::shared_ptr &&tracer, - nostd::string_view name, - const trace_api::StartSpanOptions &options) noexcept; +class Span final : public trace_api::Span +{ +public: + explicit Span(std::shared_ptr &&tracer, + nostd::string_view name, + const trace_api::StartSpanOptions &options) noexcept; - private: - std::shared_ptr tracer_; - std::mutex mutex_; - std::unique_ptr recordable_; + void AddEvent(nostd::string_view name) noexcept override; + + void AddEvent(nostd::string_view name, core::SystemTimestamp timestamp) noexcept override; + void AddEvent(nostd::string_view name, core::SteadyTimestamp timestamp) noexcept override; + + void SetStatus(trace_api::CanonicalCode code, nostd::string_view description) noexcept override; + + void UpdateName(nostd::string_view name) noexcept override; + + void End() noexcept override; + + bool IsRecording() const noexcept override; + + trace_api::Tracer &tracer() const noexcept override { return *tracer_; } + +private: + std::shared_ptr tracer_; + std::mutex mutex_; + std::unique_ptr recordable_; }; -} // namespace trace -} // namespace sdk -} // namespace opentelemetry +} // namespace trace +} // namespace sdk +} // namespace opentelemetry From 8bcff6e424025cc910bca24234a174c57cee2040 Mon Sep 17 00:00:00 2001 From: Ryan Burn Date: Tue, 3 Mar 2020 00:06:29 -0800 Subject: [PATCH 03/44] Reformat --- sdk/src/trace/span.cc | 23 ++++++++++++++++++++--- 1 file changed, 20 insertions(+), 3 deletions(-) diff --git a/sdk/src/trace/span.cc b/sdk/src/trace/span.cc index 533745e56b..8fd220e773 100644 --- a/sdk/src/trace/span.cc +++ b/sdk/src/trace/span.cc @@ -11,8 +11,11 @@ Span::Span(std::shared_ptr &&tracer, const trace_api::StartSpanOptions &options) noexcept : tracer_{std::move(tracer)}, recordable_{tracer_->recorder().MakeRecordable()} { - (void)name; (void)options; + if (recordable_ == nullptr) { + return; + } + recordable_->SetName(name); } void Span::AddEvent(nostd::string_view name) noexcept @@ -40,10 +43,24 @@ void Span::SetStatus(trace_api::CanonicalCode code, nostd::string_view descripti void Span::UpdateName(nostd::string_view name) noexcept { - (void)name; + std::lock_guard lock_guard{mutex_}; + if (recordable_ == nullptr) + { + return; + } + recordable_->SetName(name); } -void Span::End() noexcept {} +void Span::End() noexcept +{ + std::lock_guard lock_guard{mutex_}; + if (recordable_ == nullptr) + { + return; + } + tracer_->recorder().Record(std::move(recordable_)); + recordable_.reset(); +} bool Span::IsRecording() const noexcept { From c5e9a9e53357a0282edf3752a0624a5e5c8129d8 Mon Sep 17 00:00:00 2001 From: Ryan Burn Date: Tue, 3 Mar 2020 13:43:27 -0800 Subject: [PATCH 04/44] Fill out Tracer class --- sdk/src/trace/span.cc | 12 ++++++++++-- sdk/src/trace/span.h | 2 ++ sdk/src/trace/tracer.cc | 7 ++++--- 3 files changed, 16 insertions(+), 5 deletions(-) diff --git a/sdk/src/trace/span.cc b/sdk/src/trace/span.cc index 8fd220e773..726d63c7f5 100644 --- a/sdk/src/trace/span.cc +++ b/sdk/src/trace/span.cc @@ -18,6 +18,10 @@ Span::Span(std::shared_ptr &&tracer, recordable_->SetName(name); } +Span::~Span() { + End(); +} + void Span::AddEvent(nostd::string_view name) noexcept { (void)name; @@ -37,8 +41,12 @@ void Span::AddEvent(nostd::string_view name, core::SteadyTimestamp timestamp) no void Span::SetStatus(trace_api::CanonicalCode code, nostd::string_view description) noexcept { - (void)code; - (void)description; + std::lock_guard lock_guard{mutex_}; + if (recordable_ == nullptr) + { + return; + } + recordable_->SetStatus(code, description); } void Span::UpdateName(nostd::string_view name) noexcept diff --git a/sdk/src/trace/span.h b/sdk/src/trace/span.h index 5240562c3b..8eb6fb178b 100644 --- a/sdk/src/trace/span.h +++ b/sdk/src/trace/span.h @@ -19,6 +19,8 @@ class Span final : public trace_api::Span nostd::string_view name, const trace_api::StartSpanOptions &options) noexcept; + ~Span() override; + void AddEvent(nostd::string_view name) noexcept override; void AddEvent(nostd::string_view name, core::SystemTimestamp timestamp) noexcept override; diff --git a/sdk/src/trace/tracer.cc b/sdk/src/trace/tracer.cc index 18808f19d2..a923f17133 100644 --- a/sdk/src/trace/tracer.cc +++ b/sdk/src/trace/tracer.cc @@ -1,5 +1,7 @@ #include "sdk/src/trace/tracer.h" +#include "sdk/src/trace/span.h" + namespace opentelemetry { namespace sdk @@ -10,9 +12,8 @@ nostd::unique_ptr Tracer::StartSpan( nostd::string_view name, const trace_api::StartSpanOptions &options) noexcept { - (void)name; - (void)options; - return nullptr; + return nostd::unique_ptr{new (std::nothrow) + Span{this->shared_from_this(), name, options}}; } } // namespace trace } // namespace sdk From a69206f70c1dd33bfc2cc3c71ecb0e901a870729 Mon Sep 17 00:00:00 2001 From: Ryan Burn Date: Tue, 3 Mar 2020 16:58:34 -0800 Subject: [PATCH 05/44] Add cmake build --- CMakeLists.txt | 3 +++ sdk/src/trace/BUILD | 1 + sdk/src/trace/CMakeLists.txt | 3 +++ sdk/src/trace/recorder.h | 2 +- sdk/src/trace/span.cc | 2 +- sdk/src/trace/span.h | 2 +- sdk/src/trace/tracer.cc | 4 ++-- sdk/src/trace/tracer.h | 2 +- 8 files changed, 13 insertions(+), 6 deletions(-) create mode 100644 sdk/src/trace/CMakeLists.txt diff --git a/CMakeLists.txt b/CMakeLists.txt index c34736db49..c10f92d39d 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -20,4 +20,7 @@ endif() include_directories(api/include) add_subdirectory(api) +include_directories(sdk/include) +include_directories(sdk) +add_subdirectory(sdk) add_subdirectory(examples) diff --git a/sdk/src/trace/BUILD b/sdk/src/trace/BUILD index 997958e41e..540fc8fccb 100644 --- a/sdk/src/trace/BUILD +++ b/sdk/src/trace/BUILD @@ -21,4 +21,5 @@ cc_library( deps = [ "//api", ], + include_prefix = "src/trace", ) diff --git a/sdk/src/trace/CMakeLists.txt b/sdk/src/trace/CMakeLists.txt new file mode 100644 index 0000000000..e2ec1f99cb --- /dev/null +++ b/sdk/src/trace/CMakeLists.txt @@ -0,0 +1,3 @@ +add_library(opentelemetry_trace + tracer.cc + span.cc) diff --git a/sdk/src/trace/recorder.h b/sdk/src/trace/recorder.h index 9823257bea..c22f443c0a 100644 --- a/sdk/src/trace/recorder.h +++ b/sdk/src/trace/recorder.h @@ -2,7 +2,7 @@ #include "opentelemetry/trace/trace_id.h" #include "opentelemetry/trace/span_id.h" -#include "sdk/src/trace/recordable.h" +#include "src/trace/recordable.h" namespace opentelemetry { diff --git a/sdk/src/trace/span.cc b/sdk/src/trace/span.cc index 726d63c7f5..3711ef5c90 100644 --- a/sdk/src/trace/span.cc +++ b/sdk/src/trace/span.cc @@ -1,4 +1,4 @@ -#include "sdk/src/trace/span.h" +#include "src/trace/span.h" namespace opentelemetry { diff --git a/sdk/src/trace/span.h b/sdk/src/trace/span.h index 8eb6fb178b..8978cd3f83 100644 --- a/sdk/src/trace/span.h +++ b/sdk/src/trace/span.h @@ -1,6 +1,6 @@ #pragma once -#include "sdk/src/trace/tracer.h" +#include "src/trace/tracer.h" #include diff --git a/sdk/src/trace/tracer.cc b/sdk/src/trace/tracer.cc index a923f17133..824c560cfe 100644 --- a/sdk/src/trace/tracer.cc +++ b/sdk/src/trace/tracer.cc @@ -1,6 +1,6 @@ -#include "sdk/src/trace/tracer.h" +#include "src/trace/tracer.h" -#include "sdk/src/trace/span.h" +#include "src/trace/span.h" namespace opentelemetry { diff --git a/sdk/src/trace/tracer.h b/sdk/src/trace/tracer.h index aee93ab45f..1f542770d6 100644 --- a/sdk/src/trace/tracer.h +++ b/sdk/src/trace/tracer.h @@ -1,7 +1,7 @@ #pragma once #include "opentelemetry/trace/tracer.h" -#include "sdk/src/trace/recorder.h" +#include "src/trace/recorder.h" #include From 87170e32f734bb1dfc62c06048c143f92023de02 Mon Sep 17 00:00:00 2001 From: Ryan Burn Date: Tue, 3 Mar 2020 17:14:54 -0800 Subject: [PATCH 06/44] Add commenting --- sdk/CMakeLists.txt | 1 + sdk/src/CMakeLists.txt | 1 + sdk/src/trace/recordable.h | 22 ++++++++++++++++++++-- sdk/src/trace/recorder.h | 25 +++++++++++++++++-------- 4 files changed, 39 insertions(+), 10 deletions(-) create mode 100644 sdk/CMakeLists.txt create mode 100644 sdk/src/CMakeLists.txt diff --git a/sdk/CMakeLists.txt b/sdk/CMakeLists.txt new file mode 100644 index 0000000000..febd4f0ab6 --- /dev/null +++ b/sdk/CMakeLists.txt @@ -0,0 +1 @@ +add_subdirectory(src) diff --git a/sdk/src/CMakeLists.txt b/sdk/src/CMakeLists.txt new file mode 100644 index 0000000000..2cea47fa7b --- /dev/null +++ b/sdk/src/CMakeLists.txt @@ -0,0 +1 @@ +add_subdirectory(trace) diff --git a/sdk/src/trace/recordable.h b/sdk/src/trace/recordable.h index 25a1f4ca1c..a1dd5bd7c0 100644 --- a/sdk/src/trace/recordable.h +++ b/sdk/src/trace/recordable.h @@ -6,24 +6,42 @@ namespace opentelemetry { -namespace sdk { +namespace sdk +{ namespace trace { namespace trace_api = opentelemetry::trace; +/** + * Maintains a representation of a span in a format that can be processed by a recroder. + */ class Recordable { public: virtual ~Recordable() = default; + /** + * Add an event to a span. + * @param name the name of the event + * @param time_since_epoch the timestamp of the event + */ virtual void AddEvent(nostd::string_view name, std::chrono::nanoseconds time_since_epoch) noexcept = 0; + /** + * Set the status of the span. + * @param code the status code + * @param description a description of the status + */ virtual void SetStatus(trace_api::CanonicalCode code, nostd::string_view description) noexcept = 0; + /** + * Set the name of the span. + * @param name the name to set + */ virtual void SetName(nostd::string_view name) noexcept = 0; }; } // namespace trace -} // namespace sdk +} // namespace sdk } // namespace opentelemetry diff --git a/sdk/src/trace/recorder.h b/sdk/src/trace/recorder.h index c22f443c0a..c228453769 100644 --- a/sdk/src/trace/recorder.h +++ b/sdk/src/trace/recorder.h @@ -1,22 +1,31 @@ #pragma once -#include "opentelemetry/trace/trace_id.h" #include "opentelemetry/trace/span_id.h" +#include "opentelemetry/trace/trace_id.h" #include "src/trace/recordable.h" namespace opentelemetry { -namespace sdk { +namespace sdk +{ namespace trace { -class Recorder { - public: - virtual ~Recorder() = default; +class Recorder +{ +public: + virtual ~Recorder() = default; - virtual std::unique_ptr MakeRecordable() noexcept = 0; + /** + * @return a Recordable object to maintain a data representation of a span. + */ + virtual std::unique_ptr MakeRecordable() noexcept = 0; - virtual void Record(std::unique_ptr&& recordable) noexcept = 0; + /** + * Record a span. + * @param recordable the data representation of the span. + */ + virtual void Record(std::unique_ptr &&recordable) noexcept = 0; }; } // namespace trace -} // namespace sdk +} // namespace sdk } // namespace opentelemetry From 320add049b1d4efef0af833e14b1e10038dfdb95 Mon Sep 17 00:00:00 2001 From: Ryan Burn Date: Tue, 3 Mar 2020 17:55:08 -0800 Subject: [PATCH 07/44] Fix formatting --- api/include/opentelemetry/plugin/detail/utility.h | 2 +- api/test/nostd/unique_ptr_test.cc | 3 +-- sdk/src/trace/BUILD | 4 ++-- sdk/src/trace/CMakeLists.txt | 4 +--- sdk/src/trace/span.cc | 6 ++++-- sdk/src/trace/tracer.h | 15 +++++++++------ 6 files changed, 18 insertions(+), 16 deletions(-) diff --git a/api/include/opentelemetry/plugin/detail/utility.h b/api/include/opentelemetry/plugin/detail/utility.h index 5d85f182ec..743ca54f6b 100644 --- a/api/include/opentelemetry/plugin/detail/utility.h +++ b/api/include/opentelemetry/plugin/detail/utility.h @@ -13,7 +13,7 @@ namespace detail { inline void CopyErrorMessage(const char *source, std::string &destination) noexcept #if __EXCEPTIONS -try + try #endif { if (source == nullptr) diff --git a/api/test/nostd/unique_ptr_test.cc b/api/test/nostd/unique_ptr_test.cc index ee1ae17f4a..521e8e16dc 100644 --- a/api/test/nostd/unique_ptr_test.cc +++ b/api/test/nostd/unique_ptr_test.cc @@ -108,8 +108,7 @@ TEST(UniquePtrTest, PointerOperators) unique_ptr ptr1{value}; EXPECT_EQ(&*ptr1, value); - EXPECT_EQ( - unique_ptr {}->f(), 123); + EXPECT_EQ(unique_ptr {}->f(), 123); } TEST(UniquePtrTest, Reset) diff --git a/sdk/src/trace/BUILD b/sdk/src/trace/BUILD index 540fc8fccb..3db5430e49 100644 --- a/sdk/src/trace/BUILD +++ b/sdk/src/trace/BUILD @@ -16,10 +16,10 @@ package(default_visibility = ["//visibility:public"]) cc_library( name = "trace", - hdrs = glob(["**/*.h"]), srcs = glob(["**/*.cc"]), + hdrs = glob(["**/*.h"]), + include_prefix = "src/trace", deps = [ "//api", ], - include_prefix = "src/trace", ) diff --git a/sdk/src/trace/CMakeLists.txt b/sdk/src/trace/CMakeLists.txt index e2ec1f99cb..62a2187c46 100644 --- a/sdk/src/trace/CMakeLists.txt +++ b/sdk/src/trace/CMakeLists.txt @@ -1,3 +1 @@ -add_library(opentelemetry_trace - tracer.cc - span.cc) +add_library(opentelemetry_trace tracer.cc span.cc) diff --git a/sdk/src/trace/span.cc b/sdk/src/trace/span.cc index 3711ef5c90..5ba7dc5275 100644 --- a/sdk/src/trace/span.cc +++ b/sdk/src/trace/span.cc @@ -12,13 +12,15 @@ Span::Span(std::shared_ptr &&tracer, : tracer_{std::move(tracer)}, recordable_{tracer_->recorder().MakeRecordable()} { (void)options; - if (recordable_ == nullptr) { + if (recordable_ == nullptr) + { return; } recordable_->SetName(name); } -Span::~Span() { +Span::~Span() +{ End(); } diff --git a/sdk/src/trace/tracer.h b/sdk/src/trace/tracer.h index 1f542770d6..2540c35647 100644 --- a/sdk/src/trace/tracer.h +++ b/sdk/src/trace/tracer.h @@ -5,9 +5,12 @@ #include -namespace opentelemetry { -namespace sdk { -namespace trace { +namespace opentelemetry +{ +namespace sdk +{ +namespace trace +{ class Tracer final : public trace_api::Tracer, public std::enable_shared_from_this { public: @@ -23,6 +26,6 @@ class Tracer final : public trace_api::Tracer, public std::enable_shared_from_th private: std::unique_ptr recorder_; }; -} // namespace trace -} // namespace sdk -} // namespace opentelemetry +} // namespace trace +} // namespace sdk +} // namespace opentelemetry From 1a3761e4187aadcda2679a3d480604deb661edc4 Mon Sep 17 00:00:00 2001 From: Ryan Burn Date: Tue, 3 Mar 2020 17:59:03 -0800 Subject: [PATCH 08/44] Reformat --- api/include/opentelemetry/plugin/detail/utility.h | 2 +- api/test/nostd/unique_ptr_test.cc | 3 ++- 2 files changed, 3 insertions(+), 2 deletions(-) diff --git a/api/include/opentelemetry/plugin/detail/utility.h b/api/include/opentelemetry/plugin/detail/utility.h index 743ca54f6b..5d85f182ec 100644 --- a/api/include/opentelemetry/plugin/detail/utility.h +++ b/api/include/opentelemetry/plugin/detail/utility.h @@ -13,7 +13,7 @@ namespace detail { inline void CopyErrorMessage(const char *source, std::string &destination) noexcept #if __EXCEPTIONS - try +try #endif { if (source == nullptr) diff --git a/api/test/nostd/unique_ptr_test.cc b/api/test/nostd/unique_ptr_test.cc index 521e8e16dc..ee1ae17f4a 100644 --- a/api/test/nostd/unique_ptr_test.cc +++ b/api/test/nostd/unique_ptr_test.cc @@ -108,7 +108,8 @@ TEST(UniquePtrTest, PointerOperators) unique_ptr ptr1{value}; EXPECT_EQ(&*ptr1, value); - EXPECT_EQ(unique_ptr {}->f(), 123); + EXPECT_EQ( + unique_ptr {}->f(), 123); } TEST(UniquePtrTest, Reset) From 597f0f37c1be91d73bcfe4e77949c30ff00c0217 Mon Sep 17 00:00:00 2001 From: Ryan Burn Date: Tue, 3 Mar 2020 18:29:00 -0800 Subject: [PATCH 09/44] Fix date --- sdk/src/trace/BUILD | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/sdk/src/trace/BUILD b/sdk/src/trace/BUILD index 3db5430e49..f990c57425 100644 --- a/sdk/src/trace/BUILD +++ b/sdk/src/trace/BUILD @@ -1,4 +1,4 @@ -# Copyright 2019, OpenTelemetry Authors +# Copyright 2020, OpenTelemetry Authors # # Licensed under the Apache License, Version 2.0 (the "License"); # you may not use this file except in compliance with the License. From 0d8649f74c5a5d89e3e86cd4cd29e603ca1fe592 Mon Sep 17 00:00:00 2001 From: Ryan Burn Date: Tue, 3 Mar 2020 18:29:11 -0800 Subject: [PATCH 10/44] Make mutex mutable --- sdk/src/trace/span.h | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/sdk/src/trace/span.h b/sdk/src/trace/span.h index 8978cd3f83..470406b410 100644 --- a/sdk/src/trace/span.h +++ b/sdk/src/trace/span.h @@ -38,7 +38,7 @@ class Span final : public trace_api::Span private: std::shared_ptr tracer_; - std::mutex mutex_; + mutable std::mutex mutex_; std::unique_ptr recordable_; }; } // namespace trace From c15286ecc4ded4657c42d9cc08eaea23e7659c5a Mon Sep 17 00:00:00 2001 From: Ryan Burn Date: Tue, 3 Mar 2020 19:01:48 -0800 Subject: [PATCH 11/44] s/mutex_/mu_/ --- sdk/src/trace/span.cc | 6 +++--- sdk/src/trace/span.h | 2 +- 2 files changed, 4 insertions(+), 4 deletions(-) diff --git a/sdk/src/trace/span.cc b/sdk/src/trace/span.cc index 5ba7dc5275..7009a964a8 100644 --- a/sdk/src/trace/span.cc +++ b/sdk/src/trace/span.cc @@ -43,7 +43,7 @@ void Span::AddEvent(nostd::string_view name, core::SteadyTimestamp timestamp) no void Span::SetStatus(trace_api::CanonicalCode code, nostd::string_view description) noexcept { - std::lock_guard lock_guard{mutex_}; + std::lock_guard lock_guard{mu_}; if (recordable_ == nullptr) { return; @@ -53,7 +53,7 @@ void Span::SetStatus(trace_api::CanonicalCode code, nostd::string_view descripti void Span::UpdateName(nostd::string_view name) noexcept { - std::lock_guard lock_guard{mutex_}; + std::lock_guard lock_guard{mu_}; if (recordable_ == nullptr) { return; @@ -63,7 +63,7 @@ void Span::UpdateName(nostd::string_view name) noexcept void Span::End() noexcept { - std::lock_guard lock_guard{mutex_}; + std::lock_guard lock_guard{mu_}; if (recordable_ == nullptr) { return; diff --git a/sdk/src/trace/span.h b/sdk/src/trace/span.h index 470406b410..f70d7d5e98 100644 --- a/sdk/src/trace/span.h +++ b/sdk/src/trace/span.h @@ -38,7 +38,7 @@ class Span final : public trace_api::Span private: std::shared_ptr tracer_; - mutable std::mutex mutex_; + mutable std::mutex mu_; std::unique_ptr recordable_; }; } // namespace trace From 3c6fbb060a55ae6ac2b074d3bc3d3b9d8ec48b55 Mon Sep 17 00:00:00 2001 From: Ryan Burn Date: Thu, 5 Mar 2020 15:10:10 -0800 Subject: [PATCH 12/44] Remove AddEvent with steady timestamp --- api/include/opentelemetry/plugin/tracer.h | 4 ---- api/include/opentelemetry/trace/noop.h | 1 - api/include/opentelemetry/trace/span.h | 1 - examples/plugin/plugin/tracer.cc | 2 -- sdk/src/trace/recordable.h | 5 ++--- sdk/src/trace/span.cc | 6 ------ sdk/src/trace/span.h | 1 - 7 files changed, 2 insertions(+), 18 deletions(-) diff --git a/api/include/opentelemetry/plugin/tracer.h b/api/include/opentelemetry/plugin/tracer.h index d9a68800df..76cd8249c8 100644 --- a/api/include/opentelemetry/plugin/tracer.h +++ b/api/include/opentelemetry/plugin/tracer.h @@ -24,10 +24,6 @@ class Span final : public trace::Span { span_->AddEvent(name, timestamp); } - void AddEvent(nostd::string_view name, core::SteadyTimestamp timestamp) noexcept override - { - span_->AddEvent(name, timestamp); - } void SetStatus(trace::CanonicalCode code, nostd::string_view description) noexcept override { diff --git a/api/include/opentelemetry/trace/noop.h b/api/include/opentelemetry/trace/noop.h index 60deddbf93..bef4cf8fc8 100644 --- a/api/include/opentelemetry/trace/noop.h +++ b/api/include/opentelemetry/trace/noop.h @@ -26,7 +26,6 @@ class NoopSpan final : public Span void AddEvent(nostd::string_view name) noexcept override {} void AddEvent(nostd::string_view name, core::SystemTimestamp timestamp) noexcept override {} - void AddEvent(nostd::string_view name, core::SteadyTimestamp timestamp) noexcept override {} void SetStatus(CanonicalCode code, nostd::string_view description) noexcept override {} diff --git a/api/include/opentelemetry/trace/span.h b/api/include/opentelemetry/trace/span.h index 300ec0478d..79d31d0cec 100644 --- a/api/include/opentelemetry/trace/span.h +++ b/api/include/opentelemetry/trace/span.h @@ -76,7 +76,6 @@ class Span // Adds an event to the Span, with a custom timestamp. virtual void AddEvent(nostd::string_view name, core::SystemTimestamp timestamp) noexcept = 0; - virtual void AddEvent(nostd::string_view name, core::SteadyTimestamp timestamp) noexcept = 0; // TODO // Adds an event to the Span, with a custom timestamp, and attributes. diff --git a/examples/plugin/plugin/tracer.cc b/examples/plugin/plugin/tracer.cc index 02a828e0fa..5a0c861ea6 100644 --- a/examples/plugin/plugin/tracer.cc +++ b/examples/plugin/plugin/tracer.cc @@ -26,8 +26,6 @@ class Span final : public trace::Span void AddEvent(nostd::string_view /*name*/, core::SystemTimestamp /*timestamp*/) noexcept override {} - void AddEvent(nostd::string_view /*name*/, core::SteadyTimestamp /*timestamp*/) noexcept override - {} void SetStatus(trace::CanonicalCode /*code*/, nostd::string_view /*description*/) noexcept override diff --git a/sdk/src/trace/recordable.h b/sdk/src/trace/recordable.h index a1dd5bd7c0..7335315a80 100644 --- a/sdk/src/trace/recordable.h +++ b/sdk/src/trace/recordable.h @@ -23,10 +23,9 @@ class Recordable /** * Add an event to a span. * @param name the name of the event - * @param time_since_epoch the timestamp of the event + * @param timestamp the timestamp of the event */ - virtual void AddEvent(nostd::string_view name, - std::chrono::nanoseconds time_since_epoch) noexcept = 0; + virtual void AddEvent(nostd::string_view name, core::SystemTimestamp timestamp) noexcept = 0; /** * Set the status of the span. diff --git a/sdk/src/trace/span.cc b/sdk/src/trace/span.cc index 7009a964a8..82be75d51e 100644 --- a/sdk/src/trace/span.cc +++ b/sdk/src/trace/span.cc @@ -35,12 +35,6 @@ void Span::AddEvent(nostd::string_view name, core::SystemTimestamp timestamp) no (void)timestamp; } -void Span::AddEvent(nostd::string_view name, core::SteadyTimestamp timestamp) noexcept -{ - (void)name; - (void)timestamp; -} - void Span::SetStatus(trace_api::CanonicalCode code, nostd::string_view description) noexcept { std::lock_guard lock_guard{mu_}; diff --git a/sdk/src/trace/span.h b/sdk/src/trace/span.h index f70d7d5e98..eccfd2a912 100644 --- a/sdk/src/trace/span.h +++ b/sdk/src/trace/span.h @@ -24,7 +24,6 @@ class Span final : public trace_api::Span void AddEvent(nostd::string_view name) noexcept override; void AddEvent(nostd::string_view name, core::SystemTimestamp timestamp) noexcept override; - void AddEvent(nostd::string_view name, core::SteadyTimestamp timestamp) noexcept override; void SetStatus(trace_api::CanonicalCode code, nostd::string_view description) noexcept override; From b0d1548688d148b79ae8582e251c845b9b169771 Mon Sep 17 00:00:00 2001 From: Ryan Burn Date: Thu, 5 Mar 2020 21:53:31 -0800 Subject: [PATCH 13/44] Fix typo --- sdk/src/trace/recordable.h | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/sdk/src/trace/recordable.h b/sdk/src/trace/recordable.h index 7335315a80..c342a63e18 100644 --- a/sdk/src/trace/recordable.h +++ b/sdk/src/trace/recordable.h @@ -13,7 +13,7 @@ namespace trace namespace trace_api = opentelemetry::trace; /** - * Maintains a representation of a span in a format that can be processed by a recroder. + * Maintains a representation of a span in a format that can be processed by a recorder. */ class Recordable { From 6210da020953b7b542076240baf02de462cc1806 Mon Sep 17 00:00:00 2001 From: Ryan Burn Date: Thu, 5 Mar 2020 21:55:10 -0800 Subject: [PATCH 14/44] Fill in IsRecordable --- sdk/src/trace/span.cc | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/sdk/src/trace/span.cc b/sdk/src/trace/span.cc index 82be75d51e..df869640e0 100644 --- a/sdk/src/trace/span.cc +++ b/sdk/src/trace/span.cc @@ -68,7 +68,8 @@ void Span::End() noexcept bool Span::IsRecording() const noexcept { - return true; + std::lock_guard lock_guard{mu_}; + return recordable_ != nullptr; } } // namespace trace } // namespace sdk From c619e2b7b7724c95e1137b74cbdfad35aa9b8205 Mon Sep 17 00:00:00 2001 From: Ryan Burn Date: Mon, 9 Mar 2020 23:26:18 -0700 Subject: [PATCH 15/44] Set up protobuf dependency --- CMakeLists.txt | 17 +++++++++++++++++ ci/install_protobuf.sh | 18 ++++++++++++++++++ 2 files changed, 35 insertions(+) create mode 100755 ci/install_protobuf.sh diff --git a/CMakeLists.txt b/CMakeLists.txt index c34736db49..900787c53f 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -8,10 +8,27 @@ project(opentelemetry-cpp) set(CMAKE_CXX_STANDARD 11) +option(WITH_OTPROTOCOL + "Whether to include the OpenTelemetry Protocol in the SDK" OFF) + +set(WITH_PROTOBUF OFF) +if (WITH_OTPROTOCOL) + set(WITH_PROTOBUF ON) +endif() + include(CTest) find_package(Threads) +if (WITH_PROTOBUF) + set(protobuf_MODULE_COMPATIBLE ON) + find_package(Protobuf CONFIG NAMES protobuf) + # Older versions of protobuf don't use cmake config files. + if (NOT protobuf_FOUND) + find_package(Protobuf REQUIRED) + endif() +endif() + if(BUILD_TESTING) find_package(GTest REQUIRED) find_package(benchmark REQUIRED) diff --git a/ci/install_protobuf.sh b/ci/install_protobuf.sh new file mode 100755 index 0000000000..95a48f75a6 --- /dev/null +++ b/ci/install_protobuf.sh @@ -0,0 +1,18 @@ +#!/bin/bash + +set -e + +[ -z "${PROTOBUF_VERSION}" ] && export PROTOBUF_VERSION="3.11.4" + +apt-get update +apt-get install --no-install-recommends --no-install-suggests -y \ + curl + +# Make sure you grab the latest version +cd / +curl -OL https://github.com/google/protobuf/releases/download/v${PROTOBUF_VERSION}/protobuf-cpp-${PROTOBUF_VERSION}.tar.gz +tar zxf protobuf-cpp-${PROTOBUF_VERSION}.tar.gz +cd protobuf-${PROTOBUF_VERSION} +./configure +make && make install +ldconfig From 84d5ccddb211d7643ee4102c23ccf2061fac3880 Mon Sep 17 00:00:00 2001 From: Ryan Burn Date: Tue, 10 Mar 2020 15:15:54 -0700 Subject: [PATCH 16/44] Install protobuf in docker image --- ci/Dockerfile | 2 ++ 1 file changed, 2 insertions(+) diff --git a/ci/Dockerfile b/ci/Dockerfile index ffce3429d6..a1f43af928 100644 --- a/ci/Dockerfile +++ b/ci/Dockerfile @@ -6,10 +6,12 @@ ADD setup_ci_environment.sh /setup-ci ADD setup_cmake.sh /setup-ci ADD install_gcc48.sh /setup-ci ADD install_bazelisk.sh /setup-ci +ADD install_protobuf.sh /setup-ci ADD install_format_tools.sh /setup-ci RUN /setup-ci/setup_ci_environment.sh \ && /setup-ci/setup_cmake.sh \ && /setup-ci/install_gcc48.sh \ && /setup-ci/install_bazelisk.sh \ + && /setup-ci/install_protobuf.sh \ && /setup-ci/install_format_tools.sh From eecc683a7aa10f475853879c4deb5cc0310bc351 Mon Sep 17 00:00:00 2001 From: Ryan Burn Date: Tue, 10 Mar 2020 15:34:38 -0700 Subject: [PATCH 17/44] Merge in Recordable --- sdk/src/trace/recordable.h | 6 +++--- sdk/src/trace/recorder.h | 6 +++--- sdk/src/trace/span.cc | 5 ++--- sdk/src/trace/span.h | 10 +++++----- sdk/src/trace/tracer.cc | 6 +++--- sdk/src/trace/tracer.h | 6 +++--- 6 files changed, 19 insertions(+), 20 deletions(-) diff --git a/sdk/src/trace/recordable.h b/sdk/src/trace/recordable.h index c342a63e18..8bca640c91 100644 --- a/sdk/src/trace/recordable.h +++ b/sdk/src/trace/recordable.h @@ -3,9 +3,9 @@ #include "opentelemetry/core/timestamp.h" #include "opentelemetry/nostd/string_view.h" #include "opentelemetry/trace/canonical_code.h" +#include "opentelemetry/version.h" -namespace opentelemetry -{ +OPENTELEMETRY_BEGIN_NAMESPACE namespace sdk { namespace trace @@ -43,4 +43,4 @@ class Recordable }; } // namespace trace } // namespace sdk -} // namespace opentelemetry +OPENTELEMETRY_END_NAMESPACE diff --git a/sdk/src/trace/recorder.h b/sdk/src/trace/recorder.h index c228453769..d4e95a337c 100644 --- a/sdk/src/trace/recorder.h +++ b/sdk/src/trace/recorder.h @@ -3,9 +3,9 @@ #include "opentelemetry/trace/span_id.h" #include "opentelemetry/trace/trace_id.h" #include "src/trace/recordable.h" +#include "opentelemetry/version.h" -namespace opentelemetry -{ +OPENTELEMETRY_BEGIN_NAMESPACE namespace sdk { namespace trace @@ -28,4 +28,4 @@ class Recorder }; } // namespace trace } // namespace sdk -} // namespace opentelemetry +OPENTELEMETRY_END_NAMESPACE diff --git a/sdk/src/trace/span.cc b/sdk/src/trace/span.cc index df869640e0..0597343ce0 100644 --- a/sdk/src/trace/span.cc +++ b/sdk/src/trace/span.cc @@ -1,7 +1,6 @@ #include "src/trace/span.h" -namespace opentelemetry -{ +OPENTELEMETRY_BEGIN_NAMESPACE namespace sdk { namespace trace @@ -73,4 +72,4 @@ bool Span::IsRecording() const noexcept } } // namespace trace } // namespace sdk -} // namespace opentelemetry +OPENTELEMETRY_END_NAMESPACE diff --git a/sdk/src/trace/span.h b/sdk/src/trace/span.h index eccfd2a912..f505123836 100644 --- a/sdk/src/trace/span.h +++ b/sdk/src/trace/span.h @@ -1,11 +1,11 @@ #pragma once -#include "src/trace/tracer.h" - #include -namespace opentelemetry -{ +#include "opentelemetry/version.h" +#include "src/trace/tracer.h" + +OPENTELEMETRY_BEGIN_NAMESPACE namespace sdk { namespace trace @@ -42,4 +42,4 @@ class Span final : public trace_api::Span }; } // namespace trace } // namespace sdk -} // namespace opentelemetry +OPENTELEMETRY_END_NAMESPACE diff --git a/sdk/src/trace/tracer.cc b/sdk/src/trace/tracer.cc index 824c560cfe..4a4c484bc9 100644 --- a/sdk/src/trace/tracer.cc +++ b/sdk/src/trace/tracer.cc @@ -1,9 +1,9 @@ #include "src/trace/tracer.h" +#include "opentelemetry/version.h" #include "src/trace/span.h" -namespace opentelemetry -{ +OPENTELEMETRY_BEGIN_NAMESPACE namespace sdk { namespace trace @@ -17,4 +17,4 @@ nostd::unique_ptr Tracer::StartSpan( } } // namespace trace } // namespace sdk -} // namespace opentelemetry +OPENTELEMETRY_END_NAMESPACE diff --git a/sdk/src/trace/tracer.h b/sdk/src/trace/tracer.h index 2540c35647..feaf32f479 100644 --- a/sdk/src/trace/tracer.h +++ b/sdk/src/trace/tracer.h @@ -1,12 +1,12 @@ #pragma once #include "opentelemetry/trace/tracer.h" +#include "opentelemetry/version.h" #include "src/trace/recorder.h" #include -namespace opentelemetry -{ +OPENTELEMETRY_BEGIN_NAMESPACE namespace sdk { namespace trace @@ -28,4 +28,4 @@ class Tracer final : public trace_api::Tracer, public std::enable_shared_from_th }; } // namespace trace } // namespace sdk -} // namespace opentelemetry +OPENTELEMETRY_END_NAMESPACE From 414957f487dc7badde9c6ab12e58f64b2a1ac592 Mon Sep 17 00:00:00 2001 From: Ryan Burn Date: Tue, 10 Mar 2020 15:51:15 -0700 Subject: [PATCH 18/44] Add exporter folder --- sdk/src/exporter/otprotocol/proto/README | 2 + .../otprotocol/proto/collector/README.md | 9 + .../metrics/v1/metrics_service.proto | 45 +++ .../collector/trace/v1/trace_service.proto | 48 +++ .../trace/v1/trace_service_http.yaml | 12 + .../otprotocol/proto/common/v1/common.proto | 55 +++ .../otprotocol/proto/metrics/v1/metrics.proto | 355 ++++++++++++++++++ .../proto/resource/v1/resource.proto | 34 ++ .../otprotocol/proto/trace/v1/trace.proto | 251 +++++++++++++ .../proto/trace/v1/trace_config.proto | 78 ++++ 10 files changed, 889 insertions(+) create mode 100644 sdk/src/exporter/otprotocol/proto/README create mode 100644 sdk/src/exporter/otprotocol/proto/collector/README.md create mode 100644 sdk/src/exporter/otprotocol/proto/collector/metrics/v1/metrics_service.proto create mode 100644 sdk/src/exporter/otprotocol/proto/collector/trace/v1/trace_service.proto create mode 100644 sdk/src/exporter/otprotocol/proto/collector/trace/v1/trace_service_http.yaml create mode 100644 sdk/src/exporter/otprotocol/proto/common/v1/common.proto create mode 100644 sdk/src/exporter/otprotocol/proto/metrics/v1/metrics.proto create mode 100644 sdk/src/exporter/otprotocol/proto/resource/v1/resource.proto create mode 100644 sdk/src/exporter/otprotocol/proto/trace/v1/trace.proto create mode 100644 sdk/src/exporter/otprotocol/proto/trace/v1/trace_config.proto diff --git a/sdk/src/exporter/otprotocol/proto/README b/sdk/src/exporter/otprotocol/proto/README new file mode 100644 index 0000000000..dfd3a68e21 --- /dev/null +++ b/sdk/src/exporter/otprotocol/proto/README @@ -0,0 +1,2 @@ +From: https://github.com/open-telemetry/opentelemetry-proto +Commit: d496c80b353bc4a4f754ae686b59ca3c41de0946 diff --git a/sdk/src/exporter/otprotocol/proto/collector/README.md b/sdk/src/exporter/otprotocol/proto/collector/README.md new file mode 100644 index 0000000000..4a73a31ed8 --- /dev/null +++ b/sdk/src/exporter/otprotocol/proto/collector/README.md @@ -0,0 +1,9 @@ +# OpenTelemetry Collector Proto + +This package describes the OpenTelemetry collector protocol. + +## Packages + +1. `common` package contains the common messages shared between different services. +2. `trace` package contains the Trace Service protos. +3. `metrics` package contains the Metrics Service protos. diff --git a/sdk/src/exporter/otprotocol/proto/collector/metrics/v1/metrics_service.proto b/sdk/src/exporter/otprotocol/proto/collector/metrics/v1/metrics_service.proto new file mode 100644 index 0000000000..5a3cbee4c9 --- /dev/null +++ b/sdk/src/exporter/otprotocol/proto/collector/metrics/v1/metrics_service.proto @@ -0,0 +1,45 @@ +// Copyright 2019, OpenTelemetry Authors +// +// Licensed under the Apache License, Version 2.0 (the "License"); +// you may not use this file except in compliance with the License. +// You may obtain a copy of the License at +// +// http://www.apache.org/licenses/LICENSE-2.0 +// +// Unless required by applicable law or agreed to in writing, software +// distributed under the License is distributed on an "AS IS" BASIS, +// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +// See the License for the specific language governing permissions and +// limitations under the License. + +syntax = "proto3"; + +package opentelemetry.proto.collector.metrics.v1; + +import "opentelemetry/proto/metrics/v1/metrics.proto"; + +option java_multiple_files = true; +option java_package = "io.opentelemetry.proto.collector.metrics.v1"; +option java_outer_classname = "MetricsServiceProto"; +option go_package = "github.com/open-telemetry/opentelemetry-proto/gen/go/collector/metrics/v1"; + +// Service that can be used to push metrics between one Application +// instrumented with OpenTelemetry and a collector, or between a collector and a +// central collector. +service MetricsService { + // For performance reasons, it is recommended to keep this RPC + // alive for the entire life of the application. + rpc Export(ExportMetricsServiceRequest) returns (ExportMetricsServiceResponse) {} +} + +message ExportMetricsServiceRequest { + // An array of ResourceMetrics. + // For data coming from a single resource this array will typically contain one + // element. Intermediary nodes (such as OpenTelemetry Collector) that receive + // data from multiple origins typically batch the data before forwarding further and + // in that case this array will contain multiple elements. + repeated opentelemetry.proto.metrics.v1.ResourceMetrics resource_metrics = 1; +} + +message ExportMetricsServiceResponse { +} diff --git a/sdk/src/exporter/otprotocol/proto/collector/trace/v1/trace_service.proto b/sdk/src/exporter/otprotocol/proto/collector/trace/v1/trace_service.proto new file mode 100644 index 0000000000..16784c666a --- /dev/null +++ b/sdk/src/exporter/otprotocol/proto/collector/trace/v1/trace_service.proto @@ -0,0 +1,48 @@ +// Copyright 2019, OpenTelemetry Authors +// +// Licensed under the Apache License, Version 2.0 (the "License"); +// you may not use this file except in compliance with the License. +// You may obtain a copy of the License at +// +// http://www.apache.org/licenses/LICENSE-2.0 +// +// Unless required by applicable law or agreed to in writing, software +// distributed under the License is distributed on an "AS IS" BASIS, +// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +// See the License for the specific language governing permissions and +// limitations under the License. + +syntax = "proto3"; + +// NOTE: This proto is experimental and is subject to change at this point. +// Please do not use it at the moment. + +package opentelemetry.proto.collector.trace.v1; + +import "opentelemetry/proto/trace/v1/trace.proto"; + +option java_multiple_files = true; +option java_package = "io.opentelemetry.proto.collector.trace.v1"; +option java_outer_classname = "TraceServiceProto"; +option go_package = "github.com/open-telemetry/opentelemetry-proto/gen/go/collector/trace/v1"; + +// Service that can be used to push spans between one Application instrumented with +// OpenTelemetry and an collector, or between an collector and a central collector (in this +// case spans are sent/received to/from multiple Applications). +service TraceService { + // For performance reasons, it is recommended to keep this RPC + // alive for the entire life of the application. + rpc Export(ExportTraceServiceRequest) returns (ExportTraceServiceResponse) {} +} + +message ExportTraceServiceRequest { + // An array of ResourceSpans. + // For data coming from a single resource this array will typically contain one + // element. Intermediary nodes (such as OpenTelemetry Collector) that receive + // data from multiple origins typically batch the data before forwarding further and + // in that case this array will contain multiple elements. + repeated opentelemetry.proto.trace.v1.ResourceSpans resource_spans = 1; +} + +message ExportTraceServiceResponse { +} diff --git a/sdk/src/exporter/otprotocol/proto/collector/trace/v1/trace_service_http.yaml b/sdk/src/exporter/otprotocol/proto/collector/trace/v1/trace_service_http.yaml new file mode 100644 index 0000000000..7754e5ff12 --- /dev/null +++ b/sdk/src/exporter/otprotocol/proto/collector/trace/v1/trace_service_http.yaml @@ -0,0 +1,12 @@ +# This is an API configuration to generate an HTTP/JSON -> gRPC gateway for the +# OpenTelemetry service using github.com/grpc-ecosystem/grpc-gateway. +type: google.api.Service +config_version: 3 +http: + rules: + - selector: opentelemetry.proto.collector.trace.v1.TraceService.Export + post: /v1/trace + body: "*" + - selector: opentelemetry.proto.collector.metrics.v1.MetricsService.Export + post: /v1/trace + body: "*" \ No newline at end of file diff --git a/sdk/src/exporter/otprotocol/proto/common/v1/common.proto b/sdk/src/exporter/otprotocol/proto/common/v1/common.proto new file mode 100644 index 0000000000..b3b1852459 --- /dev/null +++ b/sdk/src/exporter/otprotocol/proto/common/v1/common.proto @@ -0,0 +1,55 @@ +// Copyright 2019, OpenTelemetry Authors +// +// Licensed under the Apache License, Version 2.0 (the "License"); +// you may not use this file except in compliance with the License. +// You may obtain a copy of the License at +// +// http://www.apache.org/licenses/LICENSE-2.0 +// +// Unless required by applicable law or agreed to in writing, software +// distributed under the License is distributed on an "AS IS" BASIS, +// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +// See the License for the specific language governing permissions and +// limitations under the License. + +syntax = "proto3"; + +package opentelemetry.proto.common.v1; + +option java_multiple_files = true; +option java_package = "io.opentelemetry.proto.common.v1"; +option java_outer_classname = "CommonProto"; +option go_package = "github.com/open-telemetry/opentelemetry-proto/gen/go/common/v1"; + +// AttributeKeyValue is a key-value pair that is used to store Span attributes, Link +// attributes, etc. +message AttributeKeyValue { + // ValueType is the enumeration of possible types that value can have. + enum ValueType { + STRING = 0; + INT = 1; + DOUBLE = 2; + BOOL = 3; + }; + + // key part of the key-value pair. + string key = 1; + + // type of the value. + ValueType type = 2; + + // Only one of the following fields is supposed to contain data (determined by `type` field). + // This is deliberately not using Protobuf `oneof` for performance reasons (verified by benchmarks). + + string string_value = 3; + int64 int_value = 4; + double double_value = 5; + bool bool_value = 6; +} + +// StringKeyValue is a pair of key/value strings. This is the simpler (and faster) version +// of AttributeKeyValue that only supports string values. +message StringKeyValue { + string key = 1; + string value = 2; +} diff --git a/sdk/src/exporter/otprotocol/proto/metrics/v1/metrics.proto b/sdk/src/exporter/otprotocol/proto/metrics/v1/metrics.proto new file mode 100644 index 0000000000..a15a7b6c2b --- /dev/null +++ b/sdk/src/exporter/otprotocol/proto/metrics/v1/metrics.proto @@ -0,0 +1,355 @@ +// Copyright 2019, OpenTelemetry Authors +// +// Licensed under the Apache License, Version 2.0 (the "License"); +// you may not use this file except in compliance with the License. +// You may obtain a copy of the License at +// +// http://www.apache.org/licenses/LICENSE-2.0 +// +// Unless required by applicable law or agreed to in writing, software +// distributed under the License is distributed on an "AS IS" BASIS, +// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +// See the License for the specific language governing permissions and +// limitations under the License. + +syntax = "proto3"; + +package opentelemetry.proto.metrics.v1; + +import "opentelemetry/proto/common/v1/common.proto"; +import "opentelemetry/proto/resource/v1/resource.proto"; + +option java_multiple_files = true; +option java_package = "io.opentelemetry.proto.metrics.v1"; +option java_outer_classname = "MetricsProto"; +option go_package = "github.com/open-telemetry/opentelemetry-proto/gen/go/metrics/v1"; + +// A collection of metrics from a Resource. +message ResourceMetrics { + // A list of metrics that originate from a resource. + repeated Metric metrics = 1; + + // The resource for the metrics in this message. + // If this field is not set then no resource info is known. + opentelemetry.proto.resource.v1.Resource resource = 2; +} + +// Defines a Metric which has one or more timeseries. +// +// The data model and relation between entities is shown in the diagram below. +// +// - Metric is composed of a MetricDescriptor and a list of data points. +// - MetricDescriptor contains a list of label keys (shown horizontally). +// - Data is a list of DataPoints (shown vertically). +// - DataPoint contains a list of label values and a value. +// +// Metric +// +----------+ +------------------------+ +// |descriptor|-------->| MetricDescriptor | +// | | |+-----+-----+ +-----+ | +// | | ||label|label|...|label| | +// | data|--+ ||key1 |key2 | |keyN | | +// +----------+ | |+-----+-----+ +-----+ | +// | +------------------------+ +// | +// | +---------------------------+ +// | |DataPoint 1 | +// v |+------+------+ +------+ | +// +-----+ ||label |label |...|label | | +// | 1 |-->||value1|value2|...|valueN| | +// +-----+ |+------+------+ +------+ | +// | . | |+-----+ | +// | . | ||value| | +// | . | |+-----+ | +// | . | +---------------------------+ +// | . | . +// | . | . +// | . | . +// | . | +---------------------------+ +// | . | |DataPoint M | +// +-----+ |+------+------+ +------+ | +// | M |-->||label |label |...|label | | +// +-----+ ||value1|value2|...|valueN| | +// |+------+------+ +------+ | +// |+-----+ | +// ||value| | +// |+-----+ | +// +---------------------------+ +// +//----------------------------------------------------------------------- +// DataPoint is a value of specific type corresponding to a given moment in +// time. Each DataPoint is timestamped. +// +// DataPoint is strongly typed: each DataPoint type has a specific Protobuf message +// depending on the value type of the metric and thus there are currently 4 DataPoint +// messages, which correspond to the types of metric values. +message Metric { + // metric_descriptor describes the Metric. + MetricDescriptor metric_descriptor = 1; + + // Data is a list of one or more DataPoints for a single metric. Only one of the + // following fields is used for the data, depending on the type of the metric defined + // by MetricDescriptor.type field. + repeated Int64DataPoint int64_datapoints = 2; + repeated DoubleDataPoint double_datapoints = 3; + repeated HistogramDataPoint histogram_datapoints = 4; + repeated SummaryDataPoint summary_datapoints = 5; +} + +// Defines a metric type and its schema. +message MetricDescriptor { + // name of the metric, including its DNS name prefix. It must be unique. + string name = 1; + + // description of the metric, which can be used in documentation. + string description = 2; + + // unit in which the metric value is reported. Follows the format + // described by http://unitsofmeasure.org/ucum.html. + string unit = 3; + + // Type of the metric. It describes how the data is reported. + // + // A gauge is an instantaneous measurement of a value. + // + // A counter/cumulative measurement is a value accumulated over a time + // interval. In a time series, cumulative measurements should have the same + // start time, increasing values, until an event resets the cumulative value + // to zero and sets a new start time for the subsequent points. + enum Type { + // Do not use this default value. + UNSPECIFIED = 0; + + // Integer gauge. The value can go both up and down over time. + // Corresponding values are stored in Int64DataPoint. + GAUGE_INT64 = 1; + + // Floating point gauge. The value can go both up and down over time. + // Corresponding values are stored in DoubleDataPoint. + GAUGE_DOUBLE = 2; + + // Histogram gauge measurement. + // Used in scenarios like a snapshot of time that current items in a queue + // have spent there. + // Corresponding values are stored in HistogramDataPoint. The count and sum of the + // histogram can go both up and down over time. Recorded values are always >= 0. + GAUGE_HISTOGRAM = 3; + + // Integer counter measurement. The value cannot decrease; if value is reset then + // start_time_unixnano should also be reset. + // Corresponding values are stored in Int64DataPoint. + COUNTER_INT64 = 4; + + // Floating point counter measurement. The value cannot decrease, if + // resets then the start_time_unixnano should also be reset. + // Recorded values are always >= 0. + // Corresponding values are stored in DoubleDataPoint. + COUNTER_DOUBLE = 5; + + // Histogram cumulative measurement. + // Corresponding values are stored in HistogramDataPoint. The count and sum of the + // histogram cannot decrease; if values are reset then start_time_unixnano + // should also be reset to the new start timestamp. + CUMULATIVE_HISTOGRAM = 6; + + // Summary value. Some frameworks implemented Histograms as a summary of observations + // (usually things like request durations and response sizes). While it + // also provides a total count of observations and a sum of all observed + // values, it calculates configurable percentiles over a sliding time + // window. + // Corresponding values are stored in SummaryDataPoint. + SUMMARY = 7; + } + Type type = 4; + + // The set of labels associated with the metric descriptor. Labels in this list apply to + // all data points. + repeated opentelemetry.proto.common.v1.StringKeyValue labels = 5; +} + +// Int64DataPoint is a single data point in a timeseries that describes the time-varying +// values of a int64 metric. +message Int64DataPoint { + // The set of labels that uniquely identify this timeseries. + repeated opentelemetry.proto.common.v1.StringKeyValue labels = 1; + + // start_time_unixnano is the time when the cumulative value was reset to zero. + // This is used for Counter type only. For Gauge the value is not specified and + // defaults to 0. + // + // The cumulative value is over the time interval (start_time_unixnano, timestamp_unixnano]. + // Value is UNIX Epoch time in nanoseconds since 00:00:00 UTC on 1 January 1970. + // + // Value of 0 indicates that the timestamp is unspecified. In that case the timestamp + // may be decided by the backend. + fixed64 start_time_unixnano = 2; + + // timestamp_unixnano is the moment when this value was recorded. + // Value is UNIX Epoch time in nanoseconds since 00:00:00 UTC on 1 January 1970. + fixed64 timestamp_unixnano = 3; + + // value itself. + int64 value = 4; +} + +// DoubleDataPoint is a single data point in a timeseries that describes the time-varying +// value of a double metric. +message DoubleDataPoint { + // The set of labels that uniquely identify this timeseries. + repeated opentelemetry.proto.common.v1.StringKeyValue labels = 1; + + // start_time_unixnano is the time when the cumulative value was reset to zero. + // This is used for Counter type only. For Gauge the value is not specified and + // defaults to 0. + // + // The cumulative value is over the time interval (start_time_unixnano, timestamp_unixnano]. + // Value is UNIX Epoch time in nanoseconds since 00:00:00 UTC on 1 January 1970. + // + // Value of 0 indicates that the timestamp is unspecified. In that case the timestamp + // may be decided by the backend. + fixed64 start_time_unixnano = 2; + + // timestamp_unixnano is the moment when this value was recorded. + // Value is UNIX Epoch time in nanoseconds since 00:00:00 UTC on 1 January 1970. + fixed64 timestamp_unixnano = 3; + + // value itself. + double value = 4; +} + +// HistogramDataPoint is a single data point in a timeseries that describes the time-varying +// values of a Histogram. A Histogram contains summary statistics for a population of values, +// it may optionally contain the distribution of those values across a set of buckets. +message HistogramDataPoint { + // The set of labels that uniquely identify this timeseries. + repeated opentelemetry.proto.common.v1.StringKeyValue labels = 1; + + // start_time_unixnano is the time when the cumulative value was reset to zero. + // + // The cumulative value is over the time interval (start_time_unixnano, timestamp_unixnano]. + // Value is UNIX Epoch time in nanoseconds since 00:00:00 UTC on 1 January 1970. + // + // Value of 0 indicates that the timestamp is unspecified. In that case the timestamp + // may be decided by the backend. + // Note: this field is always unspecified and ignored if MetricDescriptor.type==GAUGE_HISTOGRAM. + fixed64 start_time_unixnano = 2; + + // timestamp_unixnano is the moment when this value was recorded. + // Value is UNIX Epoch time in nanoseconds since 00:00:00 UTC on 1 January 1970. + fixed64 timestamp_unixnano = 3; + + // count is the number of values in the population. Must be non-negative. This value + // must be equal to the sum of the "count" fields in buckets if a histogram is provided. + uint64 count = 4; + + // sum of the values in the population. If count is zero then this field + // must be zero. This value must be equal to the sum of the "sum" fields in buckets if + // a histogram is provided. + double sum = 5; + + // Bucket contains values for a bucket. + message Bucket { + // The number of values in each bucket of the histogram, as described by + // bucket_options. + uint64 count = 1; + + // Exemplars are example points that may be used to annotate aggregated + // Histogram values. They are metadata that gives information about a + // particular value added to a Histogram bucket. + message Exemplar { + // Value of the exemplar point. It determines which bucket the exemplar belongs to. + // If bucket_options define bounds for this bucket then this value must be within + // the defined bounds. + double value = 1; + + // timestamp_unixnano is the moment when this exemplar was recorded. + // Value is UNIX Epoch time in nanoseconds since 00:00:00 UTC on 1 January 1970. + fixed64 timestamp_unixnano = 2; + + // exemplar_attachments are contextual information about the example value. + // Keys in this list must be unique. + repeated opentelemetry.proto.common.v1.StringKeyValue attachments = 3; + } + + // exemplar is an optional representative value of the bucket. + Exemplar exemplar = 2; + } + + // buckets is an optional field contains the values of histogram for each bucket. + // + // The sum of the values in the buckets "count" field must equal the value in the count field. + // + // The number of elements in buckets array must be by one greater than the + // number of elements in bucket_bounds array. + // + // Note: if HistogramDataPoint.bucket_options defines bucket bounds then this field + // must also be present and number of elements in this field must be equal to the + // number of buckets defined by bucket_options. + repeated Bucket buckets = 6; + + // A histogram may optionally contain the distribution of the values in the population. + // In that case one of the option fields below and "buckets" field both must be defined. + // Otherwise all option fields and "buckets" field must be omitted in which case the + // distribution of values in the histogram is unknown and only the total count and sum are known. + + // explicit_bounds is the only supported bucket option currently. + // TODO: Add more bucket options. + + // explicit_bounds specifies buckets with explicitly defined bounds for values. + // The bucket boundaries are described by "bounds" field. + // + // This defines size(bounds) + 1 (= N) buckets. The boundaries for bucket + // at index i are: + // + // [0, bounds[i]) for i == 0 + // [bounds[i-1], bounds[i]) for 0 < i < N-1 + // [bounds[i], +infinity) for i == N-1 + // The values in bounds array must be strictly increasing and > 0. + // + // Note: only [a, b) intervals are currently supported for each bucket. If we decides + // to also support (a, b] intervals we should add support for these by defining a boolean + // value which decides what type of intervals to use. + repeated double explicit_bounds = 7; +} + +// SummaryDataPoint is a single data point in a timeseries that describes the time-varying +// values of a Summary metric. +message SummaryDataPoint { + // The set of labels that uniquely identify this timeseries. + repeated opentelemetry.proto.common.v1.StringKeyValue labels = 1; + + // start_time_unixnano is the time when the cumulative value was reset to zero. + // + // The cumulative value is over the time interval (start_time_unixnano, timestamp_unixnano]. + // Value is UNIX Epoch time in nanoseconds since 00:00:00 UTC on 1 January 1970. + // + // Value of 0 indicates that the timestamp is unspecified. In that case the timestamp + // may be decided by the backend. + fixed64 start_time_unixnano = 2; + + // timestamp_unixnano is the moment when this value was recorded. + // Value is UNIX Epoch time in nanoseconds since 00:00:00 UTC on 1 January 1970. + fixed64 timestamp_unixnano = 3; + + // The total number of recorded values since start_time. Optional since + // some systems don't expose this. + uint64 count = 4; + + // The total sum of recorded values since start_time. Optional since some + // systems don't expose this. If count is zero then this field must be zero. + double sum = 5; + + // Represents the value at a given percentile of a distribution. + message ValueAtPercentile { + // The percentile of a distribution. Must be in the interval + // [0.0, 100.0]. + double percentile = 1; + + // The value at the given percentile of a distribution. + double value = 2; + } + + // A list of values at different percentiles of the distribution calculated + // from the current snapshot. The percentiles must be strictly increasing. + repeated ValueAtPercentile percentile_values = 6; +} diff --git a/sdk/src/exporter/otprotocol/proto/resource/v1/resource.proto b/sdk/src/exporter/otprotocol/proto/resource/v1/resource.proto new file mode 100644 index 0000000000..a9e1711af4 --- /dev/null +++ b/sdk/src/exporter/otprotocol/proto/resource/v1/resource.proto @@ -0,0 +1,34 @@ +// Copyright 2019, OpenTelemetry Authors +// +// Licensed under the Apache License, Version 2.0 (the "License"); +// you may not use this file except in compliance with the License. +// You may obtain a copy of the License at +// +// http://www.apache.org/licenses/LICENSE-2.0 +// +// Unless required by applicable law or agreed to in writing, software +// distributed under the License is distributed on an "AS IS" BASIS, +// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +// See the License for the specific language governing permissions and +// limitations under the License. + +syntax = "proto3"; + +package opentelemetry.proto.resource.v1; + +import "opentelemetry/proto/common/v1/common.proto"; + +option java_multiple_files = true; +option java_package = "io.opentelemetry.proto.resource.v1"; +option java_outer_classname = "ResourceProto"; +option go_package = "github.com/open-telemetry/opentelemetry-proto/gen/go/resource/v1"; + +// Resource information. +message Resource { + // Set of labels that describe the resource. + repeated opentelemetry.proto.common.v1.AttributeKeyValue attributes = 1; + + // dropped_attributes_count is the number of dropped attributes. If the value is 0, then + // no attributes were dropped. + uint32 dropped_attributes_count = 2; +} diff --git a/sdk/src/exporter/otprotocol/proto/trace/v1/trace.proto b/sdk/src/exporter/otprotocol/proto/trace/v1/trace.proto new file mode 100644 index 0000000000..7f0e4a75c0 --- /dev/null +++ b/sdk/src/exporter/otprotocol/proto/trace/v1/trace.proto @@ -0,0 +1,251 @@ +// Copyright 2019, OpenTelemetry Authors +// +// Licensed under the Apache License, Version 2.0 (the "License"); +// you may not use this file except in compliance with the License. +// You may obtain a copy of the License at +// +// http://www.apache.org/licenses/LICENSE-2.0 +// +// Unless required by applicable law or agreed to in writing, software +// distributed under the License is distributed on an "AS IS" BASIS, +// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +// See the License for the specific language governing permissions and +// limitations under the License. + +syntax = "proto3"; + +package opentelemetry.proto.trace.v1; + +import "opentelemetry/proto/common/v1/common.proto"; +import "opentelemetry/proto/resource/v1/resource.proto"; + +option java_multiple_files = true; +option java_package = "io.opentelemetry.proto.trace.v1"; +option java_outer_classname = "TraceProto"; +option go_package = "github.com/open-telemetry/opentelemetry-proto/gen/go/trace/v1"; + +// A collection of spans from a Resource. +message ResourceSpans { + // The resource for the spans in this message. + // If this field is not set then no resource info is known. + opentelemetry.proto.resource.v1.Resource resource = 1; + + // A list of Spans that originate from a resource. + repeated Span spans = 2; +} + +// Span represents a single operation within a trace. Spans can be +// nested to form a trace tree. Spans may also be linked to other spans +// from the same or different trace and form graphs. Often, a trace +// contains a root span that describes the end-to-end latency, and one +// or more subspans for its sub-operations. A trace can also contain +// multiple root spans, or none at all. Spans do not need to be +// contiguous - there may be gaps or overlaps between spans in a trace. +// +// The next available field id is 17. +message Span { + // A unique identifier for a trace. All spans from the same trace share + // the same `trace_id`. The ID is a 16-byte array. An ID with all zeroes + // is considered invalid. + // + // This field is semantically required. Receiver should generate new + // random trace_id if empty or invalid trace_id was received. + // + // This field is required. + bytes trace_id = 1; + + // A unique identifier for a span within a trace, assigned when the span + // is created. The ID is an 8-byte array. An ID with all zeroes is considered + // invalid. + // + // This field is semantically required. Receiver should generate new + // random span_id if empty or invalid span_id was received. + // + // This field is required. + bytes span_id = 2; + + // trace_state conveys information about request position in multiple distributed tracing graphs. + // It is a trace_state in w3c-trace-context format: https://www.w3.org/TR/trace-context/#tracestate-header + // See also https://github.com/w3c/distributed-tracing for more details about this field. + string trace_state = 3; + + // The `span_id` of this span's parent span. If this is a root span, then this + // field must be empty. The ID is an 8-byte array. + bytes parent_span_id = 4; + + // A description of the span's operation. + // + // For example, the name can be a qualified method name or a file name + // and a line number where the operation is called. A best practice is to use + // the same display name at the same call point in an application. + // This makes it easier to correlate spans in different traces. + // + // This field is semantically required to be set to non-empty string. + // When null or empty string received - receiver may use string "name" + // as a replacement. There might be smarted algorithms implemented by + // receiver to fix the empty span name. + // + // This field is required. + string name = 5; + + // SpanKind is the type of span. Can be used to specify additional relationships between spans + // in addition to a parent/child relationship. + enum SpanKind { + // Unspecified. Do NOT use as default. + // Implementations MAY assume SpanKind to be INTERNAL when receiving UNSPECIFIED. + SPAN_KIND_UNSPECIFIED = 0; + + // Indicates that the span represents an internal operation within an application, + // as opposed to an operations happening at the boundaries. Default value. + INTERNAL = 1; + + // Indicates that the span covers server-side handling of an RPC or other + // remote network request. + SERVER = 2; + + // Indicates that the span describes a request to some remote service. + CLIENT = 3; + + // Indicates that the span describes a producer sending a message to a broker. + // Unlike CLIENT and SERVER, there is often no direct critical path latency relationship + // between producer and consumer spans. A PRODUCER span ends when the message was accepted + // by the broker while the logical processing of the message might span a much longer time. + PRODUCER = 4; + + // Indicates that the span describes consumer receiving a message from a broker. + // Like the PRODUCER kind, there is often no direct critical path latency relationship + // between producer and consumer spans. + CONSUMER = 5; + } + + // Distinguishes between spans generated in a particular context. For example, + // two spans with the same name may be distinguished using `CLIENT` (caller) + // and `SERVER` (callee) to identify queueing latency associated with the span. + SpanKind kind = 6; + + // start_time_unixnano is the start time of the span. On the client side, this is the time + // kept by the local machine where the span execution starts. On the server side, this + // is the time when the server's application handler starts running. + // Value is UNIX Epoch time in nanoseconds since 00:00:00 UTC on 1 January 1970. + // + // This field is semantically required and it is expected that end_time >= start_time. + fixed64 start_time_unixnano = 7; + + // end_time_unixnano is the end time of the span. On the client side, this is the time + // kept by the local machine where the span execution ends. On the server side, this + // is the time when the server application handler stops running. + // Value is UNIX Epoch time in nanoseconds since 00:00:00 UTC on 1 January 1970. + // + // This field is semantically required and it is expected that end_time >= start_time. + fixed64 end_time_unixnano = 8; + + // attributes is a collection of key/value pairs. The value can be a string, + // an integer, a double or the Boolean values `true` or `false`. Note, global attributes + // like server name can be set using the resource API. Examples of attributes: + // + // "/http/user_agent": "Mozilla/5.0 (Macintosh; Intel Mac OS X 10_14_2) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/71.0.3578.98 Safari/537.36" + // "/http/server_latency": 300 + // "abc.com/myattribute": true + // "abc.com/score": 10.239 + repeated opentelemetry.proto.common.v1.AttributeKeyValue attributes = 9; + + // dropped_attributes_count is the number of attributes that were discarded. Attributes + // can be discarded because their keys are too long or because there are too many + // attributes. If this value is 0, then no attributes were dropped. + uint32 dropped_attributes_count = 10; + + // Event is a time-stamped annotation of the span, consisting of user-supplied + // text description and key-value pairs. + message Event { + // time_unixnano is the time the event occurred. + fixed64 time_unixnano = 1; + + // name of the event. + // This field is semantically required to be set to non-empty string. + string name = 2; + + // attributes is a collection of attribute key/value pairs on the event. + repeated opentelemetry.proto.common.v1.AttributeKeyValue attributes = 3; + + // dropped_attributes_count is the number of dropped attributes. If the value is 0, + // then no attributes were dropped. + uint32 dropped_attributes_count = 4; + } + + // events is a collection of Event items. + repeated Event events = 11; + + // dropped_events_count is the number of dropped events. If the value is 0, then no + // events were dropped. + uint32 dropped_events_count = 12; + + // A pointer from the current span to another span in the same trace or in a + // different trace. For example, this can be used in batching operations, + // where a single batch handler processes multiple requests from different + // traces or when the handler receives a request from a different project. + message Link { + // A unique identifier of a trace that this linked span is part of. The ID is a + // 16-byte array. + bytes trace_id = 1; + + // A unique identifier for the linked span. The ID is an 8-byte array. + bytes span_id = 2; + + // The trace_state associated with the link. + string trace_state = 3; + + // attributes is a collection of attribute key/value pairs on the link. + repeated opentelemetry.proto.common.v1.AttributeKeyValue attributes = 4; + + // dropped_attributes_count is the number of dropped attributes. If the value is 0, + // then no attributes were dropped. + uint32 dropped_attributes_count = 5; + } + + // links is a collection of Links, which are references from this span to a span + // in the same or different trace. + repeated Link links = 13; + + // dropped_links_count is the number of dropped links after the maximum size was + // enforced. If this value is 0, then no links were dropped. + uint32 dropped_links_count = 14; + + // An optional final status for this span. Semantically when Status + // wasn't set it is means span ended without errors and assume + // Status.Ok (code = 0). + Status status = 15; +} + +// The Status type defines a logical error model that is suitable for different +// programming environments, including REST APIs and RPC APIs. +message Status { + + // StatusCode mirrors the codes defined at + // https://github.com/open-telemetry/opentelemetry-specification/blob/master/specification/api-tracing.md#statuscanonicalcode + enum StatusCode { + Ok = 0; + Cancelled = 1; + UnknownError = 2; + InvalidArgument = 3; + DeadlineExceeded = 4; + NotFound = 5; + AlreadyExists = 6; + PermissionDenied = 7; + ResourceExhausted = 8; + FailedPrecondition = 9; + Aborted = 10; + OutOfRange = 11; + Unimplemented = 12; + InternalError = 13; + Unavailable = 14; + DataLoss = 15; + Unauthenticated = 16; + }; + + // The status code. This is optional field. It is safe to assume 0 (OK) + // when not set. + StatusCode code = 1; + + // A developer-facing human readable error message. + string message = 2; +} diff --git a/sdk/src/exporter/otprotocol/proto/trace/v1/trace_config.proto b/sdk/src/exporter/otprotocol/proto/trace/v1/trace_config.proto new file mode 100644 index 0000000000..7269da1ee8 --- /dev/null +++ b/sdk/src/exporter/otprotocol/proto/trace/v1/trace_config.proto @@ -0,0 +1,78 @@ +// Copyright 2019, OpenTelemetry Authors +// +// Licensed under the Apache License, Version 2.0 (the "License"); +// you may not use this file except in compliance with the License. +// You may obtain a copy of the License at +// +// http://www.apache.org/licenses/LICENSE-2.0 +// +// Unless required by applicable law or agreed to in writing, software +// distributed under the License is distributed on an "AS IS" BASIS, +// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +// See the License for the specific language governing permissions and +// limitations under the License. + +syntax = "proto3"; + +package opentelemetry.proto.trace.v1; + +option java_multiple_files = true; +option java_package = "io.opentelemetry.proto.trace.v1"; +option java_outer_classname = "TraceConfigProto"; +option go_package = "github.com/open-telemetry/opentelemetry-proto/gen/go/collector/trace/v1"; + +// Global configuration of the trace service. All fields must be specified, or +// the default (zero) values will be used for each type. +message TraceConfig { + + // The global default sampler used to make decisions on span sampling. + oneof sampler { + ConstantSampler constant_sampler = 1; + + ProbabilitySampler probability_sampler = 2; + + RateLimitingSampler rate_limiting_sampler = 3; + } + + // The global default max number of attributes per span. + int64 max_number_of_attributes = 4; + + // The global default max number of annotation events per span. + int64 max_number_of_timed_events= 5; + + // The global default max number of attributes per timed event. + int64 max_number_of_attributes_per_timed_event = 6; + + // The global default max number of link entries per span. + int64 max_number_of_links = 7; + + // The global default max number of attributes per span. + int64 max_number_of_attributes_per_link = 8; +} + +// Sampler that always makes a constant decision on span sampling. +message ConstantSampler { + // How spans should be sampled: + // - Always off + // - Always on + // - Always follow the parent Span's decision (off if no parent). + enum ConstantDecision { + ALWAYS_OFF = 0; + ALWAYS_ON = 1; + ALWAYS_PARENT = 2; + } + ConstantDecision decision = 1; +} + +// Sampler that tries to uniformly sample traces with a given probability. +// The probability of sampling a trace is equal to that of the specified probability. +message ProbabilitySampler { + // The desired probability of sampling. Must be within [0.0, 1.0]. + double samplingProbability = 1; +} + +// Sampler that tries to sample with a rate per time window. +message RateLimitingSampler { + // Rate per second. + int64 qps = 1; +} From c8fc55723a3053648f672fe3655e4d63a9dbb8f2 Mon Sep 17 00:00:00 2001 From: Ryan Burn Date: Tue, 10 Mar 2020 21:11:20 -0700 Subject: [PATCH 19/44] Integrate protobuf files into build --- sdk/src/CMakeLists.txt | 1 + sdk/src/exporter/CMakeLists.txt | 3 ++ sdk/src/exporter/otprotocol/CMakeLists.txt | 1 + .../exporter/otprotocol/proto/Protobuf.cmake | 46 +++++++++++++++++++ .../proto}/collector/README.md | 0 .../metrics/v1/metrics_service.proto | 0 .../collector/trace/v1/trace_service.proto | 0 .../trace/v1/trace_service_http.yaml | 0 .../proto}/common/v1/common.proto | 0 .../proto}/metrics/v1/metrics.proto | 0 .../proto}/resource/v1/resource.proto | 0 .../proto}/trace/v1/trace.proto | 0 .../proto}/trace/v1/trace_config.proto | 0 13 files changed, 51 insertions(+) create mode 100644 sdk/src/exporter/CMakeLists.txt create mode 100644 sdk/src/exporter/otprotocol/CMakeLists.txt create mode 100644 sdk/src/exporter/otprotocol/proto/Protobuf.cmake rename sdk/src/exporter/otprotocol/proto/{ => opentelemetry/proto}/collector/README.md (100%) rename sdk/src/exporter/otprotocol/proto/{ => opentelemetry/proto}/collector/metrics/v1/metrics_service.proto (100%) rename sdk/src/exporter/otprotocol/proto/{ => opentelemetry/proto}/collector/trace/v1/trace_service.proto (100%) rename sdk/src/exporter/otprotocol/proto/{ => opentelemetry/proto}/collector/trace/v1/trace_service_http.yaml (100%) rename sdk/src/exporter/otprotocol/proto/{ => opentelemetry/proto}/common/v1/common.proto (100%) rename sdk/src/exporter/otprotocol/proto/{ => opentelemetry/proto}/metrics/v1/metrics.proto (100%) rename sdk/src/exporter/otprotocol/proto/{ => opentelemetry/proto}/resource/v1/resource.proto (100%) rename sdk/src/exporter/otprotocol/proto/{ => opentelemetry/proto}/trace/v1/trace.proto (100%) rename sdk/src/exporter/otprotocol/proto/{ => opentelemetry/proto}/trace/v1/trace_config.proto (100%) diff --git a/sdk/src/CMakeLists.txt b/sdk/src/CMakeLists.txt index 2cea47fa7b..84e987128b 100644 --- a/sdk/src/CMakeLists.txt +++ b/sdk/src/CMakeLists.txt @@ -1 +1,2 @@ add_subdirectory(trace) +add_subdirectory(exporter) diff --git a/sdk/src/exporter/CMakeLists.txt b/sdk/src/exporter/CMakeLists.txt new file mode 100644 index 0000000000..a646cdfc3a --- /dev/null +++ b/sdk/src/exporter/CMakeLists.txt @@ -0,0 +1,3 @@ +if (WITH_OTPROTOCOL) + add_subdirectory(otprotocol) +endif() diff --git a/sdk/src/exporter/otprotocol/CMakeLists.txt b/sdk/src/exporter/otprotocol/CMakeLists.txt new file mode 100644 index 0000000000..907075f796 --- /dev/null +++ b/sdk/src/exporter/otprotocol/CMakeLists.txt @@ -0,0 +1 @@ +include(proto/Protobuf.cmake) diff --git a/sdk/src/exporter/otprotocol/proto/Protobuf.cmake b/sdk/src/exporter/otprotocol/proto/Protobuf.cmake new file mode 100644 index 0000000000..fed4f1e78f --- /dev/null +++ b/sdk/src/exporter/otprotocol/proto/Protobuf.cmake @@ -0,0 +1,46 @@ +set(PROTO_PATH "${CMAKE_SOURCE_DIR}/sdk/src/exporter/otprotocol/proto") + +set(COMMON_PROTO "${PROTO_PATH}/opentelemetry/proto/common/v1/common.proto") +set(RESOURCE_PROTO "${PROTO_PATH}/opentelemetry/proto/resource/v1/resource.proto") +set(TRACE_PROTO "${PROTO_PATH}/opentelemetry/proto/trace/v1/trace.proto") + +set(GENERATED_PROTOBUF_PATH "${CMAKE_BINARY_DIR}/generated/src/sdk/exporter/otprotocol") + +file(MAKE_DIRECTORY "${GENERATED_PROTOBUF_PATH}") + +set(COMMON_PB_CPP_FILE "${GENERATED_PROTOBUF_PATH}/opentelemetry/proto/common/v1/common.pb.cc") +set(COMMON_PB_H_FILE "${GENERATED_PROTOBUF_PATH}/opentelemetry/proto/common/v1/common.pb.h") +set(RESOURCE_PB_CPP_FILE "${GENERATED_PROTOBUF_PATH}/opentelemetry/proto/resource/v1/resource.pb.cc") +set(RESOURCE_PB_H_FILE "${GENERATED_PROTOBUF_PATH}/opentelemetry/proto/resource/v1/resource.pb.h") +set(TRACE_PB_CPP_FILE "${GENERATED_PROTOBUF_PATH}/opentelemetry/proto/trace/v1/trace.pb.cc") +set(TRACE_PB_H_FILE "${GENERATED_PROTOBUF_PATH}/opentelemetry/proto/trace/v1/trace.pb.h") + +foreach(IMPORT_DIR ${PROTOBUF_IMPORT_DIRS}) + list(APPEND PROTOBUF_INCLUDE_FLAGS "-I${IMPORT_DIR}") +endforeach() + +add_custom_command( + OUTPUT + ${COMMON_PB_H_FILE} + ${COMMON_PB_CPP_FILE} + ${RESOURCE_PB_H_FILE} + ${RESOURCE_PB_CPP_FILE} + ${TRACE_PB_H_FILE} + ${TRACE_PB_CPP_FILE} + COMMAND ${PROTOBUF_PROTOC_EXECUTABLE} + ARGS + "--proto_path=${PROTO_PATH}" + ${PROTOBUF_INCLUDE_FLAGS} + "--cpp_out=${GENERATED_PROTOBUF_PATH}" + ${COMMON_PROTO} + ${RESOURCE_PROTO} + ${TRACE_PROTO} +) + +include_directories(SYSTEM "${CMAKE_BINARY_DIR}/generated") +include_directories(SYSTEM "${CMAKE_BINARY_DIR}/generated/src/sdk/exporter/otprotocol") + +add_library(opentelemetry_exporter_otprotocol_proto OBJECT + ${COMMON_PB_CPP_FILE} + ${RESOURCE_PB_CPP_FILE} + ${TRACE_PB_CPP_FILE}) diff --git a/sdk/src/exporter/otprotocol/proto/collector/README.md b/sdk/src/exporter/otprotocol/proto/opentelemetry/proto/collector/README.md similarity index 100% rename from sdk/src/exporter/otprotocol/proto/collector/README.md rename to sdk/src/exporter/otprotocol/proto/opentelemetry/proto/collector/README.md diff --git a/sdk/src/exporter/otprotocol/proto/collector/metrics/v1/metrics_service.proto b/sdk/src/exporter/otprotocol/proto/opentelemetry/proto/collector/metrics/v1/metrics_service.proto similarity index 100% rename from sdk/src/exporter/otprotocol/proto/collector/metrics/v1/metrics_service.proto rename to sdk/src/exporter/otprotocol/proto/opentelemetry/proto/collector/metrics/v1/metrics_service.proto diff --git a/sdk/src/exporter/otprotocol/proto/collector/trace/v1/trace_service.proto b/sdk/src/exporter/otprotocol/proto/opentelemetry/proto/collector/trace/v1/trace_service.proto similarity index 100% rename from sdk/src/exporter/otprotocol/proto/collector/trace/v1/trace_service.proto rename to sdk/src/exporter/otprotocol/proto/opentelemetry/proto/collector/trace/v1/trace_service.proto diff --git a/sdk/src/exporter/otprotocol/proto/collector/trace/v1/trace_service_http.yaml b/sdk/src/exporter/otprotocol/proto/opentelemetry/proto/collector/trace/v1/trace_service_http.yaml similarity index 100% rename from sdk/src/exporter/otprotocol/proto/collector/trace/v1/trace_service_http.yaml rename to sdk/src/exporter/otprotocol/proto/opentelemetry/proto/collector/trace/v1/trace_service_http.yaml diff --git a/sdk/src/exporter/otprotocol/proto/common/v1/common.proto b/sdk/src/exporter/otprotocol/proto/opentelemetry/proto/common/v1/common.proto similarity index 100% rename from sdk/src/exporter/otprotocol/proto/common/v1/common.proto rename to sdk/src/exporter/otprotocol/proto/opentelemetry/proto/common/v1/common.proto diff --git a/sdk/src/exporter/otprotocol/proto/metrics/v1/metrics.proto b/sdk/src/exporter/otprotocol/proto/opentelemetry/proto/metrics/v1/metrics.proto similarity index 100% rename from sdk/src/exporter/otprotocol/proto/metrics/v1/metrics.proto rename to sdk/src/exporter/otprotocol/proto/opentelemetry/proto/metrics/v1/metrics.proto diff --git a/sdk/src/exporter/otprotocol/proto/resource/v1/resource.proto b/sdk/src/exporter/otprotocol/proto/opentelemetry/proto/resource/v1/resource.proto similarity index 100% rename from sdk/src/exporter/otprotocol/proto/resource/v1/resource.proto rename to sdk/src/exporter/otprotocol/proto/opentelemetry/proto/resource/v1/resource.proto diff --git a/sdk/src/exporter/otprotocol/proto/trace/v1/trace.proto b/sdk/src/exporter/otprotocol/proto/opentelemetry/proto/trace/v1/trace.proto similarity index 100% rename from sdk/src/exporter/otprotocol/proto/trace/v1/trace.proto rename to sdk/src/exporter/otprotocol/proto/opentelemetry/proto/trace/v1/trace.proto diff --git a/sdk/src/exporter/otprotocol/proto/trace/v1/trace_config.proto b/sdk/src/exporter/otprotocol/proto/opentelemetry/proto/trace/v1/trace_config.proto similarity index 100% rename from sdk/src/exporter/otprotocol/proto/trace/v1/trace_config.proto rename to sdk/src/exporter/otprotocol/proto/opentelemetry/proto/trace/v1/trace_config.proto From b98eb9d5db5648bdb35e9e4113a3e4e815b2e3af Mon Sep 17 00:00:00 2001 From: Ryan Burn Date: Tue, 10 Mar 2020 22:11:11 -0700 Subject: [PATCH 20/44] Add otprotocol Recordable --- sdk/src/exporter/otprotocol/CMakeLists.txt | 4 ++++ sdk/src/exporter/otprotocol/proto/Protobuf.cmake | 3 +++ sdk/src/exporter/otprotocol/recordable.cc | 8 ++++++++ sdk/src/exporter/otprotocol/recordable.h | 13 +++++++++++++ 4 files changed, 28 insertions(+) create mode 100644 sdk/src/exporter/otprotocol/recordable.cc create mode 100644 sdk/src/exporter/otprotocol/recordable.h diff --git a/sdk/src/exporter/otprotocol/CMakeLists.txt b/sdk/src/exporter/otprotocol/CMakeLists.txt index 907075f796..70d7e83297 100644 --- a/sdk/src/exporter/otprotocol/CMakeLists.txt +++ b/sdk/src/exporter/otprotocol/CMakeLists.txt @@ -1 +1,5 @@ include(proto/Protobuf.cmake) + +add_library(opentelemetry_exporter_otprotocol recordable.cc) +target_link_libraries(opentelemetry_exporter_otprotocol + $) diff --git a/sdk/src/exporter/otprotocol/proto/Protobuf.cmake b/sdk/src/exporter/otprotocol/proto/Protobuf.cmake index fed4f1e78f..b119707ab8 100644 --- a/sdk/src/exporter/otprotocol/proto/Protobuf.cmake +++ b/sdk/src/exporter/otprotocol/proto/Protobuf.cmake @@ -44,3 +44,6 @@ add_library(opentelemetry_exporter_otprotocol_proto OBJECT ${COMMON_PB_CPP_FILE} ${RESOURCE_PB_CPP_FILE} ${TRACE_PB_CPP_FILE}) +if (BUILD_SHARED_LIBS) + set_property(TARGET opentelemetry_exporter_otprotocol_proto PROPERTY POSITION_INDEPENDENT_CODE ON) +endif() diff --git a/sdk/src/exporter/otprotocol/recordable.cc b/sdk/src/exporter/otprotocol/recordable.cc new file mode 100644 index 0000000000..eaa5891b1e --- /dev/null +++ b/sdk/src/exporter/otprotocol/recordable.cc @@ -0,0 +1,8 @@ +#include "src/exporter/otprotocol/recordable.h" + +OPENTELEMETRY_BEGIN_NAMESPACE +namespace exporter { +namespace otprotocol { +} // namespace otprotocol +} // namespace exporter +OPENTELEMETRY_END_NAMESPACE diff --git a/sdk/src/exporter/otprotocol/recordable.h b/sdk/src/exporter/otprotocol/recordable.h new file mode 100644 index 0000000000..36423b6e4c --- /dev/null +++ b/sdk/src/exporter/otprotocol/recordable.h @@ -0,0 +1,13 @@ +#pragma once + +#include "src/trace/recordable.h" + +#include "opentelemetry/version.h" +#include "opentelemetry/proto/trace/v1/trace.pb.h" + +OPENTELEMETRY_BEGIN_NAMESPACE +namespace exporter { +namespace otprotocol { +} // namespace otprotocol +} // namespace exporter +OPENTELEMETRY_END_NAMESPACE From d2e219818ed38239d6723fd0ab8087003f84fd39 Mon Sep 17 00:00:00 2001 From: Ryan Burn Date: Wed, 11 Mar 2020 18:14:46 -0700 Subject: [PATCH 21/44] Set up protobuf with bazel --- WORKSPACE | 23 +++++++ bazel/opentelemetry_proto.BUILD | 60 +++++++++++++++++++ sdk/CMakeLists.txt | 4 ++ .../opentelemetry}/Protobuf.cmake | 11 ++-- .../proto => proto/opentelemetry}/README | 0 .../opentelemetry/proto/collector/README.md | 0 .../metrics/v1/metrics_service.proto | 0 .../collector/trace/v1/trace_service.proto | 0 .../trace/v1/trace_service_http.yaml | 0 .../proto/common/v1/common.proto | 0 .../proto/metrics/v1/metrics.proto | 0 .../proto/resource/v1/resource.proto | 0 .../opentelemetry/proto/trace/v1/trace.proto | 0 .../proto/trace/v1/trace_config.proto | 0 sdk/src/exporter/otprotocol/BUILD | 30 ++++++++++ sdk/src/exporter/otprotocol/CMakeLists.txt | 4 +- 16 files changed, 123 insertions(+), 9 deletions(-) create mode 100644 bazel/opentelemetry_proto.BUILD rename sdk/{src/exporter/otprotocol/proto => proto/opentelemetry}/Protobuf.cmake (76%) rename sdk/{src/exporter/otprotocol/proto => proto/opentelemetry}/README (100%) rename sdk/{src/exporter/otprotocol => }/proto/opentelemetry/proto/collector/README.md (100%) rename sdk/{src/exporter/otprotocol => }/proto/opentelemetry/proto/collector/metrics/v1/metrics_service.proto (100%) rename sdk/{src/exporter/otprotocol => }/proto/opentelemetry/proto/collector/trace/v1/trace_service.proto (100%) rename sdk/{src/exporter/otprotocol => }/proto/opentelemetry/proto/collector/trace/v1/trace_service_http.yaml (100%) rename sdk/{src/exporter/otprotocol => }/proto/opentelemetry/proto/common/v1/common.proto (100%) rename sdk/{src/exporter/otprotocol => }/proto/opentelemetry/proto/metrics/v1/metrics.proto (100%) rename sdk/{src/exporter/otprotocol => }/proto/opentelemetry/proto/resource/v1/resource.proto (100%) rename sdk/{src/exporter/otprotocol => }/proto/opentelemetry/proto/trace/v1/trace.proto (100%) rename sdk/{src/exporter/otprotocol => }/proto/opentelemetry/proto/trace/v1/trace_config.proto (100%) create mode 100644 sdk/src/exporter/otprotocol/BUILD diff --git a/WORKSPACE b/WORKSPACE index 13176f04b4..0ae6d844f0 100644 --- a/WORKSPACE +++ b/WORKSPACE @@ -15,6 +15,29 @@ workspace(name = "io_opentelemetry_cpp") load("@bazel_tools//tools/build_defs/repo:http.bzl", "http_archive") +load("@bazel_tools//tools/build_defs/repo:git.bzl", "new_git_repository") + +# Uses older protobuf version because of +# https://github.com/protocolbuffers/protobuf/issues/7179 +http_archive( + name = "com_google_protobuf", + sha256 = "b679cef31102ed8beddc39ecfd6368ee311cbee6f50742f13f21be7278781821", + strip_prefix = "protobuf-3.11.2", + urls = [ + "https://github.com/protocolbuffers/protobuf/releases/download/v3.11.2/protobuf-all-3.11.2.tar.gz", + ], +) + +load("@com_google_protobuf//:protobuf_deps.bzl", "protobuf_deps") + +protobuf_deps() + +new_git_repository( + name = "com_github_opentelemetry_proto", + remote = "https://github.com/open-telemetry/opentelemetry-proto", + commit = "d496c80b353bc4a4f754ae686b59ca3c41de0946", + build_file = "//bazel:opentelemetry_proto.BUILD", +) # GoogleTest framework. # Only needed for tests, not to build the OpenTelemetry library. diff --git a/bazel/opentelemetry_proto.BUILD b/bazel/opentelemetry_proto.BUILD new file mode 100644 index 0000000000..dfc30b5db5 --- /dev/null +++ b/bazel/opentelemetry_proto.BUILD @@ -0,0 +1,60 @@ +# Copyright 2020, OpenTelemetry Authors +# +# Licensed under the Apache License, Version 2.0 (the "License"); +# you may not use this file except in compliance with the License. +# You may obtain a copy of the License at +# +# http://www.apache.org/licenses/LICENSE-2.0 +# +# Unless required by applicable law or agreed to in writing, software +# distributed under the License is distributed on an "AS IS" BASIS, +# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +# See the License for the specific language governing permissions and +# limitations under the License. + +package(default_visibility = ["//visibility:public"]) + +load("@rules_proto//proto:defs.bzl", "proto_library") + +proto_library( + name = "common_proto", + srcs = glob([ + "opentelemetry/proto/common/v1/common.proto", + ]), +) + +cc_proto_library( + name = "common_proto_cc", + deps = [":common_proto"], +) + +proto_library( + name = "resource_proto", + srcs = glob([ + "opentelemetry/proto/resource/v1/resource.proto", + ]), + deps = [ + ":common_proto", + ], +) + +cc_proto_library( + name = "resource_proto_cc", + deps = [":resource_proto"], +) + +proto_library( + name = "trace_proto", + srcs = glob([ + "opentelemetry/proto/trace/v1/trace.proto", + ]), + deps = [ + ":common_proto", + ":resource_proto", + ], +) + +cc_proto_library( + name = "trace_proto_cc", + deps = [":trace_proto"], +) diff --git a/sdk/CMakeLists.txt b/sdk/CMakeLists.txt index febd4f0ab6..d2d5aa76f6 100644 --- a/sdk/CMakeLists.txt +++ b/sdk/CMakeLists.txt @@ -1 +1,5 @@ +if (WITH_OTPROTOCOL) + include(proto/opentelemetry/Protobuf.cmake) +endif() + add_subdirectory(src) diff --git a/sdk/src/exporter/otprotocol/proto/Protobuf.cmake b/sdk/proto/opentelemetry/Protobuf.cmake similarity index 76% rename from sdk/src/exporter/otprotocol/proto/Protobuf.cmake rename to sdk/proto/opentelemetry/Protobuf.cmake index b119707ab8..9f7c33deda 100644 --- a/sdk/src/exporter/otprotocol/proto/Protobuf.cmake +++ b/sdk/proto/opentelemetry/Protobuf.cmake @@ -1,10 +1,10 @@ -set(PROTO_PATH "${CMAKE_SOURCE_DIR}/sdk/src/exporter/otprotocol/proto") +set(PROTO_PATH "${CMAKE_SOURCE_DIR}/sdk/proto") set(COMMON_PROTO "${PROTO_PATH}/opentelemetry/proto/common/v1/common.proto") set(RESOURCE_PROTO "${PROTO_PATH}/opentelemetry/proto/resource/v1/resource.proto") set(TRACE_PROTO "${PROTO_PATH}/opentelemetry/proto/trace/v1/trace.proto") -set(GENERATED_PROTOBUF_PATH "${CMAKE_BINARY_DIR}/generated/src/sdk/exporter/otprotocol") +set(GENERATED_PROTOBUF_PATH "${CMAKE_BINARY_DIR}/generated/sdk/proto") file(MAKE_DIRECTORY "${GENERATED_PROTOBUF_PATH}") @@ -37,13 +37,12 @@ add_custom_command( ${TRACE_PROTO} ) -include_directories(SYSTEM "${CMAKE_BINARY_DIR}/generated") -include_directories(SYSTEM "${CMAKE_BINARY_DIR}/generated/src/sdk/exporter/otprotocol") +include_directories(SYSTEM "${CMAKE_BINARY_DIR}/generated/sdk/proto") -add_library(opentelemetry_exporter_otprotocol_proto OBJECT +add_library(opentelemetry_proto OBJECT ${COMMON_PB_CPP_FILE} ${RESOURCE_PB_CPP_FILE} ${TRACE_PB_CPP_FILE}) if (BUILD_SHARED_LIBS) - set_property(TARGET opentelemetry_exporter_otprotocol_proto PROPERTY POSITION_INDEPENDENT_CODE ON) + set_property(TARGET opentelemetry_proto PROPERTY POSITION_INDEPENDENT_CODE ON) endif() diff --git a/sdk/src/exporter/otprotocol/proto/README b/sdk/proto/opentelemetry/README similarity index 100% rename from sdk/src/exporter/otprotocol/proto/README rename to sdk/proto/opentelemetry/README diff --git a/sdk/src/exporter/otprotocol/proto/opentelemetry/proto/collector/README.md b/sdk/proto/opentelemetry/proto/collector/README.md similarity index 100% rename from sdk/src/exporter/otprotocol/proto/opentelemetry/proto/collector/README.md rename to sdk/proto/opentelemetry/proto/collector/README.md diff --git a/sdk/src/exporter/otprotocol/proto/opentelemetry/proto/collector/metrics/v1/metrics_service.proto b/sdk/proto/opentelemetry/proto/collector/metrics/v1/metrics_service.proto similarity index 100% rename from sdk/src/exporter/otprotocol/proto/opentelemetry/proto/collector/metrics/v1/metrics_service.proto rename to sdk/proto/opentelemetry/proto/collector/metrics/v1/metrics_service.proto diff --git a/sdk/src/exporter/otprotocol/proto/opentelemetry/proto/collector/trace/v1/trace_service.proto b/sdk/proto/opentelemetry/proto/collector/trace/v1/trace_service.proto similarity index 100% rename from sdk/src/exporter/otprotocol/proto/opentelemetry/proto/collector/trace/v1/trace_service.proto rename to sdk/proto/opentelemetry/proto/collector/trace/v1/trace_service.proto diff --git a/sdk/src/exporter/otprotocol/proto/opentelemetry/proto/collector/trace/v1/trace_service_http.yaml b/sdk/proto/opentelemetry/proto/collector/trace/v1/trace_service_http.yaml similarity index 100% rename from sdk/src/exporter/otprotocol/proto/opentelemetry/proto/collector/trace/v1/trace_service_http.yaml rename to sdk/proto/opentelemetry/proto/collector/trace/v1/trace_service_http.yaml diff --git a/sdk/src/exporter/otprotocol/proto/opentelemetry/proto/common/v1/common.proto b/sdk/proto/opentelemetry/proto/common/v1/common.proto similarity index 100% rename from sdk/src/exporter/otprotocol/proto/opentelemetry/proto/common/v1/common.proto rename to sdk/proto/opentelemetry/proto/common/v1/common.proto diff --git a/sdk/src/exporter/otprotocol/proto/opentelemetry/proto/metrics/v1/metrics.proto b/sdk/proto/opentelemetry/proto/metrics/v1/metrics.proto similarity index 100% rename from sdk/src/exporter/otprotocol/proto/opentelemetry/proto/metrics/v1/metrics.proto rename to sdk/proto/opentelemetry/proto/metrics/v1/metrics.proto diff --git a/sdk/src/exporter/otprotocol/proto/opentelemetry/proto/resource/v1/resource.proto b/sdk/proto/opentelemetry/proto/resource/v1/resource.proto similarity index 100% rename from sdk/src/exporter/otprotocol/proto/opentelemetry/proto/resource/v1/resource.proto rename to sdk/proto/opentelemetry/proto/resource/v1/resource.proto diff --git a/sdk/src/exporter/otprotocol/proto/opentelemetry/proto/trace/v1/trace.proto b/sdk/proto/opentelemetry/proto/trace/v1/trace.proto similarity index 100% rename from sdk/src/exporter/otprotocol/proto/opentelemetry/proto/trace/v1/trace.proto rename to sdk/proto/opentelemetry/proto/trace/v1/trace.proto diff --git a/sdk/src/exporter/otprotocol/proto/opentelemetry/proto/trace/v1/trace_config.proto b/sdk/proto/opentelemetry/proto/trace/v1/trace_config.proto similarity index 100% rename from sdk/src/exporter/otprotocol/proto/opentelemetry/proto/trace/v1/trace_config.proto rename to sdk/proto/opentelemetry/proto/trace/v1/trace_config.proto diff --git a/sdk/src/exporter/otprotocol/BUILD b/sdk/src/exporter/otprotocol/BUILD new file mode 100644 index 0000000000..3743bbc75b --- /dev/null +++ b/sdk/src/exporter/otprotocol/BUILD @@ -0,0 +1,30 @@ +# Copyright 2020, OpenTelemetry Authors +# +# Licensed under the Apache License, Version 2.0 (the "License"); +# you may not use this file except in compliance with the License. +# You may obtain a copy of the License at +# +# http://www.apache.org/licenses/LICENSE-2.0 +# +# Unless required by applicable law or agreed to in writing, software +# distributed under the License is distributed on an "AS IS" BASIS, +# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +# See the License for the specific language governing permissions and +# limitations under the License. + +package(default_visibility = ["//visibility:public"]) + +cc_library( + name = "recordable", + hdrs = [ + "recordable.h", + ], + srcs = [ + "recordable.cc", + ], + include_prefix = "src/exporter/otprotocol", + deps = [ + "//sdk/src/trace", + "@com_github_opentelemetry_proto//:trace_proto_cc", + ], +) diff --git a/sdk/src/exporter/otprotocol/CMakeLists.txt b/sdk/src/exporter/otprotocol/CMakeLists.txt index 70d7e83297..eb4de0894c 100644 --- a/sdk/src/exporter/otprotocol/CMakeLists.txt +++ b/sdk/src/exporter/otprotocol/CMakeLists.txt @@ -1,5 +1,3 @@ -include(proto/Protobuf.cmake) - add_library(opentelemetry_exporter_otprotocol recordable.cc) target_link_libraries(opentelemetry_exporter_otprotocol - $) + $) From f470dd06555d3efcc609984c3269cd9683a870a9 Mon Sep 17 00:00:00 2001 From: Ryan Burn Date: Wed, 11 Mar 2020 18:24:30 -0700 Subject: [PATCH 22/44] Reformat --- CMakeLists.txt | 8 +++--- WORKSPACE | 4 +-- ci/install_protobuf.sh | 2 +- sdk/CMakeLists.txt | 2 +- sdk/src/exporter/CMakeLists.txt | 2 +- sdk/src/exporter/otprotocol/BUILD | 6 ++--- sdk/src/exporter/otprotocol/CMakeLists.txt | 4 +-- sdk/src/exporter/otprotocol/recordable.cc | 28 +++++++++++++++++--- sdk/src/exporter/otprotocol/recordable.h | 30 ++++++++++++++++++---- sdk/src/trace/recordable.h | 3 +-- sdk/src/trace/recorder.h | 2 +- 11 files changed, 65 insertions(+), 26 deletions(-) diff --git a/CMakeLists.txt b/CMakeLists.txt index 7df3f0dd32..9a5580a8a0 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -9,10 +9,10 @@ project(opentelemetry-cpp) set(CMAKE_CXX_STANDARD 11) option(WITH_OTPROTOCOL - "Whether to include the OpenTelemetry Protocol in the SDK" OFF) + "Whether to include the OpenTelemetry Protocol in the SDK" OFF) set(WITH_PROTOBUF OFF) -if (WITH_OTPROTOCOL) +if(WITH_OTPROTOCOL) set(WITH_PROTOBUF ON) endif() @@ -20,11 +20,11 @@ include(CTest) find_package(Threads) -if (WITH_PROTOBUF) +if(WITH_PROTOBUF) set(protobuf_MODULE_COMPATIBLE ON) find_package(Protobuf CONFIG NAMES protobuf) # Older versions of protobuf don't use cmake config files. - if (NOT protobuf_FOUND) + if(NOT protobuf_FOUND) find_package(Protobuf REQUIRED) endif() endif() diff --git a/WORKSPACE b/WORKSPACE index 0ae6d844f0..e8403c8504 100644 --- a/WORKSPACE +++ b/WORKSPACE @@ -34,9 +34,9 @@ protobuf_deps() new_git_repository( name = "com_github_opentelemetry_proto", - remote = "https://github.com/open-telemetry/opentelemetry-proto", - commit = "d496c80b353bc4a4f754ae686b59ca3c41de0946", build_file = "//bazel:opentelemetry_proto.BUILD", + commit = "d496c80b353bc4a4f754ae686b59ca3c41de0946", + remote = "https://github.com/open-telemetry/opentelemetry-proto", ) # GoogleTest framework. diff --git a/ci/install_protobuf.sh b/ci/install_protobuf.sh index 95a48f75a6..fbab3deef1 100755 --- a/ci/install_protobuf.sh +++ b/ci/install_protobuf.sh @@ -4,7 +4,7 @@ set -e [ -z "${PROTOBUF_VERSION}" ] && export PROTOBUF_VERSION="3.11.4" -apt-get update +apt-get update apt-get install --no-install-recommends --no-install-suggests -y \ curl diff --git a/sdk/CMakeLists.txt b/sdk/CMakeLists.txt index d2d5aa76f6..e0a9869d54 100644 --- a/sdk/CMakeLists.txt +++ b/sdk/CMakeLists.txt @@ -1,4 +1,4 @@ -if (WITH_OTPROTOCOL) +if(WITH_OTPROTOCOL) include(proto/opentelemetry/Protobuf.cmake) endif() diff --git a/sdk/src/exporter/CMakeLists.txt b/sdk/src/exporter/CMakeLists.txt index a646cdfc3a..d0b48f6752 100644 --- a/sdk/src/exporter/CMakeLists.txt +++ b/sdk/src/exporter/CMakeLists.txt @@ -1,3 +1,3 @@ -if (WITH_OTPROTOCOL) +if(WITH_OTPROTOCOL) add_subdirectory(otprotocol) endif() diff --git a/sdk/src/exporter/otprotocol/BUILD b/sdk/src/exporter/otprotocol/BUILD index 3743bbc75b..d5635df61f 100644 --- a/sdk/src/exporter/otprotocol/BUILD +++ b/sdk/src/exporter/otprotocol/BUILD @@ -16,12 +16,12 @@ package(default_visibility = ["//visibility:public"]) cc_library( name = "recordable", - hdrs = [ - "recordable.h", - ], srcs = [ "recordable.cc", ], + hdrs = [ + "recordable.h", + ], include_prefix = "src/exporter/otprotocol", deps = [ "//sdk/src/trace", diff --git a/sdk/src/exporter/otprotocol/CMakeLists.txt b/sdk/src/exporter/otprotocol/CMakeLists.txt index eb4de0894c..07311ce909 100644 --- a/sdk/src/exporter/otprotocol/CMakeLists.txt +++ b/sdk/src/exporter/otprotocol/CMakeLists.txt @@ -1,3 +1,3 @@ add_library(opentelemetry_exporter_otprotocol recordable.cc) -target_link_libraries(opentelemetry_exporter_otprotocol - $) +target_link_libraries(opentelemetry_exporter_otprotocol + $) diff --git a/sdk/src/exporter/otprotocol/recordable.cc b/sdk/src/exporter/otprotocol/recordable.cc index eaa5891b1e..b67dca56cb 100644 --- a/sdk/src/exporter/otprotocol/recordable.cc +++ b/sdk/src/exporter/otprotocol/recordable.cc @@ -1,8 +1,28 @@ #include "src/exporter/otprotocol/recordable.h" OPENTELEMETRY_BEGIN_NAMESPACE -namespace exporter { -namespace otprotocol { -} // namespace otprotocol -} // namespace exporter +namespace sdk +{ +namespace exporter +{ +namespace otprotocol +{ +void Recordable::AddEvent(nostd::string_view name, core::SystemTimestamp timestamp) noexcept +{ + (void)name; +} + +void Recordable::SetStatus(trace_api::CanonicalCode code, nostd::string_view description) noexcept +{ + (void)code; + (void)description; +} + +void Recordable::SetName(nostd::string_view name) noexcept +{ + span_.set_name(name.data(), name.size()); +} +} // namespace otprotocol +} // namespace exporter +} // namespace sdk OPENTELEMETRY_END_NAMESPACE diff --git a/sdk/src/exporter/otprotocol/recordable.h b/sdk/src/exporter/otprotocol/recordable.h index 36423b6e4c..40bd05c7f0 100644 --- a/sdk/src/exporter/otprotocol/recordable.h +++ b/sdk/src/exporter/otprotocol/recordable.h @@ -2,12 +2,32 @@ #include "src/trace/recordable.h" -#include "opentelemetry/version.h" #include "opentelemetry/proto/trace/v1/trace.pb.h" +#include "opentelemetry/version.h" OPENTELEMETRY_BEGIN_NAMESPACE -namespace exporter { -namespace otprotocol { -} // namespace otprotocol -} // namespace exporter +namespace sdk +{ +namespace exporter +{ +namespace otprotocol +{ +class Recordable final : public sdk::trace::Recordable +{ +public: + const proto::trace::v1::Span &span() const noexcept { return span_; } + + // sdk::trace::Recordable + void AddEvent(nostd::string_view name, core::SystemTimestamp timestamp) noexcept override; + + void SetStatus(trace_api::CanonicalCode code, nostd::string_view description) noexcept override; + + void SetName(nostd::string_view name) noexcept override; + +private: + proto::trace::v1::Span span_; +}; +} // namespace otprotocol +} // namespace exporter +} // namespace sdk OPENTELEMETRY_END_NAMESPACE diff --git a/sdk/src/trace/recordable.h b/sdk/src/trace/recordable.h index 8bca640c91..6c7da791a4 100644 --- a/sdk/src/trace/recordable.h +++ b/sdk/src/trace/recordable.h @@ -8,10 +8,9 @@ OPENTELEMETRY_BEGIN_NAMESPACE namespace sdk { +namespace trace_api = opentelemetry::trace; namespace trace { -namespace trace_api = opentelemetry::trace; - /** * Maintains a representation of a span in a format that can be processed by a recorder. */ diff --git a/sdk/src/trace/recorder.h b/sdk/src/trace/recorder.h index d4e95a337c..b701c113d6 100644 --- a/sdk/src/trace/recorder.h +++ b/sdk/src/trace/recorder.h @@ -2,8 +2,8 @@ #include "opentelemetry/trace/span_id.h" #include "opentelemetry/trace/trace_id.h" -#include "src/trace/recordable.h" #include "opentelemetry/version.h" +#include "src/trace/recordable.h" OPENTELEMETRY_BEGIN_NAMESPACE namespace sdk From 51f91825eda5939147f3c63be78218cc025dd1f4 Mon Sep 17 00:00:00 2001 From: Ryan Burn Date: Wed, 11 Mar 2020 18:39:29 -0700 Subject: [PATCH 23/44] Install git in CI --- ci/setup_ci_environment.sh | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/ci/setup_ci_environment.sh b/ci/setup_ci_environment.sh index 56be9af1f3..50c7b373e9 100755 --- a/ci/setup_ci_environment.sh +++ b/ci/setup_ci_environment.sh @@ -5,4 +5,5 @@ apt-get update apt-get install --no-install-recommends --no-install-suggests -y \ build-essential \ ca-certificates \ - wget + wget \ + git From d240118745d913a80a29b1debb7fc7f347f38c6e Mon Sep 17 00:00:00 2001 From: Ryan Burn Date: Wed, 11 Mar 2020 18:44:45 -0700 Subject: [PATCH 24/44] Add otprotocol to cmake test --- .circleci/config.yml | 2 ++ ci/do_ci.sh | 10 ++++++++++ 2 files changed, 12 insertions(+) diff --git a/.circleci/config.yml b/.circleci/config.yml index f4494791ac..0fccaef7ff 100644 --- a/.circleci/config.yml +++ b/.circleci/config.yml @@ -12,7 +12,9 @@ jobs: - checkout - run: ./ci/setup_ci_environment.sh - run: ./ci/setup_cmake.sh + - run: ./ci/install_protobuf.sh - run: ./ci/do_ci.sh cmake.test + - run: ./ci/do_ci.sh cmake.exporter.otprotocol.test - store_artifacts: path: ~/build/Testing/Temporary/LastTest.log destination: Test.log diff --git a/ci/do_ci.sh b/ci/do_ci.sh index 9f06090415..db3be0fa14 100755 --- a/ci/do_ci.sh +++ b/ci/do_ci.sh @@ -20,6 +20,16 @@ if [[ "$1" == "cmake.test" ]]; then make make test exit 0 +if [[ "$1" == "cmake.exporter.otprotocol.test" ]]; then + cd "${BUILD_DIR}" + rm -rf * + cmake -DCMAKE_BUILD_TYPE=Debug \ + -Dcmake -DWITH_OTPROTOCOL=ON \ + -DCMAKE_CXX_FLAGS="-Werror" \ + "${SRC_DIR}" + make + make test + exit 0 elif [[ "$1" == "cmake.test_example_plugin" ]]; then # Build the plugin cd "${BUILD_DIR}" From 427314a2ad719c18366b8658d12526f18433f3d5 Mon Sep 17 00:00:00 2001 From: Ryan Burn Date: Wed, 11 Mar 2020 18:47:35 -0700 Subject: [PATCH 25/44] Fix typo --- ci/do_ci.sh | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/ci/do_ci.sh b/ci/do_ci.sh index db3be0fa14..0380f89bb7 100755 --- a/ci/do_ci.sh +++ b/ci/do_ci.sh @@ -20,7 +20,7 @@ if [[ "$1" == "cmake.test" ]]; then make make test exit 0 -if [[ "$1" == "cmake.exporter.otprotocol.test" ]]; then +elif [[ "$1" == "cmake.exporter.otprotocol.test" ]]; then cd "${BUILD_DIR}" rm -rf * cmake -DCMAKE_BUILD_TYPE=Debug \ From 5f5050c157341e3de84053562ae7ea80c7963b57 Mon Sep 17 00:00:00 2001 From: Ryan Burn Date: Wed, 11 Mar 2020 18:52:42 -0700 Subject: [PATCH 26/44] Fix install_protobuf.sh --- ci/install_protobuf.sh | 8 +------- 1 file changed, 1 insertion(+), 7 deletions(-) diff --git a/ci/install_protobuf.sh b/ci/install_protobuf.sh index fbab3deef1..860166a779 100755 --- a/ci/install_protobuf.sh +++ b/ci/install_protobuf.sh @@ -4,13 +4,7 @@ set -e [ -z "${PROTOBUF_VERSION}" ] && export PROTOBUF_VERSION="3.11.4" -apt-get update -apt-get install --no-install-recommends --no-install-suggests -y \ - curl - -# Make sure you grab the latest version -cd / -curl -OL https://github.com/google/protobuf/releases/download/v${PROTOBUF_VERSION}/protobuf-cpp-${PROTOBUF_VERSION}.tar.gz +wget https://github.com/google/protobuf/releases/download/v${PROTOBUF_VERSION}/protobuf-cpp-${PROTOBUF_VERSION}.tar.gz tar zxf protobuf-cpp-${PROTOBUF_VERSION}.tar.gz cd protobuf-${PROTOBUF_VERSION} ./configure From 092bd8d4eb4756eaee16901470a0cbc5d629381d Mon Sep 17 00:00:00 2001 From: Ryan Burn Date: Wed, 11 Mar 2020 18:56:54 -0700 Subject: [PATCH 27/44] Fix install_protobuf.sh --- ci/install_protobuf.sh | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/ci/install_protobuf.sh b/ci/install_protobuf.sh index 860166a779..31aa1efa59 100755 --- a/ci/install_protobuf.sh +++ b/ci/install_protobuf.sh @@ -4,8 +4,9 @@ set -e [ -z "${PROTOBUF_VERSION}" ] && export PROTOBUF_VERSION="3.11.4" +cd / wget https://github.com/google/protobuf/releases/download/v${PROTOBUF_VERSION}/protobuf-cpp-${PROTOBUF_VERSION}.tar.gz -tar zxf protobuf-cpp-${PROTOBUF_VERSION}.tar.gz +tar zxf --no-same-owner protobuf-cpp-${PROTOBUF_VERSION}.tar.gz cd protobuf-${PROTOBUF_VERSION} ./configure make && make install From a979b8ef00feb24d4ff287b0e3644235568c1a97 Mon Sep 17 00:00:00 2001 From: Ryan Burn Date: Wed, 11 Mar 2020 18:59:26 -0700 Subject: [PATCH 28/44] Fix install_protobuf.sh --- ci/install_protobuf.sh | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/ci/install_protobuf.sh b/ci/install_protobuf.sh index 31aa1efa59..71390f9a2a 100755 --- a/ci/install_protobuf.sh +++ b/ci/install_protobuf.sh @@ -6,7 +6,7 @@ set -e cd / wget https://github.com/google/protobuf/releases/download/v${PROTOBUF_VERSION}/protobuf-cpp-${PROTOBUF_VERSION}.tar.gz -tar zxf --no-same-owner protobuf-cpp-${PROTOBUF_VERSION}.tar.gz +tar zxf protobuf-cpp-${PROTOBUF_VERSION}.tar.gz --no-same-owner cd protobuf-${PROTOBUF_VERSION} ./configure make && make install From fda73fe8b17cfa2d3117a91355dbc3018a6cc297 Mon Sep 17 00:00:00 2001 From: Ryan Burn Date: Wed, 11 Mar 2020 19:14:06 -0700 Subject: [PATCH 29/44] Fix do_ci.sh --- ci/do_ci.sh | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/ci/do_ci.sh b/ci/do_ci.sh index 0380f89bb7..8fa3f2a89e 100755 --- a/ci/do_ci.sh +++ b/ci/do_ci.sh @@ -24,7 +24,7 @@ elif [[ "$1" == "cmake.exporter.otprotocol.test" ]]; then cd "${BUILD_DIR}" rm -rf * cmake -DCMAKE_BUILD_TYPE=Debug \ - -Dcmake -DWITH_OTPROTOCOL=ON \ + -DWITH_OTPROTOCOL=ON \ -DCMAKE_CXX_FLAGS="-Werror" \ "${SRC_DIR}" make From 366e9e092864d0e9c25d305038ab5ed0438eca20 Mon Sep 17 00:00:00 2001 From: Ryan Burn Date: Wed, 11 Mar 2020 19:38:07 -0700 Subject: [PATCH 30/44] Add otprotocol windows tests --- .circleci/config.yml | 1 + ci/do_ci.ps1 | 21 +++++++++++++++++++++ ci/setup_windows_ci_environment.ps1 | 1 + 3 files changed, 23 insertions(+) diff --git a/.circleci/config.yml b/.circleci/config.yml index 0fccaef7ff..175db1d05f 100644 --- a/.circleci/config.yml +++ b/.circleci/config.yml @@ -114,6 +114,7 @@ jobs: - run: ./ci/setup_windows_cmake.ps1 - run: ./ci/setup_windows_ci_environment.ps1 - run: ./ci/do_ci.ps1 cmake.test + - run: ./ci/do_ci.sh cmake.exporter.otprotocol.test windows_plugin_test: executor: win/vs2019 diff --git a/ci/do_ci.ps1 b/ci/do_ci.ps1 index 62e643439c..fcadf17c15 100644 --- a/ci/do_ci.ps1 +++ b/ci/do_ci.ps1 @@ -38,6 +38,27 @@ switch ($action) { exit $exit } } + "cmake.exporter.otprotocol.test" { + cd "$BUILD_DIR" + cmake $SRC_DIR ` + -DVCPKG_TARGET_TRIPLET=x64-windows ` + -DWITH_OTPROTCOL=ON ` + "-DCMAKE_TOOLCHAIN_FILE=$VCPKG_DIR\scripts\buildsystems\vcpkg.cmake" + $exit = $LASTEXITCODE + if ($exit -ne 0) { + exit $exit + } + cmake --build . + $exit = $LASTEXITCODE + if ($exit -ne 0) { + exit $exit + } + ctest -C Debug + $exit = $LASTEXITCODE + if ($exit -ne 0) { + exit $exit + } + } "cmake.build_example_plugin" { cd "$BUILD_DIR" cmake $SRC_DIR ` diff --git a/ci/setup_windows_ci_environment.ps1 b/ci/setup_windows_ci_environment.ps1 index a1b1b89d9c..7dda61ba87 100755 --- a/ci/setup_windows_ci_environment.ps1 +++ b/ci/setup_windows_ci_environment.ps1 @@ -8,3 +8,4 @@ $VCPKG_DIR=(Get-Item -Path ".\").FullName ./vcpkg integrate install ./vcpkg install benchmark:x64-windows ./vcpkg install gtest:x64-windows +/vcpkg install protobuf:x64-windows From 9094a52439f0b0fcf4f0a527fbb2c74376020dc5 Mon Sep 17 00:00:00 2001 From: Ryan Burn Date: Wed, 11 Mar 2020 19:42:40 -0700 Subject: [PATCH 31/44] Fix typo --- ci/setup_windows_ci_environment.ps1 | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/ci/setup_windows_ci_environment.ps1 b/ci/setup_windows_ci_environment.ps1 index 7dda61ba87..bb32e73b9d 100755 --- a/ci/setup_windows_ci_environment.ps1 +++ b/ci/setup_windows_ci_environment.ps1 @@ -8,4 +8,4 @@ $VCPKG_DIR=(Get-Item -Path ".\").FullName ./vcpkg integrate install ./vcpkg install benchmark:x64-windows ./vcpkg install gtest:x64-windows -/vcpkg install protobuf:x64-windows +./vcpkg install protobuf:x64-windows From b3d611b83f0c8f293477099cd0cf35d13df9e4be Mon Sep 17 00:00:00 2001 From: Ryan Burn Date: Wed, 11 Mar 2020 21:46:44 -0700 Subject: [PATCH 32/44] Make protobuf install optional for windows --- .circleci/config.yml | 1 + ci/install_windows_protobuf.ps1 | 4 ++++ ci/setup_windows_ci_environment.ps1 | 1 - 3 files changed, 5 insertions(+), 1 deletion(-) create mode 100644 ci/install_windows_protobuf.ps1 diff --git a/.circleci/config.yml b/.circleci/config.yml index 175db1d05f..2d63546b64 100644 --- a/.circleci/config.yml +++ b/.circleci/config.yml @@ -113,6 +113,7 @@ jobs: - checkout - run: ./ci/setup_windows_cmake.ps1 - run: ./ci/setup_windows_ci_environment.ps1 + - run: ./ci/install_windows_protobuf.ps1 - run: ./ci/do_ci.ps1 cmake.test - run: ./ci/do_ci.sh cmake.exporter.otprotocol.test diff --git a/ci/install_windows_protobuf.ps1 b/ci/install_windows_protobuf.ps1 new file mode 100644 index 0000000000..0ea70b785c --- /dev/null +++ b/ci/install_windows_protobuf.ps1 @@ -0,0 +1,4 @@ +$ErrorActionPreference = "Stop" +trap { $host.SetShouldExit(1) } + +./vcpkg install protobuf:x64-windows diff --git a/ci/setup_windows_ci_environment.ps1 b/ci/setup_windows_ci_environment.ps1 index bb32e73b9d..a1b1b89d9c 100755 --- a/ci/setup_windows_ci_environment.ps1 +++ b/ci/setup_windows_ci_environment.ps1 @@ -8,4 +8,3 @@ $VCPKG_DIR=(Get-Item -Path ".\").FullName ./vcpkg integrate install ./vcpkg install benchmark:x64-windows ./vcpkg install gtest:x64-windows -./vcpkg install protobuf:x64-windows From 3b9452160816df75abd64cd0d0e08fdcd746a4c7 Mon Sep 17 00:00:00 2001 From: Ryan Burn Date: Wed, 11 Mar 2020 21:52:47 -0700 Subject: [PATCH 33/44] Fix install_windows_protobuf.ps1 --- ci/install_windows_protobuf.ps1 | 1 + 1 file changed, 1 insertion(+) diff --git a/ci/install_windows_protobuf.ps1 b/ci/install_windows_protobuf.ps1 index 0ea70b785c..79ba092781 100644 --- a/ci/install_windows_protobuf.ps1 +++ b/ci/install_windows_protobuf.ps1 @@ -1,4 +1,5 @@ $ErrorActionPreference = "Stop" trap { $host.SetShouldExit(1) } +cd vcpkg ./vcpkg install protobuf:x64-windows From 27e8526c61ceacc321ffa405eed6eb5cbb5e7c09 Mon Sep 17 00:00:00 2001 From: Ryan Burn Date: Thu, 12 Mar 2020 21:40:54 -0700 Subject: [PATCH 34/44] Remove unnecessary globs --- bazel/opentelemetry_proto.BUILD | 12 ++++++------ 1 file changed, 6 insertions(+), 6 deletions(-) diff --git a/bazel/opentelemetry_proto.BUILD b/bazel/opentelemetry_proto.BUILD index dfc30b5db5..ddb9915bf2 100644 --- a/bazel/opentelemetry_proto.BUILD +++ b/bazel/opentelemetry_proto.BUILD @@ -18,9 +18,9 @@ load("@rules_proto//proto:defs.bzl", "proto_library") proto_library( name = "common_proto", - srcs = glob([ + srcs = [ "opentelemetry/proto/common/v1/common.proto", - ]), + ], ) cc_proto_library( @@ -30,9 +30,9 @@ cc_proto_library( proto_library( name = "resource_proto", - srcs = glob([ + srcs = [ "opentelemetry/proto/resource/v1/resource.proto", - ]), + ], deps = [ ":common_proto", ], @@ -45,9 +45,9 @@ cc_proto_library( proto_library( name = "trace_proto", - srcs = glob([ + srcs = [ "opentelemetry/proto/trace/v1/trace.proto", - ]), + ], deps = [ ":common_proto", ":resource_proto", From 1fbb06ec8f82297fd3b49103779e4ab4ec8d550a Mon Sep 17 00:00:00 2001 From: Ryan Burn Date: Tue, 17 Mar 2020 14:57:40 -0700 Subject: [PATCH 35/44] Refactor --- WORKSPACE | 6 ++++++ api/include/opentelemetry/plugin/detail/utility.h | 2 +- api/test/nostd/shared_ptr_test.cc | 3 +-- api/test/nostd/unique_ptr_test.cc | 3 +-- 4 files changed, 9 insertions(+), 5 deletions(-) diff --git a/WORKSPACE b/WORKSPACE index e8403c8504..b2860bb1a0 100644 --- a/WORKSPACE +++ b/WORKSPACE @@ -39,6 +39,12 @@ new_git_repository( remote = "https://github.com/open-telemetry/opentelemetry-proto", ) +# new_local_repository( +# name = "com_github_opentelemetry_proto", +# build_file = "//bazel:opentelemetry_proto.BUILD", +# path = "sdk/proto/opentelemetry", +# ) + # GoogleTest framework. # Only needed for tests, not to build the OpenTelemetry library. http_archive( diff --git a/api/include/opentelemetry/plugin/detail/utility.h b/api/include/opentelemetry/plugin/detail/utility.h index 789371d0e2..56f17b6231 100644 --- a/api/include/opentelemetry/plugin/detail/utility.h +++ b/api/include/opentelemetry/plugin/detail/utility.h @@ -13,7 +13,7 @@ namespace detail { inline void CopyErrorMessage(const char *source, std::string &destination) noexcept #if __EXCEPTIONS -try + try #endif { if (source == nullptr) diff --git a/api/test/nostd/shared_ptr_test.cc b/api/test/nostd/shared_ptr_test.cc index 7f18d3bdb5..31180aaaf3 100644 --- a/api/test/nostd/shared_ptr_test.cc +++ b/api/test/nostd/shared_ptr_test.cc @@ -124,8 +124,7 @@ TEST(SharedPtrTest, PointerOperators) shared_ptr ptr1{value}; EXPECT_EQ(&*ptr1, value); - EXPECT_EQ( - shared_ptr {}->f(), 123); + EXPECT_EQ(shared_ptr {}->f(), 123); } TEST(SharedPtrTest, Swap) diff --git a/api/test/nostd/unique_ptr_test.cc b/api/test/nostd/unique_ptr_test.cc index ee1ae17f4a..521e8e16dc 100644 --- a/api/test/nostd/unique_ptr_test.cc +++ b/api/test/nostd/unique_ptr_test.cc @@ -108,8 +108,7 @@ TEST(UniquePtrTest, PointerOperators) unique_ptr ptr1{value}; EXPECT_EQ(&*ptr1, value); - EXPECT_EQ( - unique_ptr {}->f(), 123); + EXPECT_EQ(unique_ptr {}->f(), 123); } TEST(UniquePtrTest, Reset) From 2f3296c68d37e4853e8d964b27664fc13f8a928c Mon Sep 17 00:00:00 2001 From: Ryan Burn Date: Wed, 18 Mar 2020 21:32:49 -0700 Subject: [PATCH 36/44] Rearrange protobuf files --- CMakeLists.txt | 4 ++++ WORKSPACE | 11 ++--------- sdk/CMakeLists.txt | 4 ---- .../opentelemetry-proto}/Protobuf.cmake | 6 +++--- .../opentelemetry-proto}/README | 0 .../opentelemetry/proto/collector/README.md | 0 .../proto/collector/metrics/v1/metrics_service.proto | 0 .../proto/collector/trace/v1/trace_service.proto | 0 .../proto/collector/trace/v1/trace_service_http.yaml | 0 .../opentelemetry/proto/common/v1/common.proto | 0 .../opentelemetry/proto/metrics/v1/metrics.proto | 0 .../opentelemetry/proto/resource/v1/resource.proto | 0 .../opentelemetry/proto/trace/v1/trace.proto | 0 .../opentelemetry/proto/trace/v1/trace_config.proto | 0 14 files changed, 9 insertions(+), 16 deletions(-) rename {sdk/proto/opentelemetry => third_party/opentelemetry-proto}/Protobuf.cmake (86%) rename {sdk/proto/opentelemetry => third_party/opentelemetry-proto}/README (100%) rename {sdk/proto => third_party/opentelemetry-proto}/opentelemetry/proto/collector/README.md (100%) rename {sdk/proto => third_party/opentelemetry-proto}/opentelemetry/proto/collector/metrics/v1/metrics_service.proto (100%) rename {sdk/proto => third_party/opentelemetry-proto}/opentelemetry/proto/collector/trace/v1/trace_service.proto (100%) rename {sdk/proto => third_party/opentelemetry-proto}/opentelemetry/proto/collector/trace/v1/trace_service_http.yaml (100%) rename {sdk/proto => third_party/opentelemetry-proto}/opentelemetry/proto/common/v1/common.proto (100%) rename {sdk/proto => third_party/opentelemetry-proto}/opentelemetry/proto/metrics/v1/metrics.proto (100%) rename {sdk/proto => third_party/opentelemetry-proto}/opentelemetry/proto/resource/v1/resource.proto (100%) rename {sdk/proto => third_party/opentelemetry-proto}/opentelemetry/proto/trace/v1/trace.proto (100%) rename {sdk/proto => third_party/opentelemetry-proto}/opentelemetry/proto/trace/v1/trace_config.proto (100%) diff --git a/CMakeLists.txt b/CMakeLists.txt index 9a5580a8a0..6404b9bab7 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -29,6 +29,10 @@ if(WITH_PROTOBUF) endif() endif() +if(WITH_OTPROTOCOL) + include(third_party/opentelemetry-proto/Protobuf.cmake) +endif() + if(BUILD_TESTING) find_package(GTest REQUIRED) find_package(benchmark REQUIRED) diff --git a/WORKSPACE b/WORKSPACE index b2860bb1a0..7bd87369c4 100644 --- a/WORKSPACE +++ b/WORKSPACE @@ -32,19 +32,12 @@ load("@com_google_protobuf//:protobuf_deps.bzl", "protobuf_deps") protobuf_deps() -new_git_repository( +new_local_repository( name = "com_github_opentelemetry_proto", build_file = "//bazel:opentelemetry_proto.BUILD", - commit = "d496c80b353bc4a4f754ae686b59ca3c41de0946", - remote = "https://github.com/open-telemetry/opentelemetry-proto", + path = "third_party/opentelemetry-proto", ) -# new_local_repository( -# name = "com_github_opentelemetry_proto", -# build_file = "//bazel:opentelemetry_proto.BUILD", -# path = "sdk/proto/opentelemetry", -# ) - # GoogleTest framework. # Only needed for tests, not to build the OpenTelemetry library. http_archive( diff --git a/sdk/CMakeLists.txt b/sdk/CMakeLists.txt index e0a9869d54..febd4f0ab6 100644 --- a/sdk/CMakeLists.txt +++ b/sdk/CMakeLists.txt @@ -1,5 +1 @@ -if(WITH_OTPROTOCOL) - include(proto/opentelemetry/Protobuf.cmake) -endif() - add_subdirectory(src) diff --git a/sdk/proto/opentelemetry/Protobuf.cmake b/third_party/opentelemetry-proto/Protobuf.cmake similarity index 86% rename from sdk/proto/opentelemetry/Protobuf.cmake rename to third_party/opentelemetry-proto/Protobuf.cmake index 9f7c33deda..50a174f1fc 100644 --- a/sdk/proto/opentelemetry/Protobuf.cmake +++ b/third_party/opentelemetry-proto/Protobuf.cmake @@ -1,10 +1,10 @@ -set(PROTO_PATH "${CMAKE_SOURCE_DIR}/sdk/proto") +set(PROTO_PATH "${CMAKE_SOURCE_DIR}/third_party/opentelemetry-proto") set(COMMON_PROTO "${PROTO_PATH}/opentelemetry/proto/common/v1/common.proto") set(RESOURCE_PROTO "${PROTO_PATH}/opentelemetry/proto/resource/v1/resource.proto") set(TRACE_PROTO "${PROTO_PATH}/opentelemetry/proto/trace/v1/trace.proto") -set(GENERATED_PROTOBUF_PATH "${CMAKE_BINARY_DIR}/generated/sdk/proto") +set(GENERATED_PROTOBUF_PATH "${CMAKE_BINARY_DIR}/generated/third_party/opentelemetry-proto") file(MAKE_DIRECTORY "${GENERATED_PROTOBUF_PATH}") @@ -37,7 +37,7 @@ add_custom_command( ${TRACE_PROTO} ) -include_directories(SYSTEM "${CMAKE_BINARY_DIR}/generated/sdk/proto") +include_directories(SYSTEM "${CMAKE_BINARY_DIR}/generated/third_party/opentelemetry-proto") add_library(opentelemetry_proto OBJECT ${COMMON_PB_CPP_FILE} diff --git a/sdk/proto/opentelemetry/README b/third_party/opentelemetry-proto/README similarity index 100% rename from sdk/proto/opentelemetry/README rename to third_party/opentelemetry-proto/README diff --git a/sdk/proto/opentelemetry/proto/collector/README.md b/third_party/opentelemetry-proto/opentelemetry/proto/collector/README.md similarity index 100% rename from sdk/proto/opentelemetry/proto/collector/README.md rename to third_party/opentelemetry-proto/opentelemetry/proto/collector/README.md diff --git a/sdk/proto/opentelemetry/proto/collector/metrics/v1/metrics_service.proto b/third_party/opentelemetry-proto/opentelemetry/proto/collector/metrics/v1/metrics_service.proto similarity index 100% rename from sdk/proto/opentelemetry/proto/collector/metrics/v1/metrics_service.proto rename to third_party/opentelemetry-proto/opentelemetry/proto/collector/metrics/v1/metrics_service.proto diff --git a/sdk/proto/opentelemetry/proto/collector/trace/v1/trace_service.proto b/third_party/opentelemetry-proto/opentelemetry/proto/collector/trace/v1/trace_service.proto similarity index 100% rename from sdk/proto/opentelemetry/proto/collector/trace/v1/trace_service.proto rename to third_party/opentelemetry-proto/opentelemetry/proto/collector/trace/v1/trace_service.proto diff --git a/sdk/proto/opentelemetry/proto/collector/trace/v1/trace_service_http.yaml b/third_party/opentelemetry-proto/opentelemetry/proto/collector/trace/v1/trace_service_http.yaml similarity index 100% rename from sdk/proto/opentelemetry/proto/collector/trace/v1/trace_service_http.yaml rename to third_party/opentelemetry-proto/opentelemetry/proto/collector/trace/v1/trace_service_http.yaml diff --git a/sdk/proto/opentelemetry/proto/common/v1/common.proto b/third_party/opentelemetry-proto/opentelemetry/proto/common/v1/common.proto similarity index 100% rename from sdk/proto/opentelemetry/proto/common/v1/common.proto rename to third_party/opentelemetry-proto/opentelemetry/proto/common/v1/common.proto diff --git a/sdk/proto/opentelemetry/proto/metrics/v1/metrics.proto b/third_party/opentelemetry-proto/opentelemetry/proto/metrics/v1/metrics.proto similarity index 100% rename from sdk/proto/opentelemetry/proto/metrics/v1/metrics.proto rename to third_party/opentelemetry-proto/opentelemetry/proto/metrics/v1/metrics.proto diff --git a/sdk/proto/opentelemetry/proto/resource/v1/resource.proto b/third_party/opentelemetry-proto/opentelemetry/proto/resource/v1/resource.proto similarity index 100% rename from sdk/proto/opentelemetry/proto/resource/v1/resource.proto rename to third_party/opentelemetry-proto/opentelemetry/proto/resource/v1/resource.proto diff --git a/sdk/proto/opentelemetry/proto/trace/v1/trace.proto b/third_party/opentelemetry-proto/opentelemetry/proto/trace/v1/trace.proto similarity index 100% rename from sdk/proto/opentelemetry/proto/trace/v1/trace.proto rename to third_party/opentelemetry-proto/opentelemetry/proto/trace/v1/trace.proto diff --git a/sdk/proto/opentelemetry/proto/trace/v1/trace_config.proto b/third_party/opentelemetry-proto/opentelemetry/proto/trace/v1/trace_config.proto similarity index 100% rename from sdk/proto/opentelemetry/proto/trace/v1/trace_config.proto rename to third_party/opentelemetry-proto/opentelemetry/proto/trace/v1/trace_config.proto From 49c27fe417cd4b12dfbb3a2bcc7b85a67bfcf64a Mon Sep 17 00:00:00 2001 From: Ryan Burn Date: Wed, 18 Mar 2020 22:14:11 -0700 Subject: [PATCH 37/44] Clean up workspace --- WORKSPACE | 1 - 1 file changed, 1 deletion(-) diff --git a/WORKSPACE b/WORKSPACE index 7bd87369c4..1dd2ea37fc 100644 --- a/WORKSPACE +++ b/WORKSPACE @@ -15,7 +15,6 @@ workspace(name = "io_opentelemetry_cpp") load("@bazel_tools//tools/build_defs/repo:http.bzl", "http_archive") -load("@bazel_tools//tools/build_defs/repo:git.bzl", "new_git_repository") # Uses older protobuf version because of # https://github.com/protocolbuffers/protobuf/issues/7179 From 28c8e5b09adaa7cf696242a571c9600e244b6939 Mon Sep 17 00:00:00 2001 From: Ryan Burn Date: Wed, 18 Mar 2020 22:17:28 -0700 Subject: [PATCH 38/44] Fix formatting --- api/include/opentelemetry/plugin/detail/utility.h | 2 +- api/test/nostd/shared_ptr_test.cc | 3 ++- api/test/nostd/unique_ptr_test.cc | 3 ++- 3 files changed, 5 insertions(+), 3 deletions(-) diff --git a/api/include/opentelemetry/plugin/detail/utility.h b/api/include/opentelemetry/plugin/detail/utility.h index 56f17b6231..789371d0e2 100644 --- a/api/include/opentelemetry/plugin/detail/utility.h +++ b/api/include/opentelemetry/plugin/detail/utility.h @@ -13,7 +13,7 @@ namespace detail { inline void CopyErrorMessage(const char *source, std::string &destination) noexcept #if __EXCEPTIONS - try +try #endif { if (source == nullptr) diff --git a/api/test/nostd/shared_ptr_test.cc b/api/test/nostd/shared_ptr_test.cc index 31180aaaf3..7f18d3bdb5 100644 --- a/api/test/nostd/shared_ptr_test.cc +++ b/api/test/nostd/shared_ptr_test.cc @@ -124,7 +124,8 @@ TEST(SharedPtrTest, PointerOperators) shared_ptr ptr1{value}; EXPECT_EQ(&*ptr1, value); - EXPECT_EQ(shared_ptr {}->f(), 123); + EXPECT_EQ( + shared_ptr {}->f(), 123); } TEST(SharedPtrTest, Swap) diff --git a/api/test/nostd/unique_ptr_test.cc b/api/test/nostd/unique_ptr_test.cc index 521e8e16dc..ee1ae17f4a 100644 --- a/api/test/nostd/unique_ptr_test.cc +++ b/api/test/nostd/unique_ptr_test.cc @@ -108,7 +108,8 @@ TEST(UniquePtrTest, PointerOperators) unique_ptr ptr1{value}; EXPECT_EQ(&*ptr1, value); - EXPECT_EQ(unique_ptr {}->f(), 123); + EXPECT_EQ( + unique_ptr {}->f(), 123); } TEST(UniquePtrTest, Reset) From 6f5316c42d1594b089e650eaf99c99b8b324de58 Mon Sep 17 00:00:00 2001 From: Ryan Burn Date: Wed, 25 Mar 2020 20:48:39 -0700 Subject: [PATCH 39/44] Update CI --- .circleci/config.yml | 2 +- ci/README.md | 2 ++ ci/do_ci.sh | 4 ++++ 3 files changed, 7 insertions(+), 1 deletion(-) diff --git a/.circleci/config.yml b/.circleci/config.yml index 17700fe25b..e9cdcf67ec 100644 --- a/.circleci/config.yml +++ b/.circleci/config.yml @@ -44,7 +44,7 @@ jobs: - run: ./ci/setup_ci_environment.sh - run: ./ci/install_bazelisk.sh - run: ./ci/install_gcc48.sh - - run: CC=/usr/bin/g++-4.8 ./ci/do_ci.sh bazel.test + - run: CC=/usr/bin/g++-4.8 ./ci/do_ci.sh bazel.test_api bazel_test: resource_class: xlarge diff --git a/ci/README.md b/ci/README.md index e985c6e3b8..b1629c6b1f 100644 --- a/ci/README.md +++ b/ci/README.md @@ -4,6 +4,8 @@ CI tests can be run on docker by invoking the script `./ci/run_docker.sh ./ci/do * `cmake.test`: build cmake targets and run tests. * `cmake.test_example_plugin`: build and test an example OpenTelemetry plugin. +* `cmake.exporter.otprotocol.test`: build and test the otprotocol exporter +* `bazel.test_api`: build bazel targets and run tests for the api only. * `bazel.test`: build bazel targets and run tests. * `bazel.noexcept`: build bazel targets and run tests with exceptions disabled. * `bazel.asan`: build bazel targets and run tests with AddressSanitizer. diff --git a/ci/do_ci.sh b/ci/do_ci.sh index b444ff0bbe..b38bb40e9a 100755 --- a/ci/do_ci.sh +++ b/ci/do_ci.sh @@ -64,6 +64,10 @@ EOF make load_plugin_example examples/plugin/load/load_plugin_example ${PLUGIN_DIR}/libexample_plugin.so /dev/null exit 0 +elif [[ "$1" == "bazel.test_api" ]]; then + bazel build $BAZEL_OPTIONS //api/... + bazel test $BAZEL_TEST_OPTIONS //api/... + exit 0 elif [[ "$1" == "bazel.test" ]]; then bazel build $BAZEL_OPTIONS //... bazel test $BAZEL_TEST_OPTIONS //... From 1d83819dc71867e00b17ce727a6bf13054372992 Mon Sep 17 00:00:00 2001 From: Ryan Burn Date: Fri, 3 Apr 2020 20:35:13 -0700 Subject: [PATCH 40/44] Restructure --- CMakeLists.txt | 2 ++ exporters/CMakeLists.txt | 4 ++++ .../src/exporter/otprotocol => exporters/otlp}/BUILD | 2 +- .../otprotocol => exporters/otlp}/CMakeLists.txt | 0 .../otprotocol => exporters/otlp}/recordable.cc | 9 +++------ .../otprotocol => exporters/otlp}/recordable.h | 12 ++++-------- .../opentelemetry/sdk}/trace/recordable.h | 0 sdk/src/CMakeLists.txt | 1 - sdk/src/exporter/CMakeLists.txt | 3 --- sdk/src/trace/recorder.h | 2 +- 10 files changed, 15 insertions(+), 20 deletions(-) create mode 100644 exporters/CMakeLists.txt rename {sdk/src/exporter/otprotocol => exporters/otlp}/BUILD (94%) rename {sdk/src/exporter/otprotocol => exporters/otlp}/CMakeLists.txt (100%) rename {sdk/src/exporter/otprotocol => exporters/otlp}/recordable.cc (65%) rename {sdk/src/exporter/otprotocol => exporters/otlp}/recordable.h (72%) rename sdk/{src => include/opentelemetry/sdk}/trace/recordable.h (100%) delete mode 100644 sdk/src/exporter/CMakeLists.txt diff --git a/CMakeLists.txt b/CMakeLists.txt index 6404b9bab7..264d58992d 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -44,4 +44,6 @@ add_subdirectory(api) include_directories(sdk/include) include_directories(sdk) add_subdirectory(sdk) +include_directories(.) +add_subdirectory(exporters) add_subdirectory(examples) diff --git a/exporters/CMakeLists.txt b/exporters/CMakeLists.txt new file mode 100644 index 0000000000..9b0c2d54c2 --- /dev/null +++ b/exporters/CMakeLists.txt @@ -0,0 +1,4 @@ +if(WITH_OTPROTOCOL) + add_subdirectory(otlp) +endif() + diff --git a/sdk/src/exporter/otprotocol/BUILD b/exporters/otlp/BUILD similarity index 94% rename from sdk/src/exporter/otprotocol/BUILD rename to exporters/otlp/BUILD index d5635df61f..09b1516ab5 100644 --- a/sdk/src/exporter/otprotocol/BUILD +++ b/exporters/otlp/BUILD @@ -22,7 +22,7 @@ cc_library( hdrs = [ "recordable.h", ], - include_prefix = "src/exporter/otprotocol", + include_prefix = "exporters/otlp", deps = [ "//sdk/src/trace", "@com_github_opentelemetry_proto//:trace_proto_cc", diff --git a/sdk/src/exporter/otprotocol/CMakeLists.txt b/exporters/otlp/CMakeLists.txt similarity index 100% rename from sdk/src/exporter/otprotocol/CMakeLists.txt rename to exporters/otlp/CMakeLists.txt diff --git a/sdk/src/exporter/otprotocol/recordable.cc b/exporters/otlp/recordable.cc similarity index 65% rename from sdk/src/exporter/otprotocol/recordable.cc rename to exporters/otlp/recordable.cc index b67dca56cb..92a2c78e7e 100644 --- a/sdk/src/exporter/otprotocol/recordable.cc +++ b/exporters/otlp/recordable.cc @@ -1,18 +1,16 @@ -#include "src/exporter/otprotocol/recordable.h" +#include "exporters/otlp/recordable.h" OPENTELEMETRY_BEGIN_NAMESPACE -namespace sdk -{ namespace exporter { -namespace otprotocol +namespace otlp { void Recordable::AddEvent(nostd::string_view name, core::SystemTimestamp timestamp) noexcept { (void)name; } -void Recordable::SetStatus(trace_api::CanonicalCode code, nostd::string_view description) noexcept +void Recordable::SetStatus(trace::CanonicalCode code, nostd::string_view description) noexcept { (void)code; (void)description; @@ -24,5 +22,4 @@ void Recordable::SetName(nostd::string_view name) noexcept } } // namespace otprotocol } // namespace exporter -} // namespace sdk OPENTELEMETRY_END_NAMESPACE diff --git a/sdk/src/exporter/otprotocol/recordable.h b/exporters/otlp/recordable.h similarity index 72% rename from sdk/src/exporter/otprotocol/recordable.h rename to exporters/otlp/recordable.h index 40bd05c7f0..12be1f3f6e 100644 --- a/sdk/src/exporter/otprotocol/recordable.h +++ b/exporters/otlp/recordable.h @@ -1,16 +1,13 @@ #pragma once -#include "src/trace/recordable.h" - +#include "opentelemetry/sdk/trace/recordable.h" #include "opentelemetry/proto/trace/v1/trace.pb.h" #include "opentelemetry/version.h" OPENTELEMETRY_BEGIN_NAMESPACE -namespace sdk -{ namespace exporter { -namespace otprotocol +namespace otlp { class Recordable final : public sdk::trace::Recordable { @@ -20,14 +17,13 @@ class Recordable final : public sdk::trace::Recordable // sdk::trace::Recordable void AddEvent(nostd::string_view name, core::SystemTimestamp timestamp) noexcept override; - void SetStatus(trace_api::CanonicalCode code, nostd::string_view description) noexcept override; + void SetStatus(trace::CanonicalCode code, nostd::string_view description) noexcept override; void SetName(nostd::string_view name) noexcept override; private: proto::trace::v1::Span span_; }; -} // namespace otprotocol +} // namespace otlp } // namespace exporter -} // namespace sdk OPENTELEMETRY_END_NAMESPACE diff --git a/sdk/src/trace/recordable.h b/sdk/include/opentelemetry/sdk/trace/recordable.h similarity index 100% rename from sdk/src/trace/recordable.h rename to sdk/include/opentelemetry/sdk/trace/recordable.h diff --git a/sdk/src/CMakeLists.txt b/sdk/src/CMakeLists.txt index 164d1358e1..8c8b199946 100644 --- a/sdk/src/CMakeLists.txt +++ b/sdk/src/CMakeLists.txt @@ -1,3 +1,2 @@ add_subdirectory(common) add_subdirectory(trace) -add_subdirectory(exporter) diff --git a/sdk/src/exporter/CMakeLists.txt b/sdk/src/exporter/CMakeLists.txt deleted file mode 100644 index d0b48f6752..0000000000 --- a/sdk/src/exporter/CMakeLists.txt +++ /dev/null @@ -1,3 +0,0 @@ -if(WITH_OTPROTOCOL) - add_subdirectory(otprotocol) -endif() diff --git a/sdk/src/trace/recorder.h b/sdk/src/trace/recorder.h index b701c113d6..c2c398d7ce 100644 --- a/sdk/src/trace/recorder.h +++ b/sdk/src/trace/recorder.h @@ -3,7 +3,7 @@ #include "opentelemetry/trace/span_id.h" #include "opentelemetry/trace/trace_id.h" #include "opentelemetry/version.h" -#include "src/trace/recordable.h" +#include "opentelemetry/sdk/trace/recordable.h" OPENTELEMETRY_BEGIN_NAMESPACE namespace sdk From f64c826ce33965a46a64dd72afedbf4d67983feb Mon Sep 17 00:00:00 2001 From: Ryan Burn Date: Fri, 3 Apr 2020 20:35:37 -0700 Subject: [PATCH 41/44] Reformat --- exporters/CMakeLists.txt | 1 - exporters/otlp/recordable.cc | 2 +- exporters/otlp/recordable.h | 2 +- sdk/src/trace/recorder.h | 2 +- 4 files changed, 3 insertions(+), 4 deletions(-) diff --git a/exporters/CMakeLists.txt b/exporters/CMakeLists.txt index 9b0c2d54c2..c70dee5473 100644 --- a/exporters/CMakeLists.txt +++ b/exporters/CMakeLists.txt @@ -1,4 +1,3 @@ if(WITH_OTPROTOCOL) add_subdirectory(otlp) endif() - diff --git a/exporters/otlp/recordable.cc b/exporters/otlp/recordable.cc index 92a2c78e7e..d38f284577 100644 --- a/exporters/otlp/recordable.cc +++ b/exporters/otlp/recordable.cc @@ -20,6 +20,6 @@ void Recordable::SetName(nostd::string_view name) noexcept { span_.set_name(name.data(), name.size()); } -} // namespace otprotocol +} // namespace otlp } // namespace exporter OPENTELEMETRY_END_NAMESPACE diff --git a/exporters/otlp/recordable.h b/exporters/otlp/recordable.h index 12be1f3f6e..5ea1edf497 100644 --- a/exporters/otlp/recordable.h +++ b/exporters/otlp/recordable.h @@ -1,7 +1,7 @@ #pragma once -#include "opentelemetry/sdk/trace/recordable.h" #include "opentelemetry/proto/trace/v1/trace.pb.h" +#include "opentelemetry/sdk/trace/recordable.h" #include "opentelemetry/version.h" OPENTELEMETRY_BEGIN_NAMESPACE diff --git a/sdk/src/trace/recorder.h b/sdk/src/trace/recorder.h index c2c398d7ce..22730a74cb 100644 --- a/sdk/src/trace/recorder.h +++ b/sdk/src/trace/recorder.h @@ -1,9 +1,9 @@ #pragma once +#include "opentelemetry/sdk/trace/recordable.h" #include "opentelemetry/trace/span_id.h" #include "opentelemetry/trace/trace_id.h" #include "opentelemetry/version.h" -#include "opentelemetry/sdk/trace/recordable.h" OPENTELEMETRY_BEGIN_NAMESPACE namespace sdk From 49c375ff2d3bc6542b105078d79aa631c193c1dc Mon Sep 17 00:00:00 2001 From: Ryan Burn Date: Mon, 6 Apr 2020 12:16:15 -0700 Subject: [PATCH 42/44] Refactor legacy test --- .circleci/config.yml | 2 +- ci/README.md | 2 +- ci/do_ci.sh | 8 ++++---- 3 files changed, 6 insertions(+), 6 deletions(-) diff --git a/.circleci/config.yml b/.circleci/config.yml index 42cf5621ab..4c4557583b 100644 --- a/.circleci/config.yml +++ b/.circleci/config.yml @@ -44,7 +44,7 @@ jobs: - run: ./ci/setup_ci_environment.sh - run: ./ci/install_bazelisk.sh - run: ./ci/install_gcc48.sh - - run: CC=/usr/bin/g++-4.8 ./ci/do_ci.sh bazel.test_api + - run: CC=/usr/bin/g++-4.8 ./ci/do_ci.sh bazel.legacy.test bazel_test: resource_class: xlarge diff --git a/ci/README.md b/ci/README.md index b1629c6b1f..f755d3f54a 100644 --- a/ci/README.md +++ b/ci/README.md @@ -5,8 +5,8 @@ CI tests can be run on docker by invoking the script `./ci/run_docker.sh ./ci/do * `cmake.test`: build cmake targets and run tests. * `cmake.test_example_plugin`: build and test an example OpenTelemetry plugin. * `cmake.exporter.otprotocol.test`: build and test the otprotocol exporter -* `bazel.test_api`: build bazel targets and run tests for the api only. * `bazel.test`: build bazel targets and run tests. +* `bazel.legacy.test`: build bazel targets and run tests for the targets meant to work with older compilers. * `bazel.noexcept`: build bazel targets and run tests with exceptions disabled. * `bazel.asan`: build bazel targets and run tests with AddressSanitizer. * `bazel.tsan`: build bazel targets and run tests with ThreadSanitizer. diff --git a/ci/do_ci.sh b/ci/do_ci.sh index b38bb40e9a..c67c32df0c 100755 --- a/ci/do_ci.sh +++ b/ci/do_ci.sh @@ -64,14 +64,14 @@ EOF make load_plugin_example examples/plugin/load/load_plugin_example ${PLUGIN_DIR}/libexample_plugin.so /dev/null exit 0 -elif [[ "$1" == "bazel.test_api" ]]; then - bazel build $BAZEL_OPTIONS //api/... - bazel test $BAZEL_TEST_OPTIONS //api/... - exit 0 elif [[ "$1" == "bazel.test" ]]; then bazel build $BAZEL_OPTIONS //... bazel test $BAZEL_TEST_OPTIONS //... exit 0 +elif [[ "$1" == "bazel.legacy.test" ]]; then + bazel build $BAZEL_OPTIONS -- //... -//exporters/otlp/... + bazel test $BAZEL_TEST_OPTIONS //... + exit 0 elif [[ "$1" == "bazel.noexcept" ]]; then bazel build --copt=-fno-exceptions $BAZEL_OPTIONS //... bazel test --copt=-fno-exceptions $BAZEL_TEST_OPTIONS //... From ab62b0145f5517027aba35ab148a691330c52e47 Mon Sep 17 00:00:00 2001 From: Ryan Burn Date: Mon, 6 Apr 2020 12:28:22 -0700 Subject: [PATCH 43/44] Fix legacy target --- ci/do_ci.sh | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/ci/do_ci.sh b/ci/do_ci.sh index c67c32df0c..3cefa8b6a9 100755 --- a/ci/do_ci.sh +++ b/ci/do_ci.sh @@ -70,7 +70,7 @@ elif [[ "$1" == "bazel.test" ]]; then exit 0 elif [[ "$1" == "bazel.legacy.test" ]]; then bazel build $BAZEL_OPTIONS -- //... -//exporters/otlp/... - bazel test $BAZEL_TEST_OPTIONS //... + bazel test $BAZEL_TEST_OPTIONS //... -//exporters/otlp/... exit 0 elif [[ "$1" == "bazel.noexcept" ]]; then bazel build --copt=-fno-exceptions $BAZEL_OPTIONS //... From 336d466b2a68e2843c9ab42481a68996243d0aaf Mon Sep 17 00:00:00 2001 From: Ryan Burn Date: Mon, 6 Apr 2020 12:37:21 -0700 Subject: [PATCH 44/44] Fix legacy target --- ci/do_ci.sh | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/ci/do_ci.sh b/ci/do_ci.sh index 3cefa8b6a9..6b3205843b 100755 --- a/ci/do_ci.sh +++ b/ci/do_ci.sh @@ -70,7 +70,7 @@ elif [[ "$1" == "bazel.test" ]]; then exit 0 elif [[ "$1" == "bazel.legacy.test" ]]; then bazel build $BAZEL_OPTIONS -- //... -//exporters/otlp/... - bazel test $BAZEL_TEST_OPTIONS //... -//exporters/otlp/... + bazel test $BAZEL_TEST_OPTIONS -- //... -//exporters/otlp/... exit 0 elif [[ "$1" == "bazel.noexcept" ]]; then bazel build --copt=-fno-exceptions $BAZEL_OPTIONS //...