-
Notifications
You must be signed in to change notification settings - Fork 864
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
Changes from 5 commits
39df92d
939900b
7c99d6f
30d755f
cdc0336
f328909
3bfa984
58c7c03
7f03b24
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 |
|---|---|---|
| @@ -1,32 +1,28 @@ | ||
| import io | ||
| import unittest | ||
| import unittest.mock as mock | ||
| import wsgiref.util as wsgiref_util | ||
|
|
||
| from opentelemetry import trace as trace_api | ||
| from opentelemetry.sdk.trace import TracerSource, export | ||
| from opentelemetry.sdk.trace.export.in_memory_span_exporter import ( | ||
| InMemorySpanExporter, | ||
| ) | ||
|
|
||
|
|
||
| class WsgiTestBase(unittest.TestCase): | ||
| def setUp(self): | ||
| self.span = mock.create_autospec(trace_api.Span, spec_set=True) | ||
| tracer = trace_api.Tracer() | ||
| self.get_tracer_patcher = mock.patch.object( | ||
| trace_api.TracerSource, | ||
| "get_tracer", | ||
| autospec=True, | ||
| spec_set=True, | ||
| return_value=tracer, | ||
| ) | ||
| self.get_tracer_patcher.start() | ||
|
|
||
| self.start_span_patcher = mock.patch.object( | ||
| tracer, | ||
| "start_span", | ||
| autospec=True, | ||
| spec_set=True, | ||
| return_value=self.span, | ||
| @classmethod | ||
| def setUpClass(cls): | ||
|
Member
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. We'll need to add a
Contributor
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. Thanks for the pointer, I did not know about the reload method, will updated the test.
Contributor
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. Updated |
||
| trace_api.set_preferred_tracer_source_implementation( | ||
| lambda T: TracerSource() | ||
| ) | ||
| self.start_span = self.start_span_patcher.start() | ||
|
|
||
| def setUp(self): | ||
| tracer_source = trace_api.tracer_source() | ||
|
|
||
| self.memory_exporter = InMemorySpanExporter() | ||
| span_processor = export.SimpleExportSpanProcessor(self.memory_exporter) | ||
| tracer_source.add_span_processor(span_processor) | ||
|
Member
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. 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?
Contributor
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. Updated the test to set a single in-memory span exporter on class setup and clear it each time. |
||
|
|
||
| self.write_buffer = io.BytesIO() | ||
| self.write = self.write_buffer.write | ||
|
|
||
|
|
@@ -37,10 +33,6 @@ def setUp(self): | |
| self.response_headers = None | ||
| self.exc_info = None | ||
|
|
||
| def tearDown(self): | ||
| self.get_tracer_patcher.stop() | ||
| self.start_span_patcher.stop() | ||
|
|
||
| def start_response(self, status, response_headers, exc_info=None): | ||
| self.status = status | ||
| self.response_headers = response_headers | ||
|
|
||
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.
some of these expected_attrs looks pretty common. could they be pooled into some common constructor or factory?
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.
updated to use a method with a dict argument for anything that the test needs to override