Skip to content

Link api - to add links to span.#342

Closed
lalitb wants to merge 8 commits into
open-telemetry:masterfrom
lalitb:link-api
Closed

Link api - to add links to span.#342
lalitb wants to merge 8 commits into
open-telemetry:masterfrom
lalitb:link-api

Conversation

@lalitb
Copy link
Copy Markdown
Member

@lalitb lalitb commented Sep 28, 2020

As per the specification : https://github.com/open-telemetry/opentelemetry-specification/blob/master/specification/trace/api.md#add-links.

TBD -> Need to fix test coverage, although it's passing in forked repo PR, it seems to fail here.

@lalitb lalitb requested a review from a team September 28, 2020 20:21
@codecov
Copy link
Copy Markdown

codecov Bot commented Sep 28, 2020

Codecov Report

Merging #342 into master will decrease coverage by 0.18%.
The diff coverage is 70.58%.

Impacted file tree graph

@@            Coverage Diff             @@
##           master     #342      +/-   ##
==========================================
- Coverage   94.57%   94.39%   -0.19%     
==========================================
  Files         150      150              
  Lines        6768     6815      +47     
==========================================
+ Hits         6401     6433      +32     
- Misses        367      382      +15     
Impacted Files Coverage Δ
api/include/opentelemetry/trace/default_span.h 16.66% <0.00%> (-4.77%) ⬇️
...de/opentelemetry/ext/zpages/threadsafe_span_data.h 96.87% <ø> (ø)
sdk/src/trace/span.h 100.00% <ø> (ø)
sdk/src/trace/span.cc 74.72% <33.33%> (-8.40%) ⬇️
api/include/opentelemetry/trace/noop.h 83.33% <75.00%> (-1.29%) ⬇️
api/include/opentelemetry/trace/span.h 100.00% <100.00%> (ø)
api/test/trace/noop_test.cc 100.00% <100.00%> (ø)
sdk/include/opentelemetry/sdk/trace/recordable.h 100.00% <100.00%> (ø)
sdk/include/opentelemetry/sdk/trace/span_data.h 100.00% <100.00%> (ø)
sdk/src/trace/tracer.cc 72.72% <100.00%> (+1.75%) ⬆️
... and 1 more

Copy link
Copy Markdown
Member

@reyang reyang left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

LGTM.

* @param attributes Link attributes
*/

virtual void AddLink(const trace::Link &link) noexcept = 0;
Copy link
Copy Markdown
Contributor

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::Link type altogether? We don't have a type for events, so leaving this out for links would make things more symmetrical.

Copy link
Copy Markdown
Member Author

@lalitb lalitb Sep 29, 2020

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::Link would be helpful.

  • Creating a link, and then associating it with multiple spans. It would be helpful to have link as an entity in that case.
  • Link should be associated with the Span during it's creation, and not afterwards. As per the specification
    "Links cannot be added after Span creation." With link type, it's helpful to pass sequence of links in Span constructor. Currently we do provide Span::AddLink() but it needs to be called immediately after the span creation ( probably this needs to be clearly documented).

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Links cannot be added after Span creation.

I see. What do you think about completely dismissing AddLink methods, 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::Link as it is now is not useful. An API user couldn't even construct a trace::Link, as it's a pure interface.

Copy link
Copy Markdown
Member Author

@lalitb lalitb Sep 30, 2020

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 AddLink methods. But sending links via StartSpanOptions won'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 in StartSpan :

 nostd::shared_ptr<Span> StartSpan(nostd::string_view /*name*/,
                                    const KeyValueIterable & /*attributes*/,
                                    const StartSpanOptions & /*options*/,
                                    const nostd::span<nostd::shared_ptr<Link>>& /*links*/) noexcept override

I don't have strong opinion in having dedicated Link type, but since link contains attribute pairs , and so the overloading for KeyValueIterable can be done within Link type, instead of adding more overloaded StartSpan methods. Let me know what you think ?

Copy link
Copy Markdown
Contributor

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 StartSpan function. I'm not yet sure about the best way to realize this, but let's work towards that!

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Copy link
Copy Markdown
Member Author

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.

Comment thread api/include/opentelemetry/trace/span.h
Comment thread api/include/opentelemetry/trace/span.h Outdated
Comment thread api/test/trace/noop_test.cc
@pyohannes
Copy link
Copy Markdown
Contributor

Closes #319.

@pyohannes pyohannes linked an issue Sep 29, 2020 that may be closed by this pull request
Comment thread sdk/src/trace/span.cc
start_steady_time{options.start_steady_time},
has_ended_{false}
{
(void)options;
Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The 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.

Copy link
Copy Markdown
Member Author

Choose a reason for hiding this comment

The 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.

Comment thread sdk/src/trace/span.cc
}

void Span::AddLink(const trace_api::Link &link) noexcept
{
Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Declare lock_guard(mf_) to make sure it is thread-safe?

Copy link
Copy Markdown
Member Author

Choose a reason for hiding this comment

The 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.

@jlisee
Copy link
Copy Markdown

jlisee commented May 18, 2022

Was this supposed to be closed or merged? I cannot find a way to add links to Spans otherwise.

@lalitb
Copy link
Copy Markdown
Member Author

lalitb commented May 18, 2022

Was this supposed to be closed or merged? I cannot find a way to add links to Spans otherwise.

You can add link while creating the span:
https://github.com/open-telemetry/opentelemetry-cpp/blob/main/api/include/opentelemetry/trace/tracer.h#L42

Specs doesn't allow adding links once span is created.

GerHobbelt pushed a commit to GerHobbelt/opentelemetry-cpp that referenced this pull request Aug 31, 2025
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Add functionality to create links on spans

5 participants