From 92fbbe9b018d5f35f037d1df5c28aad58e5eb7e3 Mon Sep 17 00:00:00 2001 From: "Benjamin A. Beasley" Date: Thu, 5 Aug 2021 09:50:37 -0400 Subject: [PATCH 1/2] Handle traceback.format_exception() API change in Python 3.10 MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit The first argument of traceback.format_exception() has been renamed from “etype” to “exc” and is now positional-only. Passing it as a positional argument rather than a keyword argument fixes a TypeError on Python 3.10 while remaining compatible with previous Python releases: • On Python 3.10, the parameter *should* be the exception object; it is now possible to call format_exception() with only the exception object, omitting “value” and “tb”. Here the type of the exception object is given instead; however, this is OK because “value” and “tb” are also given, and therefore the positional “exc” parameter is ignored and may have any value or type whatsoever. • From Python 3.5 to 3.9, the first argument is “etype” and is correctly the type of the exception object; however, its actual value is still ignored in favor of the type of “value”. • Prior to Python 3.5, the “etype” would actually be used, if this project supported those Python versions. The changes in the traceback module in Python 3.10 are documented at: https://docs.python.org/3.10/library/traceback.html#traceback.print_exception https://docs.python.org/3.10/library/traceback.html#traceback.format_exception https://docs.python.org/3.10/library/traceback.html#traceback.format_exception_only https://docs.python.org/3.10/library/traceback.html#traceback.TracebackException.format_exception_only --- shim/opentelemetry-opentracing-shim/tests/test_shim.py | 4 +--- 1 file changed, 1 insertion(+), 3 deletions(-) diff --git a/shim/opentelemetry-opentracing-shim/tests/test_shim.py b/shim/opentelemetry-opentracing-shim/tests/test_shim.py index 828097270f0..e27f7797340 100644 --- a/shim/opentelemetry-opentracing-shim/tests/test_shim.py +++ b/shim/opentelemetry-opentracing-shim/tests/test_shim.py @@ -482,9 +482,7 @@ def test_span_on_error(self): ex = exc_ctx.exception expected_stack = "".join( - traceback.format_exception( - etype=type(ex), value=ex, tb=ex.__traceback__ - ) + traceback.format_exception(type(ex), value=ex, tb=ex.__traceback__) ) # Verify exception details have been added to span. exc_event = scope.span.unwrap().events[0] From 62b07cab0cfcadc5366ef323f9c0c413a09fcfa8 Mon Sep 17 00:00:00 2001 From: "Benjamin A. Beasley" Date: Thu, 5 Aug 2021 13:41:13 -0400 Subject: [PATCH 2/2] Add a changelog entry for PR#2018 --- CHANGELOG.md | 2 ++ 1 file changed, 2 insertions(+) diff --git a/CHANGELOG.md b/CHANGELOG.md index fae7b823869..d1132b19e33 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -9,6 +9,8 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0 to let distros use its default implementation ([#1937](https://github.com/open-telemetry/opentelemetry-python/pull/1937)) - Add Trace ID validation to meet [TraceID spec](https://github.com/open-telemetry/opentelemetry-specification/blob/main/specification/overview.md#spancontext) ([#1992](https://github.com/open-telemetry/opentelemetry-python/pull/1992)) +- Fixed Python 3.10 incompatibility in `opentelemetry-opentracing-shim` tests + ([#2018](https://github.com/open-telemetry/opentelemetry-python/pull/2018)) ## [0.23.1](https://github.com/open-telemetry/opentelemetry-python/pull/1987) - 2021-07-26