Skip to content
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

Python 3.11: Enhanced error locations in tracebacks #2771

Merged
merged 2 commits into from
Jun 21, 2022

Conversation

hroncok
Copy link
Contributor

@hroncok hroncok commented Jun 20, 2022

Description

Expect ^^^^^^^^^ in tracebacks when testing them

Type of change

Please delete options that are not relevant.

  • Bug fix (non-breaking change which fixes an issue)
  • New feature (non-breaking change which adds functionality)
  • Breaking change (fix or feature that would cause existing functionality to not work as expected)
  • This change requires a documentation update

How Has This Been Tested?

I've built the Fedora package on Python 3.11.0b3.

Does This PR Require a Contrib Repo Change?

Answer the following question based on these examples of changes that would require a Contrib Repo Change:

  • The OTel specification has changed which prompted this PR to update the method interfaces of opentelemetry-api/ or opentelemetry-sdk/

  • The method interfaces of test/util have changed

  • Scripts in scripts/ that were copied over to the Contrib repo have changed

  • Configuration files that were copied over to the Contrib repo have changed (when consistency between repositories is applicable) such as in

    • pyproject.toml
    • isort.cfg
    • .flake8
  • When a new .github/CODEOWNER is added

  • Major changes to project information, such as in:

    • README.md
    • CONTRIBUTING.md
  • Yes. - Link to PR:

  • No.

Checklist:

  • Followed the style guidelines of this project
  • Changelogs have been updated
  • Unit tests have been added
  • Documentation has been updated

I've opened this here because I needed it in Fedora, but I am currently herding dozens of similar issues as the Fedora's Python 3.11 mass rebuild is in progress. I won't be able to dedicate my time to fixing any style issues, changelog fragments, or similar things. Sorry about that. Feel free to adjust this in any way you see fit or even close it if it's not up to the project's standards.

@linux-foundation-easycla
Copy link

linux-foundation-easycla bot commented Jun 20, 2022

CLA Signed

The committers listed above are authorized under a signed CLA.

  • ✅ login: hroncok / name: Miro Hrončok (98075fd)

Expect ^^^^^^^^^ in tracebacks when testing them
@hroncok hroncok marked this pull request as ready for review June 20, 2022 15:36
@hroncok hroncok requested a review from a team June 20, 2022 15:36
@srikanthccv srikanthccv added the Skip Changelog PRs that do not require a CHANGELOG.md entry label Jun 21, 2022
@ocelotl ocelotl merged commit aa36730 into open-telemetry:main Jun 21, 2022
@musicinmybrain
Copy link
Contributor

This has changed again in 3.11b4:

________________ TestSpan.test_record_exception_context_manager ________________
self = <tests.trace.test_trace.TestSpan testMethod=test_record_exception_context_manager>
        def test_record_exception_context_manager(self):
            try:
                with self.tracer.start_as_current_span("span") as span:
                    raise RuntimeError("example error")
            except RuntimeError:
                pass
            finally:
                self.assertEqual(len(span.events), 1)
                event = span.events[0]
                self.assertEqual("exception", event.name)
                self.assertEqual(
                    "RuntimeError", event.attributes["exception.type"]
                )
                self.assertEqual(
                    "example error", event.attributes["exception.message"]
                )
    
                stacktrace = """in test_record_exception_context_manager
        raise RuntimeError("example error")
    RuntimeError: example error"""
                if sys.version_info >= (3, 11):
                    # https://docs.python.org/3.11/whatsnew/3.11.html#enhanced-error-locations-in-tracebacks
                    tracelines = stacktrace.splitlines()
                    tracelines.insert(-1, "    ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^")
                    stacktrace = "\n".join(tracelines)
>               self.assertIn(stacktrace, event.attributes["exception.stacktrace"])
E               AssertionError: 'in test_record_exception_context_manager\n    raise RuntimeError("example error")\n    ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^\nRuntimeError: example error' not found in 'Traceback (most recent call last):\n  File "/builddir/build/BUILDROOT/python-opentelemetry-1.11.1-9.fc37.noarch/usr/lib/python3.11/site-packages/opentelemetry/trace/__init__.py", line 563, in use_span\n    yield span\n  File "/builddir/build/BUILDROOT/python-opentelemetry-1.11.1-9.fc37.noarch/usr/lib/python3.11/site-packages/opentelemetry/sdk/trace/__init__.py", line 1015, in start_as_current_span\n    yield span_context\n  File "/builddir/build/BUILD/opentelemetry-python-1.11.1/opentelemetry-sdk/tests/trace/test_trace.py", line 1140, in test_record_exception_context_manager\n    raise RuntimeError("example error")\nRuntimeError: example error\n'
opentelemetry-sdk/tests/trace/test_trace.py:1162: AssertionError

Apparently, the ^^^^… are now omitted when they would “underline” the whole preceding line, which is the case here. Therefore, this will need to be reverted for 3.11.0b4 and later compatibility.

musicinmybrain added a commit to musicinmybrain/opentelemetry-python that referenced this pull request Jul 25, 2022
…emetry#2771)"

This reverts commit aa36730.

It is no longer required on Python 3.11.0b4 and later; see
open-telemetry#2771 (comment)
and
https://mail.python.org/archives/list/python-dev@python.org/message/73YP4RS4QOJXUS63BQZVLTQHK3OP3L3H/.

Specifically, the ^^^^… are now omitted when they would “underline” the
whole preceding line, which is the case here, so the expected output is
the same as for Python 3.10 and earlier.
srikanthccv pushed a commit that referenced this pull request Jul 25, 2022
…2839)

This reverts commit aa36730.

It is no longer required on Python 3.11.0b4 and later; see
#2771 (comment)
and
https://mail.python.org/archives/list/python-dev@python.org/message/73YP4RS4QOJXUS63BQZVLTQHK3OP3L3H/.

Specifically, the ^^^^… are now omitted when they would “underline” the
whole preceding line, which is the case here, so the expected output is
the same as for Python 3.10 and earlier.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Skip Changelog PRs that do not require a CHANGELOG.md entry
Projects
None yet
Development

Successfully merging this pull request may close these issues.

4 participants