Skip to content

Use warnings instead of logging exceptions #649

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

Closed
ocelotl opened this issue May 4, 2020 · 3 comments
Closed

Use warnings instead of logging exceptions #649

ocelotl opened this issue May 4, 2020 · 3 comments
Assignees
Labels
backlog discussion Issue or PR that needs/is extended discussion.

Comments

@ocelotl
Copy link
Contributor

ocelotl commented May 4, 2020

So far we have been catching exceptions we don't want raised and logging a message instead. This definitely accomplishes its purpose and follows these basic error handling principles.

Nevertheless, the specification also takes into consideration that this default behavior can be changed to allow the user strict error handling to reveal bugs.

I suggest that we use the warnings module instead of getLogger(...).exception. In this way, OpenTelemetry can be run in a way that makes the warnings turn into exceptions allowing the user to find bugs more easily while being specification compliant still.

Here are few examples that illustrate how this can work:

#logging_warning.py
from logging import getLogger

_logger = getLogger(__name__)

try:
    1 / 0
except ZeroDivisionError:
    _logger.exception("A division by zero happened")

print("execution complete")
python logging_warning.py

A division by zero happened
Traceback (most recent call last):
  File "logging_warning.py", line 6, in <module>
    1 / 0
ZeroDivisionError: division by zero
execution complete
# raising_warning.py
from warnings import warn

try:
    1 / 0
except ZeroDivisionError:
    warn("A division by zero happened")

print("execution complete")
python raising_warning.py

raising_warning.py:7: UserWarning: A division by zero happened
  warn("A division by zero happened")
execution complete
python -W error raising_warning.py

Traceback (most recent call last):
  File "raising_warning.py", line 5, in <module>
    1 / 0
ZeroDivisionError: division by zero

During handling of the above exception, another exception occurred:

Traceback (most recent call last):
  File "raising_warning.py", line 7, in <module>
    warn("A division by zero happened")
UserWarning: A division by zero happened
@ocelotl ocelotl added the discussion Issue or PR that needs/is extended discussion. label May 4, 2020
@ocelotl ocelotl self-assigned this May 4, 2020
@ffe4
Copy link
Contributor

ffe4 commented Sep 10, 2020

@ocelotl Is this superseded by #1079?

srikanthccv pushed a commit to srikanthccv/opentelemetry-python that referenced this issue Nov 1, 2020
* refactor: use a single eslintrc for all examples folders

furthermore, override the strict rule that ships with airbnb

* fix: turn off no-use-before-define

* fix: install eslint in ci container

Co-Authored-By: Daniel Dyla <[email protected]>

* fix: ignore uninstalled packages lint errors

We will not want to install all examples in CI

Co-authored-by: Daniel Dyla <[email protected]>
Co-authored-by: Mayur Kale <[email protected]>
@github-actions
Copy link

This issue was marked stale due to lack of activity. It will be closed in 30 days.

@github-actions
Copy link

github-actions bot commented Jun 9, 2021

Closed as inactive. Feel free to reopen if this issue needs resolving.

@github-actions github-actions bot closed this as completed Jun 9, 2021
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
backlog discussion Issue or PR that needs/is extended discussion.
Projects
None yet
Development

No branches or pull requests

2 participants