From 913ae1f40f89645be7046867a35c8a0f88925c79 Mon Sep 17 00:00:00 2001 From: Leighton Chen Date: Wed, 28 Oct 2020 17:28:58 -0400 Subject: [PATCH 1/3] Change status codes from grpc status codes, remove setting status in instrumentations except on ERROR (#1282) --- .../src/opentelemetry/instrumentation/wsgi/__init__.py | 10 +++++----- .../tests/test_wsgi_middleware.py | 4 ++-- 2 files changed, 7 insertions(+), 7 deletions(-) diff --git a/instrumentation/opentelemetry-instrumentation-wsgi/src/opentelemetry/instrumentation/wsgi/__init__.py b/instrumentation/opentelemetry-instrumentation-wsgi/src/opentelemetry/instrumentation/wsgi/__init__.py index 56c8b755c..62eef4325 100644 --- a/instrumentation/opentelemetry-instrumentation-wsgi/src/opentelemetry/instrumentation/wsgi/__init__.py +++ b/instrumentation/opentelemetry-instrumentation-wsgi/src/opentelemetry/instrumentation/wsgi/__init__.py @@ -59,9 +59,9 @@ import typing import wsgiref.util as wsgiref_util from opentelemetry import context, propagators, trace -from opentelemetry.instrumentation.utils import http_status_to_canonical_code +from opentelemetry.instrumentation.utils import http_status_to_status_code from opentelemetry.instrumentation.wsgi.version import __version__ -from opentelemetry.trace.status import Status, StatusCanonicalCode +from opentelemetry.trace.status import Status, StatusCode _HTTP_VERSION_PREFIX = "HTTP/" @@ -146,13 +146,13 @@ def add_response_attributes( except ValueError: span.set_status( Status( - StatusCanonicalCode.UNKNOWN, + StatusCode.ERROR, "Non-integer HTTP status: " + repr(status_code), ) ) else: span.set_attribute("http.status_code", status_code) - span.set_status(Status(http_status_to_canonical_code(status_code))) + span.set_status(Status(http_status_to_status_code(status_code))) def get_default_span_name(environ): @@ -217,7 +217,7 @@ class OpenTelemetryMiddleware: ) except Exception as ex: if span.is_recording(): - span.set_status(Status(StatusCanonicalCode.INTERNAL, str(ex))) + span.set_status(Status(StatusCode.ERROR, str(ex))) span.end() context.detach(token) raise diff --git a/instrumentation/opentelemetry-instrumentation-wsgi/tests/test_wsgi_middleware.py b/instrumentation/opentelemetry-instrumentation-wsgi/tests/test_wsgi_middleware.py index baab50d96..144b4cf06 100644 --- a/instrumentation/opentelemetry-instrumentation-wsgi/tests/test_wsgi_middleware.py +++ b/instrumentation/opentelemetry-instrumentation-wsgi/tests/test_wsgi_middleware.py @@ -21,7 +21,7 @@ from urllib.parse import urlsplit import opentelemetry.instrumentation.wsgi as otel_wsgi from opentelemetry import trace as trace_api from opentelemetry.test.wsgitestutil import WsgiTestBase -from opentelemetry.trace.status import StatusCanonicalCode +from opentelemetry.trace.status import StatusCode class Response: @@ -177,7 +177,7 @@ class TestWsgiApplication(WsgiTestBase): span_list = self.memory_exporter.get_finished_spans() self.assertEqual(len(span_list), 1) self.assertEqual( - span_list[0].status.canonical_code, StatusCanonicalCode.INTERNAL, + span_list[0].status.status_code, StatusCode.ERROR, ) def test_override_span_name(self): From 82c0ae94c6c5a3a5fb027c4259c0077b309907fd Mon Sep 17 00:00:00 2001 From: Prajilesh N Date: Mon, 2 Nov 2020 09:42:47 +0530 Subject: [PATCH 2/3] Converted TextMap propagator getter to a class and added keys method (#1196) Co-authored-by: alrex --- .../instrumentation/wsgi/__init__.py | 39 ++++++++++++------- 1 file changed, 24 insertions(+), 15 deletions(-) diff --git a/instrumentation/opentelemetry-instrumentation-wsgi/src/opentelemetry/instrumentation/wsgi/__init__.py b/instrumentation/opentelemetry-instrumentation-wsgi/src/opentelemetry/instrumentation/wsgi/__init__.py index 62eef4325..e1ef92c6b 100644 --- a/instrumentation/opentelemetry-instrumentation-wsgi/src/opentelemetry/instrumentation/wsgi/__init__.py +++ b/instrumentation/opentelemetry-instrumentation-wsgi/src/opentelemetry/instrumentation/wsgi/__init__.py @@ -61,24 +61,35 @@ import wsgiref.util as wsgiref_util from opentelemetry import context, propagators, trace from opentelemetry.instrumentation.utils import http_status_to_status_code from opentelemetry.instrumentation.wsgi.version import __version__ +from opentelemetry.trace.propagation.textmap import DictGetter from opentelemetry.trace.status import Status, StatusCode _HTTP_VERSION_PREFIX = "HTTP/" -def get_header_from_environ( - environ: dict, header_name: str -) -> typing.List[str]: - """Retrieve a HTTP header value from the PEP3333-conforming WSGI environ. +class CarrierGetter(DictGetter): + def get(self, carrier: dict, key: str) -> typing.List[str]: + """Getter implementation to retrieve a HTTP header value from the + PEP3333-conforming WSGI environ - Returns: - A list with a single string with the header value if it exists, else an empty list. - """ - environ_key = "HTTP_" + header_name.upper().replace("-", "_") - value = environ.get(environ_key) - if value is not None: - return [value] - return [] + Args: + carrier: WSGI environ object + key: header name in environ object + Returns: + A list with a single string with the header value if it exists, + else an empty list. + """ + environ_key = "HTTP_" + key.upper().replace("-", "_") + value = carrier.get(environ_key) + if value is not None: + return [value] + return [] + + def keys(self, carrier): + return [] + + +carrier_getter = CarrierGetter() def setifnotnone(dic, key, value): @@ -195,9 +206,7 @@ class OpenTelemetryMiddleware: start_response: The WSGI start_response callable. """ - token = context.attach( - propagators.extract(get_header_from_environ, environ) - ) + token = context.attach(propagators.extract(carrier_getter, environ)) span_name = self.name_callback(environ) span = self.tracer.start_span( From 4e9f2e1e16ebfe0808c2acfea65ab018ec3b24ec Mon Sep 17 00:00:00 2001 From: alrex Date: Mon, 2 Nov 2020 09:00:06 -0800 Subject: [PATCH 3/3] [pre-release] Update changelogs, version [0.15b0] (#1320) --- .../opentelemetry-instrumentation-wsgi/setup.cfg | 6 +++--- .../src/opentelemetry/instrumentation/wsgi/version.py | 2 +- 2 files changed, 4 insertions(+), 4 deletions(-) diff --git a/instrumentation/opentelemetry-instrumentation-wsgi/setup.cfg b/instrumentation/opentelemetry-instrumentation-wsgi/setup.cfg index 1570fd5d0..f40a219bc 100644 --- a/instrumentation/opentelemetry-instrumentation-wsgi/setup.cfg +++ b/instrumentation/opentelemetry-instrumentation-wsgi/setup.cfg @@ -39,12 +39,12 @@ package_dir= =src packages=find_namespace: install_requires = - opentelemetry-api == 0.15.dev0 - opentelemetry-instrumentation == 0.15.dev0 + opentelemetry-api == 0.15b0 + opentelemetry-instrumentation == 0.15b0 [options.extras_require] test = - opentelemetry-test == 0.15.dev0 + opentelemetry-test == 0.15b0 [options.packages.find] where = src diff --git a/instrumentation/opentelemetry-instrumentation-wsgi/src/opentelemetry/instrumentation/wsgi/version.py b/instrumentation/opentelemetry-instrumentation-wsgi/src/opentelemetry/instrumentation/wsgi/version.py index e7b342d64..ff494d225 100644 --- a/instrumentation/opentelemetry-instrumentation-wsgi/src/opentelemetry/instrumentation/wsgi/version.py +++ b/instrumentation/opentelemetry-instrumentation-wsgi/src/opentelemetry/instrumentation/wsgi/version.py @@ -12,4 +12,4 @@ # See the License for the specific language governing permissions and # limitations under the License. -__version__ = "0.15.dev0" +__version__ = "0.15b0"