-
Notifications
You must be signed in to change notification settings - Fork 559
Link api - to add links to span. #342
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
Changes from all commits
8dd7be1
375322f
0513e54
6597099
7ce23b9
fc5b652
92be882
dce3656
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,20 @@ | ||
| #pragma once | ||
|
|
||
| #include "opentelemetry/trace/key_value_iterable.h" | ||
| #include "opentelemetry/trace/span_context.h" | ||
| #include "opentelemetry/version.h" | ||
|
|
||
| OPENTELEMETRY_BEGIN_NAMESPACE | ||
| namespace trace | ||
| { | ||
| class Link | ||
| { | ||
| public: | ||
| // returns the Span Context associated with this Link | ||
| virtual const SpanContext &GetContext() const = 0; | ||
|
|
||
| // returns the attributes associated with link | ||
| virtual const KeyValueIterable &GetAttributes() const = 0; | ||
| }; | ||
| } // namespace trace | ||
| OPENTELEMETRY_END_NAMESPACE |
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,47 @@ | ||
| #pragma once | ||
|
|
||
| #include "opentelemetry/sdk/trace/attribute_utils.h" | ||
| #include "opentelemetry/trace/link.h" | ||
| #include "opentelemetry/version.h" | ||
|
|
||
| #include <memory> | ||
|
|
||
| OPENTELEMETRY_BEGIN_NAMESPACE | ||
| namespace sdk | ||
| { | ||
| namespace trace | ||
| { | ||
| namespace trace_api = opentelemetry::trace; | ||
|
|
||
| class Link final : public trace_api::Link | ||
| { | ||
| public: | ||
| Link(opentelemetry::trace::SpanContext span_context, | ||
| const opentelemetry::trace::KeyValueIterableView< | ||
| std::unordered_map<nostd::string_view, opentelemetry::common::AttributeValue>> | ||
| &attributes) noexcept | ||
| : span_context_(span_context), attribute_map_{attributes} | ||
| {} | ||
|
|
||
| Link(opentelemetry::trace::SpanContext span_context) | ||
| : span_context_(span_context), | ||
| attribute_map_( | ||
| std::unordered_map<nostd::string_view, opentelemetry::common::AttributeValue>()) | ||
| {} | ||
|
|
||
| const trace_api::SpanContext &GetContext() const noexcept override { return span_context_; } | ||
|
|
||
| const trace_api::KeyValueIterable &GetAttributes() const noexcept override | ||
| { | ||
| return attribute_map_; | ||
| } | ||
|
|
||
| private: | ||
| trace_api::SpanContext span_context_; | ||
| const trace_api::KeyValueIterableView< | ||
| std::unordered_map<nostd::string_view, opentelemetry::common::AttributeValue>> | ||
| attribute_map_; | ||
| }; | ||
| } // namespace trace | ||
| } // namespace sdk | ||
| OPENTELEMETRY_END_NAMESPACE |
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -62,13 +62,15 @@ Span::Span(std::shared_ptr<Tracer> &&tracer, | |
| nostd::string_view name, | ||
| const trace_api::KeyValueIterable &attributes, | ||
| const trace_api::StartSpanOptions &options, | ||
| const trace_api::SpanContext &parent_span_context) noexcept | ||
| const trace_api::SpanContext &parent_span_context, | ||
| const nostd::span<std::shared_ptr<trace_api::Link>> &links) noexcept | ||
| : tracer_{std::move(tracer)}, | ||
| processor_{processor}, | ||
| recordable_{processor_->MakeRecordable()}, | ||
| start_steady_time{options.start_steady_time}, | ||
| has_ended_{false} | ||
| { | ||
| (void)options; | ||
|
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Not sure why this is added back, should be removed because it was referenced in line 108 and 109.
Member
Author
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Yeah my bad . Thanks for pointing. Have raised a separate PR #351 as this was now a rework. Please review that. Will close this one. |
||
| if (recordable_ == nullptr) | ||
| { | ||
| return; | ||
|
|
@@ -98,6 +100,11 @@ Span::Span(std::shared_ptr<Tracer> &&tracer, | |
| return true; | ||
| }); | ||
|
|
||
| for (auto &link : links) | ||
| { | ||
| recordable_->AddLink(link->GetContext(), link->GetAttributes()); | ||
| } | ||
|
|
||
| recordable_->SetStartTime(NowOr(options.start_system_time)); | ||
| start_steady_time = NowOr(options.start_steady_time); | ||
| processor_->OnStart(*recordable_); | ||
|
|
@@ -136,6 +143,34 @@ void Span::AddEvent(nostd::string_view name, | |
| (void)attributes; | ||
| } | ||
|
|
||
| void Span::AddLink(const trace_api::Link &link) noexcept | ||
| { | ||
|
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Declare
Member
Author
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Have removed AddLink() as part of separate PR #351 . Please review that. thanks. |
||
| if (recordable_ == nullptr) | ||
| { | ||
| return; | ||
| } | ||
| recordable_->AddLink(link.GetContext(), link.GetAttributes()); | ||
| } | ||
|
|
||
| void Span::AddLink(const trace_api::SpanContext &span_context, | ||
| const trace_api::KeyValueIterable &attributes) noexcept | ||
| { | ||
| if (recordable_ == nullptr) | ||
| { | ||
| return; | ||
| } | ||
| recordable_->AddLink(span_context, attributes); | ||
| } | ||
|
|
||
| void Span::AddLink(const trace_api::SpanContext &span_context) noexcept | ||
| { | ||
| if (recordable_ == nullptr) | ||
| { | ||
| return; | ||
| } | ||
| recordable_->AddLink(span_context); | ||
| } | ||
|
|
||
| void Span::SetStatus(trace_api::CanonicalCode code, nostd::string_view description) noexcept | ||
| { | ||
| std::lock_guard<std::mutex> lock_guard{mu_}; | ||
|
|
||
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Could we go without the dedicated
trace::Linktype altogether? We don't have a type for events, so leaving this out for links would make things more symmetrical.Uh oh!
There was an error while loading. Please reload this page.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Just thinking about scenarios which makes it different from Events, and having
trace::Linkwould be helpful."Links cannot be added after Span creation." With link type, it's helpful to pass sequence of links in
Spanconstructor. Currently we do provideSpan::AddLink()but it needs to be called immediately after the span creation ( probably this needs to be clearly documented).There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I see. What do you think about completely dismissing
AddLinkmethods, and just adding links via StartSpanOptions? This would enforce the spec requirement, I think this is a better and less ambiguous way to add links.trace::Linkas it is now is not useful. An API user couldn't even construct atrace::Link, as it's a pure interface.Uh oh!
There was an error while loading. Please reload this page.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
@pyohannes - I agree on dismissing
AddLinkmethods. But sending links viaStartSpanOptionswon't be feasible, as we need to initialize collection of links. Using std::vector/std::array may break the ABI. Better option would be to have as separate argument inStartSpan:I don't have strong opinion in having dedicated
Linktype, but since link contains attribute pairs , and so the overloading forKeyValueIterablecan be done withinLinktype, instead of adding more overloadedStartSpanmethods. Let me know what you think ?There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I like the suggestion of having this as additional argument to the
StartSpanfunction. I'm not yet sure about the best way to realize this, but let's work towards that!There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
FYI this is what OpenTelemetry Python has https://github.com/open-telemetry/opentelemetry-python/blob/982b667ab7d32de45ed3b9cd6981f37a9e04975b/opentelemetry-sdk/src/opentelemetry/sdk/trace/__init__.py#L701
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
@pyohannes - I have done the changes as separate PR #351 , as this was mostly a rework. Please review that PR. I am closing current PR.