-
Notifications
You must be signed in to change notification settings - Fork 559
Support adding links to span #351
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Merged
Merged
Changes from all commits
Commits
Show all changes
27 commits
Select commit
Hold shift + click to select a range
6844271
links for span - first draft
lalitb 91de78c
remove comments
lalitb be9d08c
add missing file
lalitb 4ba4a0c
fix gcc48 compilation
lalitb 742a64d
Merge branch 'master' into span-links-2
reyang 27cb549
test
lalitb 9ec157e
remove link file
lalitb cee64d9
remove link file
lalitb 9d078ac
fix build
lalitb 2adca9e
merge
lalitb e00f669
fix merge
lalitb e90d18b
fix tests
lalitb e5ce74a
removed unnecessary file
lalitb 85f255b
Delete tracer_LOCAL_1034.cc
lalitb 39c2b37
Delete tracer_BACKUP_1034.cc
lalitb c13c182
Delete tracer_BASE_1034.cc
lalitb 76d7c11
Delete tracer_LOCAL_1799.cc
lalitb 8722685
fix tracer
lalitb 983de1c
fix newline
lalitb 84b755f
fix spancontext kv view
lalitb f3c5133
merge conflict
lalitb 42ad517
format
lalitb 147b92d
fix kv_iterable header
lalitb 49ec04c
fix kv iterable namespace
lalitb 6bdc521
remove un-necessary header
lalitb 693917c
review comments
lalitb 46ddd0c
Merge branch 'master' into span-links-2
reyang File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
34 changes: 34 additions & 0 deletions
34
api/include/opentelemetry/trace/span_context_kv_iterable.h
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,34 @@ | ||
| #pragma once | ||
|
|
||
| #include "opentelemetry/common/attribute_value.h" | ||
| #include "opentelemetry/common/key_value_iterable_view.h" | ||
| #include "opentelemetry/nostd/function_ref.h" | ||
| #include "opentelemetry/version.h" | ||
|
|
||
| OPENTELEMETRY_BEGIN_NAMESPACE | ||
| namespace trace | ||
| { | ||
| /** | ||
| * Supports internal iteration over a collection of SpanContext/key-value pairs. | ||
| */ | ||
| class SpanContextKeyValueIterable | ||
| { | ||
| public: | ||
| virtual ~SpanContextKeyValueIterable() = default; | ||
|
|
||
| /** | ||
| * Iterate over SpanContext/key-value pairs | ||
| * @param callback a callback to invoke for each key-value for each SpanContext. | ||
| * If the callback returns false, the iteration is aborted. | ||
| * @return true if every SpanContext/key-value pair was iterated over | ||
| */ | ||
| virtual bool ForEachKeyValue( | ||
| nostd::function_ref<bool(SpanContext, const opentelemetry::common::KeyValueIterable &)> | ||
| callback) const noexcept = 0; | ||
| /** | ||
| * @return the number of key-value pairs | ||
| */ | ||
| virtual size_t size() const noexcept = 0; | ||
| }; | ||
| } // namespace trace | ||
| OPENTELEMETRY_END_NAMESPACE |
113 changes: 113 additions & 0 deletions
113
api/include/opentelemetry/trace/span_context_kv_iterable_view.h
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,113 @@ | ||
| #pragma once | ||
|
|
||
| #include <iterator> | ||
| #include <type_traits> | ||
| #include <utility> | ||
|
|
||
| #include "opentelemetry/common/key_value_iterable_view.h" | ||
| #include "opentelemetry/nostd/utility.h" | ||
| #include "opentelemetry/trace/span_context_kv_iterable.h" | ||
| #include "opentelemetry/version.h" | ||
|
|
||
| OPENTELEMETRY_BEGIN_NAMESPACE | ||
| namespace trace | ||
| { | ||
| namespace detail | ||
| { | ||
| template <class T> | ||
| inline void take_span_context_kv(SpanContext, common::KeyValueIterableView<T>) | ||
| {} | ||
|
|
||
| template <class T, nostd::enable_if_t<common::detail::is_key_value_iterable<T>::value> * = nullptr> | ||
| inline void take_span_context_kv(SpanContext, T &) | ||
| {} | ||
|
|
||
| inline void take_span_context_kv( | ||
| SpanContext, | ||
| std::initializer_list<std::pair<nostd::string_view, common::AttributeValue>>) | ||
| {} | ||
|
|
||
| template <class T> | ||
| auto is_span_context_kv_iterable_impl(T iterable) | ||
| -> decltype(take_span_context_kv(std::begin(iterable)->first, std::begin(iterable)->second), | ||
| nostd::size(iterable), | ||
| std::true_type{}); | ||
|
|
||
| std::false_type is_span_context_kv_iterable_impl(...); | ||
|
|
||
| template <class T> | ||
| struct is_span_context_kv_iterable | ||
| { | ||
| static const bool value = | ||
| decltype(detail::is_span_context_kv_iterable_impl(std::declval<T>()))::value; | ||
| }; | ||
| } // namespace detail | ||
|
|
||
| template <class T> | ||
| class SpanContextKeyValueIterableView final : public SpanContextKeyValueIterable | ||
| { | ||
| static_assert(detail::is_span_context_kv_iterable<T>::value, | ||
| "Must be a context/key-value iterable"); | ||
|
|
||
| public: | ||
| explicit SpanContextKeyValueIterableView(const T &links) noexcept : container_{&links} {} | ||
|
|
||
| bool ForEachKeyValue( | ||
| nostd::function_ref<bool(SpanContext, const opentelemetry::common::KeyValueIterable &)> | ||
| callback) const noexcept override | ||
| { | ||
| auto iter = std::begin(*container_); | ||
| auto last = std::end(*container_); | ||
| for (; iter != last; ++iter) | ||
| { | ||
| if (!this->do_callback(iter->first, iter->second, callback)) | ||
| { | ||
| return false; | ||
| } | ||
| } | ||
| return true; | ||
| } | ||
|
|
||
| size_t size() const noexcept override { return nostd::size(*container_); } | ||
|
|
||
| private: | ||
| const T *container_; | ||
|
|
||
| bool do_callback( | ||
| SpanContext span_context, | ||
| const common::KeyValueIterable &attributes, | ||
| nostd::function_ref<bool(SpanContext, const opentelemetry::common::KeyValueIterable &)> | ||
| callback) const noexcept | ||
| { | ||
| if (!callback(span_context, attributes)) | ||
| { | ||
| return false; | ||
| } | ||
| return true; | ||
| } | ||
|
|
||
| template <class U, | ||
| nostd::enable_if_t<common::detail::is_key_value_iterable<U>::value> * = nullptr> | ||
| bool do_callback( | ||
| SpanContext span_context, | ||
| const U &attributes, | ||
| nostd::function_ref<bool(SpanContext, const common::KeyValueIterable &)> callback) const | ||
| noexcept | ||
| { | ||
| return do_callback(span_context, common::KeyValueIterableView<U>(attributes), callback); | ||
| } | ||
|
|
||
| bool do_callback( | ||
|
lalitb marked this conversation as resolved.
|
||
| SpanContext span_context, | ||
| std::initializer_list<std::pair<nostd::string_view, common::AttributeValue>> attributes, | ||
| nostd::function_ref<bool(SpanContext, const common::KeyValueIterable &)> callback) const | ||
| noexcept | ||
| { | ||
| return do_callback(span_context, | ||
| nostd::span<const std::pair<nostd::string_view, common::AttributeValue>>{ | ||
| attributes.begin(), attributes.end()}, | ||
| callback); | ||
| } | ||
| }; | ||
| } // namespace trace | ||
| OPENTELEMETRY_END_NAMESPACE | ||
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Uh oh!
There was an error while loading. Please reload this page.