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

Fix get exporter names condition #1707

Merged
merged 9 commits into from
Mar 22, 2021
Merged

Conversation

dtaniwaki
Copy link
Contributor

Description

With the current condition, _get_exporter_names always fails with no OTEL_TRACES_EXPORTER.

Python 3.8.2 (default, Apr 27 2020, 15:52:40)
[Clang 11.0.0 (clang-1100.0.33.17)] on darwin
Type "help", "copyright", "credits" or "license" for more information.
>>> from opentelemetry.distro import Configurator
description should only be set when status_code is set to StatusCode.ERROR
>>> Configurator().configure()
Traceback (most recent call last):
  File "<stdin>", line 1, in <module>
  File "/Users/dtaniwaki/.pyenv/versions/3.8.2/lib/python3.8/site-packages/opentelemetry/instrumentation/configurator.py", line 50, in configure
    self._configure(**kwargs)
  File "/Users/dtaniwaki/github/opentelemetry-python/opentelemetry-distro/src/opentelemetry/distro/__init__.py", line 152, in _configure
    _initialize_components()
  File "/Users/dtaniwaki/github/opentelemetry-python/opentelemetry-distro/src/opentelemetry/distro/__init__.py", line 143, in _initialize_components
    exporter_names = _get_exporter_names()
  File "/Users/dtaniwaki/github/opentelemetry-python/opentelemetry-distro/src/opentelemetry/distro/__init__.py", line 55, in _get_exporter_names
    or trace_exporters.lower().strip() != "none"
AttributeError: 'NoneType' object has no attribute 'lower'

Type of change

Please delete options that are not relevant.

  • Bug fix (non-breaking change which fixes an issue)

How Has This Been Tested?

  • Tried to configure it with Configurator().configure() w/ and w/o OTEL_TRACES_EXPORTER.

Does This PR Require a Contrib Repo Change?

  • No.

Checklist:

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

@dtaniwaki dtaniwaki requested review from a team, codeboten and toumorokoshi and removed request for a team March 19, 2021 13:49
@lzchen
Copy link
Contributor

lzchen commented Mar 19, 2021

This issue will only happen if OTEL_TRACES_EXPORTER is set to a blank string correct?

@@ -52,7 +52,8 @@ def _get_exporter_names() -> Sequence[str]:

if (
trace_exporters is not None
or trace_exporters.lower().strip() != "none"
and trace_exporters != ""
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Can we just do if trace_exporters and trace_exporters.lower().strip() != "none"?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

That's right. 👍

@dtaniwaki
Copy link
Contributor Author

This issue will only happen if OTEL_TRACES_EXPORTER is set to a blank string correct?

Here, the blank means the following 2 things.

  1. OTEL_TRACES_EXPORTER is not set.
  2. OTEL_TRACES_EXPORTER is an empty string.

CHANGELOG.md Outdated
@@ -68,6 +68,8 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0
([#1695](https://github.com/open-telemetry/opentelemetry-python/pull/1695))
- Change Jaeger exporters to obtain service.name from span
([#1703](https://github.com/open-telemetry/opentelemetry-python/pull/1703))
- Fixed a parse error on no `OTEL_TRACES_EXPORTER`
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

can you change the description to be focused on the behavior of the user?

In this case, I would expect something like Fixed an unset OTEL_TRACES_EXPORTER resulting in an error.

This way a reader can identify whether their behavior is fixed or not.

Copy link
Member

@toumorokoshi toumorokoshi left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

minor nit on changelog description, all else looks good!

@dtaniwaki
Copy link
Contributor Author

I updated the code, thanks!

@lzchen
Copy link
Contributor

lzchen commented Mar 20, 2021

@dtaniwaki
Don't we already have this none check?

@toumorokoshi
Copy link
Member

@dtaniwaki
Don't we already have this none check?

I think it was a logical oversight. Probably should have been the "and" operator rather than or.

If it's none, the first check is false so the OR statement continues, executing the second statement.

Here's what the logic does in a similar example:

>>> print(None is not None or None.lower())
Traceback (most recent call last):
  File "<stdin>", line 1, in <module>
AttributeError: 'NoneType' object has no attribute 'lower'

Copy link
Member

@toumorokoshi toumorokoshi left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

LGTM, thanks!

@lzchen lzchen merged commit 320d69f into open-telemetry:main Mar 22, 2021
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants