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

Update environment variable names #904

Merged
merged 7 commits into from
Jul 30, 2020
Merged
Show file tree
Hide file tree
Changes from 6 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion docs/examples/django/README.rst
Original file line number Diff line number Diff line change
Expand Up @@ -36,7 +36,7 @@ Execution of the Django app

Set these environment variables first:

#. ``export OPENTELEMETRY_PYTHON_DJANGO_INSTRUMENT=True``
#. ``export OTEL_PYTHON_DJANGO_INSTRUMENT=True``
#. ``export DJANGO_SETTINGS_MODULE=instrumentation_example.settings``

The way to achieve OpenTelemetry instrumentation for your Django app is to use
Expand Down
2 changes: 2 additions & 0 deletions ext/opentelemetry-ext-django/CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,8 @@

## Unreleased

- Update environment variable names, prefix changed from `OPENTELEMETRY` to `OTEL` ([#904](https://github.com/open-telemetry/opentelemetry-python/pull/904))

## Version 0.11b0

Released 2020-07-28
Expand Down
4 changes: 2 additions & 2 deletions ext/opentelemetry-ext-django/README.rst
Original file line number Diff line number Diff line change
Expand Up @@ -20,13 +20,13 @@ Configuration

Exclude lists
*************
To exclude certain URLs from being tracked, set the environment variable ``OPENTELEMETRY_PYTHON_DJANGO_EXCLUDED_URLS`` with comma delimited regexes representing which URLs to exclude.
To exclude certain URLs from being tracked, set the environment variable ``OTEL_PYTHON_DJANGO_EXCLUDED_URLS`` with comma delimited regexes representing which URLs to exclude.

For example,

::

export OPENTELEMETRY_PYTHON_DJANGO_EXCLUDED_URLS="client/.*/info,healthcheck"
export OTEL_PYTHON_DJANGO_EXCLUDED_URLS="client/.*/info,healthcheck"

will exclude requests such as ``https://site/client/123/info`` and ``https://site/xyz/healthcheck``.

Expand Down
2 changes: 1 addition & 1 deletion ext/opentelemetry-ext-django/tests/conftest.py
Original file line number Diff line number Diff line change
Expand Up @@ -16,4 +16,4 @@


def pytest_sessionstart(session): # pylint: disable=unused-argument
environ.setdefault("OPENTELEMETRY_PYTHON_DJANGO_INSTRUMENT", "True")
environ.setdefault("OTEL_PYTHON_DJANGO_INSTRUMENT", "True")
4 changes: 3 additions & 1 deletion ext/opentelemetry-ext-elasticsearch/CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -2,8 +2,10 @@

## Unreleased

- Update environment variable names, prefix changed from `OPENTELEMETRY` to `OTEL` ([#904](https://github.com/open-telemetry/opentelemetry-python/pull/904))

## Version 0.10b0

Released 2020-06-23

- Initial release
- Initial release
Original file line number Diff line number Diff line change
Expand Up @@ -40,7 +40,7 @@
---

Elasticsearch instrumentation prefixes operation names with the string "Elasticsearch". This
can be changed to a different string by either setting the `OPENTELEMETRY_PYTHON_ELASTICSEARCH_NAME_PREFIX`
can be changed to a different string by either setting the `OTEL_PYTHON_ELASTICSEARCH_NAME_PREFIX`
environment variable or by passing the prefix as an argument to the instrumentor. For example,


Expand Down Expand Up @@ -88,8 +88,7 @@ class ElasticsearchInstrumentor(BaseInstrumentor):
def __init__(self, span_name_prefix=None):
if not span_name_prefix:
span_name_prefix = environ.get(
"OPENTELEMETRY_PYTHON_ELASTICSEARCH_NAME_PREFIX",
"Elasticsearch",
"OTEL_PYTHON_ELASTICSEARCH_NAME_PREFIX", "Elasticsearch",
)
self._span_name_prefix = span_name_prefix.strip()
super().__init__()
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -95,7 +95,7 @@ def test_prefix_arg(self, request_mock):

def test_prefix_env(self, request_mock):
prefix = "prefix-from-args"
env_var = "OPENTELEMETRY_PYTHON_ELASTICSEARCH_NAME_PREFIX"
env_var = "OTEL_PYTHON_ELASTICSEARCH_NAME_PREFIX"
os.environ[env_var] = prefix
ElasticsearchInstrumentor().uninstrument()
ElasticsearchInstrumentor().instrument()
Expand Down
4 changes: 2 additions & 2 deletions ext/opentelemetry-ext-flask/CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -2,9 +2,9 @@

## Unreleased

## Version 0.11b0
- Update environment variable names, prefix changed from `OPENTELEMETRY` to `OTEL` ([#904](https://github.com/open-telemetry/opentelemetry-python/pull/904))

Released 2020-07-28
## Version 0.11b0

- Use one general exclude list instead of two ([#872](https://github.com/open-telemetry/opentelemetry-python/pull/872))

Expand Down
4 changes: 2 additions & 2 deletions ext/opentelemetry-ext-flask/README.rst
Original file line number Diff line number Diff line change
Expand Up @@ -21,13 +21,13 @@ Configuration

Exclude lists
*************
To exclude certain URLs from being tracked, set the environment variable ``OPENTELEMETRY_PYTHON_FLASK_EXCLUDED_URLS`` with comma delimited regexes representing which URLs to exclude.
To exclude certain URLs from being tracked, set the environment variable ``OTEL_PYTHON_FLASK_EXCLUDED_URLS`` with comma delimited regexes representing which URLs to exclude.

For example,

::

export OPENTELEMETRY_PYTHON_FLASK_EXCLUDED_URLS="client/.*/info,healthcheck"
export OTEL_PYTHON_FLASK_EXCLUDED_URLS="client/.*/info,healthcheck"

will exclude requests such as ``https://site/client/123/info`` and ``https://site/xyz/healthcheck``.

Expand Down
6 changes: 3 additions & 3 deletions ext/opentelemetry-ext-pyramid/CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -2,14 +2,14 @@

## Unreleased

## Version 0.11b0
- Update environment variable names, prefix changed from `OPENTELEMETRY` to `OTEL` ([#904](https://github.com/open-telemetry/opentelemetry-python/pull/904))

Released 2020-07-28
## Version 0.11b0

- Use one general exclude list instead of two ([#872](https://github.com/open-telemetry/opentelemetry-python/pull/872))

## 0.9b0

Released 2020-06-10

- Initial release
- Initial release
4 changes: 2 additions & 2 deletions ext/opentelemetry-ext-pyramid/README.rst
Original file line number Diff line number Diff line change
Expand Up @@ -15,13 +15,13 @@ Installation

Exclude lists
*************
To exclude certain URLs from being tracked, set the environment variable ``OPENTELEMETRY_PYTHON_PYRAMID_EXCLUDED_URLS`` with comma delimited regexes representing which URLs to exclude.
To exclude certain URLs from being tracked, set the environment variable ``OTEL_PYTHON_PYRAMID_EXCLUDED_URLS`` with comma delimited regexes representing which URLs to exclude.

For example,

::

export OPENTELEMETRY_PYTHON_PYRAMID_EXCLUDED_URLS="client/.*/info,healthcheck"
export OTEL_PYTHON_PYRAMID_EXCLUDED_URLS="client/.*/info,healthcheck"

will exclude requests such as ``https://site/client/123/info`` and ``https://site/xyz/healthcheck``.

Expand Down
5 changes: 3 additions & 2 deletions opentelemetry-api/CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -2,9 +2,10 @@

## Unreleased

## Version 0.11b0
- Update environment variable names, prefix changed from `OPENTELEMETRY` to `OTEL`
([#904](https://github.com/open-telemetry/opentelemetry-python/pull/904))

Released 2020-07-28
## Version 0.11b0

- Return INVALID_SPAN if no TracerProvider set for get_current_span
([#751](https://github.com/open-telemetry/opentelemetry-python/pull/751))
Expand Down
37 changes: 19 additions & 18 deletions opentelemetry-api/src/opentelemetry/configuration/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -16,30 +16,33 @@
Simple configuration manager

This is a configuration manager for OpenTelemetry. It reads configuration
values from environment variables prefixed with ``OPENTELEMETRY_PYTHON_`` whose
characters are only alphanumeric characters and unserscores, except for the
first character after ``OPENTELEMETRY_PYTHON_`` which must not be a number.
values from environment variables prefixed with ``OTEL_`` (for environment
variables that apply to any OpenTelemetry implementation) or with
``OTEL_PYTHON_`` (for environment variables that are specific to the Python
implementation of OpenTelemetry) whose characters are only alphanumeric
characters and unserscores, except for the first character after ``OTEL_`` or
``OTEL_PYTHON_`` which must not be a number.

For example, these environment variables will be read:

1. ``OPENTELEMETRY_PYTHON_SOMETHING``
2. ``OPENTELEMETRY_PYTHON_SOMETHING_ELSE_``
3. ``OPENTELEMETRY_PYTHON_SOMETHING_ELSE_AND__ELSE``
4. ``OPENTELEMETRY_PYTHON_SOMETHING_ELSE_AND_else``
5. ``OPENTELEMETRY_PYTHON_SOMETHING_ELSE_AND_else2``
1. ``OTEL_SOMETHING``
2. ``OTEL_SOMETHING_ELSE_``
3. ``OTEL_SOMETHING_ELSE_AND__ELSE``
4. ``OTEL_SOMETHING_ELSE_AND_else``
5. ``OTEL_SOMETHING_ELSE_AND_else2``

These won't:

1. ``OPENTELEMETRY_PYTH_SOMETHING``
2. ``OPENTELEMETRY_PYTHON_2_SOMETHING_AND__ELSE``
3. ``OPENTELEMETRY_PYTHON_SOMETHING_%_ELSE``
2. ``OTEL_2_SOMETHING_AND__ELSE``
3. ``OTEL_SOMETHING_%_ELSE``

The values stored in the environment variables can be found in an instance of
``opentelemetry.configuration.Configuration``. This class can be instantiated
freely because instantiating it returns always the same object.

For example, if the environment variable
``OPENTELEMETRY_PYTHON_METER_PROVIDER`` value is ``my_meter_provider``, then
``OTEL_PYTHON_METER_PROVIDER`` value is ``my_meter_provider``, then
``Configuration().meter_provider == "my_meter_provider"`` would be ``True``.

Non defined attributes will always return ``None``. This is intended to make it
Expand All @@ -49,8 +52,8 @@
Environment variables used by OpenTelemetry
-------------------------------------------

1. OPENTELEMETRY_PYTHON_METER_PROVIDER
2. OPENTELEMETRY_PYTHON_TRACER_PROVIDER
1. OTEL_PYTHON_METER_PROVIDER
2. OTEL_PYTHON_TRACER_PROVIDER

The value of these environment variables should be the name of the entry point
that points to the class that implements either provider. This OpenTelemetry
Expand All @@ -70,7 +73,7 @@
}

To use the meter provider above, then the
``OPENTELEMETRY_PYTHON_METER_PROVIDER`` should be set to
``OTEL_PYTHON_METER_PROVIDER`` should be set to
``"default_meter_provider"`` (this is not actually necessary since the
OpenTelemetry API provided providers are the default ones used if no
configuration is found in the environment variables).
Expand Down Expand Up @@ -110,13 +113,11 @@ def __new__(cls) -> "Configuration":
instance = super().__new__(cls)
for key, value_str in environ.items():

match = fullmatch(
r"OPENTELEMETRY_PYTHON_([A-Za-z_][\w_]*)", key
)
match = fullmatch(r"OTEL_(PYTHON_)?([A-Za-z_][\w_]*)", key)

if match is not None:

key = match.group(1)
key = match.group(2)
value = value_str # type: ConfigValue

if value_str == "True":
Expand Down
2 changes: 1 addition & 1 deletion opentelemetry-api/src/opentelemetry/context/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -55,7 +55,7 @@ def wrapper(
default_context = "contextvars_context"

configured_context = environ.get(
"OPENTELEMETRY_CONTEXT", default_context
"OTEL_CONTEXT", default_context
) # type: str
try:
_RUNTIME_CONTEXT = next(
Expand Down
30 changes: 13 additions & 17 deletions opentelemetry-api/tests/configuration/test_configuration.py
Original file line number Diff line number Diff line change
Expand Up @@ -32,10 +32,10 @@ def test_singleton(self) -> None:
@patch.dict(
"os.environ", # type: ignore
{
"OPENTELEMETRY_PYTHON_METER_PROVIDER": "meter_provider",
"OPENTELEMETRY_PYTHON_TRACER_PROVIDER": "tracer_provider",
"OPENTELEMETRY_PYTHON_OThER": "other",
"OPENTELEMETRY_PYTHON_OTHER_7": "other_7",
"OTEL_PYTHON_METER_PROVIDER": "meter_provider",
"OTEL_PYTHON_TRACER_PROVIDER": "tracer_provider",
"OTEL_OThER": "other",
"OTEL_OTHER_7": "other_7",
"OPENTELEMETRY_PTHON_TRACEX_PROVIDER": "tracex_provider",
},
)
Expand All @@ -56,7 +56,7 @@ def test_environment_variables(self) -> None:

@patch.dict(
"os.environ", # type: ignore
{"OPENTELEMETRY_PYTHON_TRACER_PROVIDER": "tracer_provider"},
{"OTEL_PYTHON_TRACER_PROVIDER": "tracer_provider"},
)
def test_property(self) -> None:
with self.assertRaises(AttributeError):
Expand All @@ -79,8 +79,7 @@ def test_getattr(self) -> None:

def test_reset(self) -> None:
environ_patcher = patch.dict(
"os.environ",
{"OPENTELEMETRY_PYTHON_TRACER_PROVIDER": "tracer_provider"},
"os.environ", {"OTEL_PYTHON_TRACER_PROVIDER": "tracer_provider"},
)

environ_patcher.start()
Expand All @@ -99,10 +98,7 @@ def test_reset(self) -> None:

@patch.dict(
"os.environ", # type: ignore
{
"OPENTELEMETRY_PYTHON_TRUE": "True",
"OPENTELEMETRY_PYTHON_FALSE": "False",
},
{"OTEL_TRUE": "True", "OTEL_FALSE": "False"},
)
def test_boolean(self) -> None:
self.assertIsInstance(
Expand All @@ -117,9 +113,9 @@ def test_boolean(self) -> None:
@patch.dict(
"os.environ", # type: ignore
{
"OPENTELEMETRY_PYTHON_POSITIVE_INTEGER": "123",
"OPENTELEMETRY_PYTHON_NEGATIVE_INTEGER": "-123",
"OPENTELEMETRY_PYTHON_NON_INTEGER": "-12z3",
"OTEL_POSITIVE_INTEGER": "123",
"OTEL_NEGATIVE_INTEGER": "-123",
"OTEL_NON_INTEGER": "-12z3",
},
)
def test_integer(self) -> None:
Expand All @@ -136,9 +132,9 @@ def test_integer(self) -> None:
@patch.dict(
"os.environ", # type: ignore
{
"OPENTELEMETRY_PYTHON_POSITIVE_FLOAT": "123.123",
"OPENTELEMETRY_PYTHON_NEGATIVE_FLOAT": "-123.123",
"OPENTELEMETRY_PYTHON_NON_FLOAT": "-12z3.123",
"OTEL_POSITIVE_FLOAT": "123.123",
"OTEL_NEGATIVE_FLOAT": "-123.123",
"OTEL_NON_FLOAT": "-12z3.123",
},
)
def test_float(self) -> None:
Expand Down
5 changes: 3 additions & 2 deletions opentelemetry-sdk/CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -2,9 +2,10 @@

## Unreleased

## Version 0.11b0
- Update environment variable names, prefix changed from `OPENTELEMETRY` to `OTEL`
([#904](https://github.com/open-telemetry/opentelemetry-python/pull/904))

Released 2020-07-28
## Version 0.11b0

- Add support for resources and resource detector
([#853](https://github.com/open-telemetry/opentelemetry-python/pull/853))
Expand Down
6 changes: 3 additions & 3 deletions opentelemetry-sdk/tests/conftest.py
Original file line number Diff line number Diff line change
Expand Up @@ -20,11 +20,11 @@ def pytest_sessionstart(session):
# pylint: disable=unused-argument
if version_info < (3, 5):
# contextvars are not supported in 3.4, use thread-local storage
environ["OPENTELEMETRY_CONTEXT"] = "threadlocal_context"
environ["OTEL_CONTEXT"] = "threadlocal_context"
else:
environ["OPENTELEMETRY_CONTEXT"] = "contextvars_context"
environ["OTEL_CONTEXT"] = "contextvars_context"


def pytest_sessionfinish(session):
# pylint: disable=unused-argument
environ.pop("OPENTELEMETRY_CONTEXT")
environ.pop("OTEL_CONTEXT")