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

Ensure the API returns right value types #307

Merged
merged 10 commits into from
Dec 6, 2019

Conversation

codeboten
Copy link
Contributor

@codeboten codeboten commented Nov 27, 2019

Fixes #142

Enabling --strict mode for mypy. Added a test in the sdk and the same test in the api to test the different behaviours between the Tracer, Span and Metric classes.

Signed-off-by: Alex Boten aboten@lightstep.com

Signed-off-by: Alex Boten <aboten@lightstep.com>
@codeboten codeboten added the WIP Work in progress label Nov 27, 2019
Alex Boten added 2 commits November 28, 2019 10:41
@codecov-io
Copy link

codecov-io commented Nov 28, 2019

Codecov Report

Merging #307 into master will decrease coverage by 0.16%.
The diff coverage is 100%.

Impacted file tree graph

@@            Coverage Diff             @@
##           master     #307      +/-   ##
==========================================
- Coverage   86.05%   85.88%   -0.17%     
==========================================
  Files          33       33              
  Lines        1628     1630       +2     
  Branches      182      182              
==========================================
- Hits         1401     1400       -1     
- Misses        181      182       +1     
- Partials       46       48       +2
Impacted Files Coverage Δ
...elemetry-api/src/opentelemetry/metrics/__init__.py 86% <ø> (ø) ⬆️
...ntelemetry-api/src/opentelemetry/trace/sampling.py 85.1% <ø> (ø) ⬆️
...etry-sdk/src/opentelemetry/sdk/metrics/__init__.py 99.05% <ø> (ø) ⬆️
...emetry-sdk/src/opentelemetry/sdk/trace/__init__.py 89.94% <100%> (ø) ⬆️
...ntelemetry-api/src/opentelemetry/trace/__init__.py 83.73% <100%> (-2.22%) ⬇️

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 15991af...a5ae35d. Read the comment docs.

@codeboten codeboten marked this pull request as ready for review November 28, 2019 20:17
@codeboten codeboten removed the WIP Work in progress label Nov 28, 2019
@Oberon00
Copy link
Member

Oberon00 commented Dec 3, 2019

I think the --strict flag should already be covered by mypy.ini mostly, and the remainder was deliberate. However, it seems you really got it working using --strict, which seems nice. Maybe we can remove (parts of) mypy.ini now? Or, remove --strict and add the missing flags to mypy.ini (that way editors could pick the options up easier).

Alex Boten added 2 commits December 3, 2019 09:35
@codeboten
Copy link
Contributor Author

Good idea! I added the remainder of the strict flags into mypy.ini.

@lzchen
Copy link
Contributor

lzchen commented Dec 3, 2019

Is assigning default values for every argument part of the "strictness"?

@codeboten
Copy link
Contributor Author

It is

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.

Two blocking comments, but this looks good otherwise. It's encouraging that you got --strict to work with so few changes.

Something to think about: since type checks aren't enforced at run time, using non-null default values for args that can't meaningfully be null means we either have to (1) explicitly handle nulls or (2) decide not to handle them and leave it up to the user to deal with the inevitable TypeErrors, AttributeErrors and etc. This isn't to say this isn't the right approach, just that we have to deal with a different set of problems than we do for null default values.

@@ -145,7 +145,7 @@ class SpanKind(enum.Enum):
class Span:
"""A span represents a single operation within a trace."""

def end(self, end_time: int = None) -> None:
def end(self, end_time: int = 0) -> None:
Copy link
Member

Choose a reason for hiding this comment

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

0 already has a well-defined meaning: even if we don't expect users to want to end spans on the unix epoch, I don't think the API should prohibit it. Optional/none seems like a better default here.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Good call. Updated to Optional[int], I updated the SDK as well

@@ -174,7 +176,7 @@ def add_event(
self,
name: str,
attributes: types.Attributes = None,
timestamp: int = None,
timestamp: int = 0,
Copy link
Member

Choose a reason for hiding this comment

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

Same comment about the epoch here.

from opentelemetry import metrics, trace


class TestAppWithAPI(unittest.TestCase):
Copy link
Member

Choose a reason for hiding this comment

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

This test looks great, but might be hard to understand out of context. An explanation in the test or module docstring and reference to the other test in each file would help, especially since we'll need to keep these in sync with each other.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Added a comment to help clarify it.

Copy link
Member

Choose a reason for hiding this comment

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

I'd prefer having that comment as the docstring for the test class instead of the test module, since I routinely skip until after the import statements when reading a file. But that's just my personal preference.

Alex Boten added 4 commits December 4, 2019 16:39
Signed-off-by: Alex Boten <aboten@lightstep.com>
Signed-off-by: Alex Boten <aboten@lightstep.com>
Signed-off-by: Alex Boten <aboten@lightstep.com>
Copy link
Member

@Oberon00 Oberon00 left a comment

Choose a reason for hiding this comment

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

Looks basically good to me, but I find the test class names confusing.

from opentelemetry import metrics, trace


class TestAppWithAPI(unittest.TestCase):
Copy link
Member

Choose a reason for hiding this comment

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

I'd prefer having that comment as the docstring for the test class instead of the test module, since I routinely skip until after the import statements when reading a file. But that's just my personal preference.

from opentelemetry import metrics, trace


class TestAppWithAPI(unittest.TestCase):
Copy link
Member

Choose a reason for hiding this comment

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

Why is this called TestAppWithAPI? From that name I had expected it to run the example app (which would actually be nice too). I suggest the name TestAPIOnlyImplementation.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Thanks for the suggestion, it's much clearer. I've renamed the files to test_implementation as well.

from opentelemetry.trace import INVALID_SPAN, INVALID_SPAN_CONTEXT


class TestAppWithSDK(unittest.TestCase):
Copy link
Member

Choose a reason for hiding this comment

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

Now I'm confused. Why is there App in the name again? And aren't these already covered by other unit tests?

Signed-off-by: Alex Boten <aboten@lightstep.com>
https://github.com/open-telemetry/opentelemetry-python/issues/142
"""

def test_tracer(self):
Copy link
Member

Choose a reason for hiding this comment

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

nice!

@c24t c24t merged commit cfecca1 into open-telemetry:master Dec 6, 2019
@codeboten codeboten deleted the issue-142 branch October 6, 2020 15:34
srikanthccv pushed a commit to srikanthccv/opentelemetry-python that referenced this pull request Nov 1, 2020
closes open-telemetry#307

Signed-off-by: Olivier Albertini <olivier.albertini@montreal.ca>
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.

Ensure that API tracer returns the right value types
6 participants