Skip to content

Using InMemorySpanExporter for wsgi/flask tests #306

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 9 commits into from
Jan 7, 2020

Conversation

codeboten
Copy link
Contributor

Fixes #303

This PR will have conflicts, I'll resolve them before moving this PR from draft.

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

@codecov-io
Copy link

codecov-io commented Nov 26, 2019

Codecov Report

Merging #306 into master will increase coverage by 0.21%.
The diff coverage is 93.68%.

Impacted file tree graph

@@            Coverage Diff             @@
##           master     #306      +/-   ##
==========================================
+ Coverage   84.51%   84.73%   +0.21%     
==========================================
  Files          33       35       +2     
  Lines        1666     1716      +50     
  Branches      197      200       +3     
==========================================
+ Hits         1408     1454      +46     
- Misses        201      204       +3     
- Partials       57       58       +1
Impacted Files Coverage Δ
...sdk/src/opentelemetry/sdk/trace/export/__init__.py 86.79% <ø> (ø) ⬆️
...etry-sdk/src/opentelemetry/sdk/metrics/__init__.py 99.05% <ø> (ø) ⬆️
opentelemetry-api/src/opentelemetry/util/loader.py 81.25% <ø> (ø) ⬆️
...ntelemetry-api/src/opentelemetry/trace/sampling.py 85.1% <ø> (ø) ⬆️
...try-ext-wsgi/src/opentelemetry/ext/wsgi/version.py 100% <100%> (ø) ⬆️
.../src/opentelemetry/ext/opentracing_shim/version.py 100% <100%> (ø)
...ry-ext-wsgi/src/opentelemetry/ext/wsgi/__init__.py 68.18% <100%> (ø) ⬆️
...src/opentelemetry/ext/opentracing_shim/__init__.py 95.9% <100%> (+0.03%) ⬆️
...sts/src/opentelemetry/ext/http_requests/version.py 100% <100%> (ø)
...pentelemetry-sdk/src/opentelemetry/sdk/__init__.py 100% <100%> (ø) ⬆️
... and 7 more

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 939900b...7f03b24. Read the comment docs.

@codeboten codeboten marked this pull request as ready for review December 10, 2019 00:22
@codeboten codeboten requested a review from a team December 10, 2019 00:22
"http.status_code": 200,
"http.status_text": "OK",
}
expected_attrs = BoundedDict.from_map(
Copy link
Member

Choose a reason for hiding this comment

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

For expectations, I would not use BoundedDict because attributes could get dropped silently.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Fixed!

@codeboten
Copy link
Contributor Author

Merge conflicts have been resolved. Ready for reviews

@codeboten codeboten added the needs reviewers PRs with this label are ready for review and needs people to review to move forward. label Dec 16, 2019
spec_set=True,
return_value=self.span,
@classmethod
def setUpClass(cls):
Copy link
Member

Choose a reason for hiding this comment

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

We'll need to add a tearDownClass that undoes this (probably using importlib.reload). Otherwise, as soon as we have a second unit test that uses the same pattern, we'll get problems. See also the loader tests in the API package.

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 pointer, I did not know about the reload method, will updated the test.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Updated


self.memory_exporter = InMemorySpanExporter()
span_processor = export.SimpleExportSpanProcessor(self.memory_exporter)
tracer_source.add_span_processor(span_processor)
Copy link
Member

Choose a reason for hiding this comment

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

tracer_source would be shared by all test cases so you will be adding new span processor for every test case executed, maybe using a single InMemorySpanExporter and just call clear method during setup?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Updated the test to set a single in-memory span exporter on class setup and clear it each time.

Copy link
Member

@toumorokoshi toumorokoshi left a comment

Choose a reason for hiding this comment

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

I agree with @Oberon00 that there should be some way to undo the trace api tracer. But aside from that, looks great!

@@ -49,100 +40,72 @@ def hello_endpoint(helloid):
self.client = Client(self.app, BaseResponse)

def test_simple(self):
expected_attrs = {
Copy link
Member

Choose a reason for hiding this comment

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

some of these expected_attrs looks pretty common. could they be pooled into some common constructor or factory?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

updated to use a method with a dict argument for anything that the test needs to override

Alex Boten added 4 commits December 20, 2019 09:36
Signed-off-by: Alex Boten <[email protected]>
Signed-off-by: Alex Boten <[email protected]>
Copy link
Member

@toumorokoshi toumorokoshi left a comment

Choose a reason for hiding this comment

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

Looks great! Thanks for addressing.

@toumorokoshi toumorokoshi merged commit 8a6b408 into open-telemetry:master Jan 7, 2020
@codeboten codeboten deleted the codeboten/issue_303 branch October 9, 2020 18:50
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
needs reviewers PRs with this label are ready for review and needs people to review to move forward.
Projects
None yet
Development

Successfully merging this pull request may close these issues.

Switch unit tests from unittest.mock to SDK & in-memory exporter
5 participants