Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Removing add_link and add_lazy_link from api/sdk #259

Merged
merged 15 commits into from
Nov 16, 2019

Conversation

codeboten
Copy link
Contributor

Definitely still a work in progress. Removing add_link and add_lazy_link from api/sdk. From the open-telemetry/oteps#28, it appeared the only place where it made sense to add links was in the start_span, create_span and start_as_current_span if we want to be able to add them to the Span before it's constructed. Would love some feedback on this.

Still need to address the other part of the OTEP regarding Attributes

Signed-off-by: Alex Boten [email protected]

@@ -1,6 +1,6 @@
import time

from opentelemetry import trace
from opentelemetry import trace, trace_api

Choose a reason for hiding this comment

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

trace_api doesn't exist on opentelemetry, just trace will work fine.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

i see, in other places it gets imported as trace_api. Fixed.

Copy link
Member

@c24t c24t left a comment

Choose a reason for hiding this comment

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

LGTM besides the mutable default. This makes the API for span creation a bit uglier, but there's no obvious nicer solution following the OTEP.

@@ -76,11 +76,15 @@
class Link:
"""A link to a `Span`."""

empty_attributes = {} # type: typing.Dict[str, types.AttributeValue]
Copy link
Member

Choose a reason for hiding this comment

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

This can't be mutable since we expose it below, changing one (initially empty-attributed) link's attributes would affect others'.

Copy link
Member

@c24t c24t left a comment

Choose a reason for hiding this comment

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

LGTM!

opentelemetry-api/src/opentelemetry/trace/__init__.py Outdated Show resolved Hide resolved
Signed-off-by: Alex Boten <[email protected]>
@codecov-io
Copy link

codecov-io commented Nov 7, 2019

Codecov Report

Merging #259 into master will decrease coverage by 0.08%.
The diff coverage is 78.57%.

Impacted file tree graph

@@            Coverage Diff             @@
##           master     #259      +/-   ##
==========================================
- Coverage   85.74%   85.65%   -0.09%     
==========================================
  Files          33       33              
  Lines        1620     1610      -10     
  Branches      183      180       -3     
==========================================
- Hits         1389     1379      -10     
- Misses        184      185       +1     
+ Partials       47       46       -1
Impacted Files Coverage Δ
...ntelemetry-api/src/opentelemetry/trace/__init__.py 86.29% <0%> (-1.62%) ⬇️
...ntelemetry-api/src/opentelemetry/trace/sampling.py 85.1% <100%> (ø) ⬆️
...emetry-sdk/src/opentelemetry/sdk/trace/__init__.py 89.11% <100%> (+0.33%) ⬆️
...src/opentelemetry/ext/opentracing_shim/__init__.py 95.96% <100%> (+0.06%) ⬆️

Continue to review full report at Codecov.

Legend - Click here to learn more
Δ = absolute <relative> (impact), ø = not affected, ? = missing data
Powered by Codecov. Last update fcdd9fe...4e0c328. Read the comment docs.

@@ -444,6 +431,7 @@ def start_span(
parent: The span's parent. Defaults to the current span.
kind: The span's kind (relationship to parent). Note that is
meaningful even if there is no parent.
links: The span's links, to be used in sampling decisions
Copy link
Member

Choose a reason for hiding this comment

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

I don't think we should call out sampling here. This is merely a detail, mostly the links will be used to, well, have the span linked to other spans, not to influence sampling.

@@ -130,7 +130,7 @@ def __init__(
resource: None = None, # TODO
attributes: types.Attributes = None, # TODO
events: Sequence[trace_api.Event] = None, # TODO
links: Sequence[trace_api.Link] = None, # TODO
links: Sequence[trace_api.Link] = None,
Copy link
Member

Choose a reason for hiding this comment

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

Since start_span uses () as a default instead of None, maybe use () here too? Also we have a Sequence not an Optional[Sequence] anyway.


links = None
Copy link
Member

Choose a reason for hiding this comment

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

Suggested change
links = None
links = ()

An empty tuple should be a singleton constant, so no performance overhead over using None here.

Alex Boten added 3 commits November 8, 2019 13:33
- updating comments
- updating default value of links for Span constructor

Signed-off-by: Alex Boten <[email protected]>
- adding `attributes` as optional parameter to `create_span`, `start_as_current_span`, `start_span`
- adding `attributes` as optional parameter to Sampler's `should_sample` to allow them to be considered during sampling decision

Signed-off-by: Alex Boten <[email protected]>
@codeboten codeboten changed the title [WIP] Removing add_link and add_lazy_link from api/sdk Removing add_link and add_lazy_link from api/sdk Nov 12, 2019
@codeboten
Copy link
Contributor Author

Added attributes as optional parameter to create_span, start_as_current_span, start_span. This should address the second portion of #132

@codeboten codeboten added api Affects the API package. and removed WIP Work in progress labels Nov 12, 2019
Signed-off-by: Alex Boten <[email protected]>
if references:
links = []
Copy link
Member

Choose a reason for hiding this comment

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

Curious, is there a strong reason to create links as a tuple and then change to list upon modification?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

There is not. Cleaned it up

@@ -416,6 +402,8 @@ def start_span(
name: str,
parent: ParentSpan = CURRENT_SPAN,
kind: SpanKind = SpanKind.INTERNAL,
attributes: typing.Optional[types.Attributes] = None,
links: typing.Sequence[Link] = (),
Copy link
Member

Choose a reason for hiding this comment

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

Do we intend to support iterator (delayed expansion)? This might give perf gain if the span is not sampled (so we don't have to evaluate the iterator at all).

Copy link
Member

Choose a reason for hiding this comment

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

I think someone should read up on the motivation behind lazy links. I think lazily evaluated iterables may be a good fit for Python.

Copy link
Member

Choose a reason for hiding this comment

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

This is a good point. If we're not using __getitem__ -- and especially if we might not read the sequence at all, -- we should generally prefer Iterator over Sequence.

Copy link
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, I've left some non-blocking suggestions.

@codeboten
Copy link
Contributor Author

Closes #132

Signed-off-by: Alex Boten <[email protected]>
Copy link
Member

@c24t c24t left a comment

Choose a reason for hiding this comment

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

LGTM, but FWIW the API changes only really make sense in the context of the new sampling API. It's not clear why we'd prevent users from adding links after the span is created unless links were involved in the sampling decision, which they're not right now.

@c24t c24t merged commit 30a1bb8 into open-telemetry:master Nov 16, 2019
@codeboten codeboten deleted the otep-0006-implementation branch October 9, 2020 18:50
srikanthccv pushed a commit to srikanthccv/opentelemetry-python that referenced this pull request Nov 1, 2020
* feat: metrics API revision based on specs and rfcs

* fix: document default values
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
api Affects the API package.
Projects
None yet
Development

Successfully merging this pull request may close these issues.

6 participants