Skip to content

Commit

Permalink
Revert "code change to resolve the bug #449"
Browse files Browse the repository at this point in the history
This reverts commit 76b2278.
  • Loading branch information
sanketmehta28 committed Jan 19, 2022
1 parent c36c445 commit 76386a8
Show file tree
Hide file tree
Showing 2 changed files with 9 additions and 55 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -20,20 +20,13 @@
from pyramid.tweens import EXCVIEW

import opentelemetry.instrumentation.wsgi as otel_wsgi
from opentelemetry import context
from opentelemetry import context, trace
from opentelemetry.instrumentation.propagators import (
get_global_response_propagator,
)
from opentelemetry.instrumentation.pyramid.version import __version__
from opentelemetry.propagate import extract
from opentelemetry.semconv.trace import SpanAttributes
from opentelemetry.trace import (
INVALID_SPAN,
SpanKind,
get_current_span,
get_tracer,
use_span,
)
from opentelemetry.util._time import _time_ns
from opentelemetry.util.http import get_excluded_urls

Expand Down Expand Up @@ -89,24 +82,19 @@ def _before_traversal(event):

start_time = request_environ.get(_ENVIRON_STARTTIME_KEY)

token = context = None
span_kind = SpanKind.INTERNAL
tracer = get_tracer(__name__, __version__)
token = context.attach(
extract(request_environ, getter=otel_wsgi.wsgi_getter)
)
tracer = trace.get_tracer(__name__, __version__)

if request.matched_route:
span_name = request.matched_route.pattern
else:
span_name = otel_wsgi.get_default_span_name(request_environ)

if get_current_span() is INVALID_SPAN:
context = extract(request_environ, getter=otel_wsgi.wsgi_getter)
token = context.attach(context)
span_kind = SpanKind.SERVER

span = tracer.start_span(
span_name,
context,
kind=span_kind,
kind=trace.SpanKind.SERVER,
start_time=start_time,
)

Expand All @@ -119,12 +107,11 @@ def _before_traversal(event):
for key, value in attributes.items():
span.set_attribute(key, value)

activation = use_span(span, end_on_exit=True)
activation = trace.use_span(span, end_on_exit=True)
activation.__enter__() # pylint: disable=E1101
request_environ[_ENVIRON_ACTIVATION_KEY] = activation
request_environ[_ENVIRON_SPAN_KEY] = span
if token:
request_environ[_ENVIRON_TOKEN] = token
request_environ[_ENVIRON_TOKEN] = token


def trace_tween_factory(handler, registry):
Expand Down Expand Up @@ -193,8 +180,7 @@ def trace_tween(request):
else:
activation.__exit__(None, None, None)

if request.environ.get(_ENVIRON_TOKEN, None) is not None:
context.detach(request.environ.get(_ENVIRON_TOKEN))
context.detach(request.environ.get(_ENVIRON_TOKEN))

return response

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,6 @@
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
Expand Down Expand Up @@ -78,34 +77,3 @@ def test_tween_list(self):
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,
)

0 comments on commit 76386a8

Please sign in to comment.