mirror of
https://github.com/open-telemetry/opentelemetry-python-contrib.git
synced 2025-08-02 11:31:52 +08:00

* code change to resolve the bug https://github.com/open-telemetry/opentelemetry-python-contrib/issues/449 * modifying the changelog file to add entry for PR #869 * removing redundent get statement * Conditionally create server spans for falcon (#867) * Making span as internal for falcon in presence of a span in current context * Updating changelog * Fixing lint and generate build failures * Resolving comments: Converting snippet to re-usable function * Fixing build failures * Resolving comments: Creating wrapper for start span to make internal/server span * Rerun docker tests * Resolving comments: Refactoring * Fix Django 1.9 issue preventing use of MIDDLEWARE_CLASSES (#870) * Update CHANGELOG.md * Fix Django 1.9 issue preventing use of MIDDLEWARE_CLASSES Co-authored-by: Srikanth Chekuri <srikanth.chekuri92@gmail.com> * changing the import trace statement to resolve issue with unit test cases Co-authored-by: Ashutosh Goel <39601429+ashu658@users.noreply.github.com> Co-authored-by: Dan <pezzer55@gmail.com> Co-authored-by: Srikanth Chekuri <srikanth.chekuri92@gmail.com> Co-authored-by: Owais Lone <owais@users.noreply.github.com>
112 lines
3.9 KiB
Python
112 lines
3.9 KiB
Python
# Copyright The OpenTelemetry Authors
|
|
#
|
|
# Licensed under the Apache License, Version 2.0 (the "License");
|
|
# you may not use this file except in compliance with the License.
|
|
# You may obtain a copy of the License at
|
|
#
|
|
# http://www.apache.org/licenses/LICENSE-2.0
|
|
#
|
|
# Unless required by applicable law or agreed to in writing, software
|
|
# distributed under the License is distributed on an "AS IS" BASIS,
|
|
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
|
# See the License for the specific language governing permissions and
|
|
# limitations under the License.
|
|
|
|
from pyramid.config import Configurator
|
|
|
|
from opentelemetry.instrumentation.pyramid import PyramidInstrumentor
|
|
from opentelemetry.test.test_base import TestBase
|
|
from opentelemetry.test.wsgitestutil import WsgiTestBase
|
|
from opentelemetry.trace import SpanKind
|
|
|
|
# pylint: disable=import-error
|
|
from .pyramid_base_test import InstrumentationTest
|
|
|
|
|
|
class TestAutomatic(InstrumentationTest, TestBase, WsgiTestBase):
|
|
def setUp(self):
|
|
super().setUp()
|
|
|
|
PyramidInstrumentor().instrument()
|
|
|
|
self.config = Configurator()
|
|
|
|
self._common_initialization(self.config)
|
|
|
|
def tearDown(self):
|
|
super().tearDown()
|
|
with self.disable_logging():
|
|
PyramidInstrumentor().uninstrument()
|
|
|
|
def test_uninstrument(self):
|
|
# pylint: disable=access-member-before-definition
|
|
resp = self.client.get("/hello/123")
|
|
self.assertEqual(200, resp.status_code)
|
|
self.assertEqual([b"Hello: 123"], list(resp.response))
|
|
span_list = self.memory_exporter.get_finished_spans()
|
|
self.assertEqual(len(span_list), 1)
|
|
|
|
PyramidInstrumentor().uninstrument()
|
|
self.config = Configurator()
|
|
|
|
self._common_initialization(self.config)
|
|
|
|
resp = self.client.get("/hello/123")
|
|
self.assertEqual(200, resp.status_code)
|
|
self.assertEqual([b"Hello: 123"], list(resp.response))
|
|
span_list = self.memory_exporter.get_finished_spans()
|
|
self.assertEqual(len(span_list), 1)
|
|
|
|
def test_tween_list(self):
|
|
tween_list = "pyramid.tweens.excview_tween_factory"
|
|
config = Configurator(settings={"pyramid.tweens": tween_list})
|
|
self._common_initialization(config)
|
|
resp = self.client.get("/hello/123")
|
|
self.assertEqual(200, resp.status_code)
|
|
self.assertEqual([b"Hello: 123"], list(resp.response))
|
|
span_list = self.memory_exporter.get_finished_spans()
|
|
self.assertEqual(len(span_list), 1)
|
|
|
|
PyramidInstrumentor().uninstrument()
|
|
|
|
self.config = Configurator()
|
|
|
|
self._common_initialization(self.config)
|
|
|
|
resp = self.client.get("/hello/123")
|
|
self.assertEqual(200, resp.status_code)
|
|
self.assertEqual([b"Hello: 123"], list(resp.response))
|
|
span_list = self.memory_exporter.get_finished_spans()
|
|
self.assertEqual(len(span_list), 1)
|
|
|
|
|
|
class TestWrappedWithOtherFramework(
|
|
InstrumentationTest, TestBase, WsgiTestBase
|
|
):
|
|
def setUp(self):
|
|
super().setUp()
|
|
PyramidInstrumentor().instrument()
|
|
self.config = Configurator()
|
|
self._common_initialization(self.config)
|
|
|
|
def tearDown(self) -> None:
|
|
super().tearDown()
|
|
with self.disable_logging():
|
|
PyramidInstrumentor().uninstrument()
|
|
|
|
def test_with_existing_span(self):
|
|
tracer_provider, _ = self.create_tracer_provider()
|
|
tracer = tracer_provider.get_tracer(__name__)
|
|
|
|
with tracer.start_as_current_span(
|
|
"test", kind=SpanKind.SERVER
|
|
) as parent_span:
|
|
resp = self.client.get("/hello/123")
|
|
self.assertEqual(200, resp.status_code)
|
|
span_list = self.memory_exporter.get_finished_spans()
|
|
self.assertEqual(SpanKind.INTERNAL, span_list[0].kind)
|
|
self.assertEqual(
|
|
parent_span.get_span_context().span_id,
|
|
span_list[0].parent.span_id,
|
|
)
|