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

Rename env vars from OTEL_TRACE -> OTEL_TRACES #1595

Merged
merged 2 commits into from
Feb 11, 2021
Merged
Show file tree
Hide file tree
Changes from all 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: 2 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,8 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0
### Changed
- Tracer and Meter provider environment variables are now consistent with the rest
([#1571](https://github.com/open-telemetry/opentelemetry-python/pull/1571)])
- Rename `TRACE_` to `TRACES_` for environment variables
([#1595](https://github.com/open-telemetry/opentelemetry-python/pull/1595)])

### Added
- Added `end_on_exit` argument to `start_as_current_span`
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -17,5 +17,5 @@
OTEL_PYTHON_DISABLED_INSTRUMENTATIONS = "OTEL_PYTHON_DISABLED_INSTRUMENTATIONS"
OTEL_PYTHON_IDS_GENERATOR = "OTEL_PYTHON_IDS_GENERATOR"
OTEL_PYTHON_SERVICE_NAME = "OTEL_PYTHON_SERVICE_NAME"
OTEL_TRACE_EXPORTER = "OTEL_TRACE_EXPORTER"
OTEL_TRACES_EXPORTER = "OTEL_TRACES_EXPORTER"
OTEL_PYTHON_TRACER_PROVIDER = "OTEL_PYTHON_TRACER_PROVIDER"
6 changes: 3 additions & 3 deletions opentelemetry-distro/src/opentelemetry/distro/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,7 @@
from opentelemetry.environment_variables import (
OTEL_PYTHON_IDS_GENERATOR,
OTEL_PYTHON_SERVICE_NAME,
OTEL_TRACE_EXPORTER,
OTEL_TRACES_EXPORTER,
)
from opentelemetry.instrumentation.configurator import BaseConfigurator
from opentelemetry.instrumentation.distro import BaseDistro
Expand Down Expand Up @@ -54,7 +54,7 @@ def _get_service_name() -> str:


def _get_exporter_names() -> Sequence[str]:
trace_exporters = environ.get(OTEL_TRACE_EXPORTER)
trace_exporters = environ.get(OTEL_TRACES_EXPORTER)

exporters = set()

Expand Down Expand Up @@ -175,4 +175,4 @@ class OpenTelemetryDistro(BaseDistro):
"""

def _configure(self, **kwargs):
os.environ.setdefault(OTEL_TRACE_EXPORTER, "otlp_span")
os.environ.setdefault(OTEL_TRACES_EXPORTER, "otlp_span")
6 changes: 3 additions & 3 deletions opentelemetry-distro/tests/test_distro.py
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@
from pkg_resources import DistributionNotFound, require

from opentelemetry.distro import OpenTelemetryDistro
from opentelemetry.environment_variables import OTEL_TRACE_EXPORTER
from opentelemetry.environment_variables import OTEL_TRACES_EXPORTER


class TestDistribution(TestCase):
Expand All @@ -31,6 +31,6 @@ def test_package_available(self):

def test_default_configuration(self):
distro = OpenTelemetryDistro()
self.assertIsNone(os.environ.get(OTEL_TRACE_EXPORTER))
self.assertIsNone(os.environ.get(OTEL_TRACES_EXPORTER))
distro.configure()
self.assertEqual("otlp_span", os.environ.get(OTEL_TRACE_EXPORTER))
self.assertEqual("otlp_span", os.environ.get(OTEL_TRACES_EXPORTER))
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,7 @@
from opentelemetry.environment_variables import (
OTEL_PYTHON_IDS_GENERATOR,
OTEL_PYTHON_SERVICE_NAME,
OTEL_TRACE_EXPORTER,
OTEL_TRACES_EXPORTER,
)

logger = getLogger(__file__)
Expand Down Expand Up @@ -82,7 +82,7 @@ def parse_args():

def load_config_from_cli_args(args):
if args.trace_exporter:
environ[OTEL_TRACE_EXPORTER] = args.trace_exporter
environ[OTEL_TRACES_EXPORTER] = args.trace_exporter
if args.service_name:
environ[OTEL_PYTHON_SERVICE_NAME] = args.service_name
if args.ids_generator:
Expand Down
6 changes: 3 additions & 3 deletions opentelemetry-instrumentation/tests/test_run.py
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@

from opentelemetry.environment_variables import (
OTEL_PYTHON_SERVICE_NAME,
OTEL_TRACE_EXPORTER,
OTEL_TRACES_EXPORTER,
)
from opentelemetry.instrumentation import auto_instrumentation

Expand Down Expand Up @@ -111,13 +111,13 @@ class TestArgs(TestCase):
def test_exporter(self, _): # pylint: disable=no-self-use
with patch("sys.argv", ["instrument", "2"]):
auto_instrumentation.run()
self.assertIsNone(environ.get(OTEL_TRACE_EXPORTER))
self.assertIsNone(environ.get(OTEL_TRACES_EXPORTER))

with patch(
"sys.argv", ["instrument", "--trace-exporter", "jaeger", "1", "2"]
):
auto_instrumentation.run()
self.assertEqual(environ.get(OTEL_TRACE_EXPORTER), "jaeger")
self.assertEqual(environ.get(OTEL_TRACES_EXPORTER), "jaeger")

@patch("opentelemetry.instrumentation.auto_instrumentation.execl")
def test_service_name(self, _): # pylint: disable=no-self-use
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -14,8 +14,8 @@

OTEL_RESOURCE_ATTRIBUTES = "OTEL_RESOURCE_ATTRIBUTES"
OTEL_LOG_LEVEL = "OTEL_LOG_LEVEL"
OTEL_TRACE_SAMPLER = "OTEL_TRACE_SAMPLER"
OTEL_TRACE_SAMPLER_ARG = "OTEL_TRACE_SAMPLER_ARG"
OTEL_TRACES_SAMPLER = "OTEL_TRACES_SAMPLER"
OTEL_TRACES_SAMPLER_ARG = "OTEL_TRACES_SAMPLER_ARG"
OTEL_BSP_SCHEDULE_DELAY = "OTEL_BSP_SCHEDULE_DELAY"
OTEL_BSP_EXPORT_TIMEOUT = "OTEL_BSP_EXPORT_TIMEOUT"
OTEL_BSP_MAX_QUEUE_SIZE = "OTEL_BSP_MAX_QUEUE_SIZE"
Expand Down
18 changes: 9 additions & 9 deletions opentelemetry-sdk/src/opentelemetry/sdk/trace/sampling.py
Original file line number Diff line number Diff line change
Expand Up @@ -60,8 +60,8 @@
with trace.get_tracer(__name__).start_as_current_span("Test Span"):
...

The tracer sampler can also be configured via environment variables ``OTEL_TRACE_SAMPLER`` and ``OTEL_TRACE_SAMPLER_ARG`` (only if applicable).
The list of known values for ``OTEL_TRACE_SAMPLER`` are:
The tracer sampler can also be configured via environment variables ``OTEL_TRACES_SAMPLER`` and ``OTEL_TRACES_SAMPLER_ARG`` (only if applicable).
The list of known values for ``OTEL_TRACES_SAMPLER`` are:

* always_on - Sampler that always samples spans, regardless of the parent span's sampling decision.
* always_off - Sampler that never samples spans, regardless of the parent span's sampling decision.
Expand All @@ -70,10 +70,10 @@
* parentbased_always_off - Sampler that respects its parent span's sampling decision, but otherwise never samples.
* parentbased_traceidratio - Sampler that respects its parent span's sampling decision, but otherwise samples probabalistically based on rate.

Sampling probability can be set with ``OTEL_TRACE_SAMPLER_ARG`` if the sampler is traceidratio or parentbased_traceidratio, when not provided rate will be set to 1.0 (maximum rate possible).
Sampling probability can be set with ``OTEL_TRACES_SAMPLER_ARG`` if the sampler is traceidratio or parentbased_traceidratio, when not provided rate will be set to 1.0 (maximum rate possible).


Prev example but with environment vairables. Please make sure to set the env ``OTEL_TRACE_SAMPLER=traceidratio`` and ``OTEL_TRACE_SAMPLER_ARG=0.001``.
Prev example but with environment vairables. Please make sure to set the env ``OTEL_TRACES_SAMPLER=traceidratio`` and ``OTEL_TRACES_SAMPLER_ARG=0.001``.

.. code:: python

Expand Down Expand Up @@ -105,8 +105,8 @@
# pylint: disable=unused-import
from opentelemetry.context import Context
from opentelemetry.sdk.environment_variables import (
OTEL_TRACE_SAMPLER,
OTEL_TRACE_SAMPLER_ARG,
OTEL_TRACES_SAMPLER,
OTEL_TRACES_SAMPLER_ARG,
)
from opentelemetry.trace import Link, get_current_span
from opentelemetry.trace.span import TraceState
Expand Down Expand Up @@ -370,17 +370,17 @@ def __init__(self, rate: float):

def _get_from_env_or_default() -> Sampler:
trace_sampler = os.getenv(
OTEL_TRACE_SAMPLER, "parentbased_always_on"
OTEL_TRACES_SAMPLER, "parentbased_always_on"
).lower()
if trace_sampler not in _KNOWN_SAMPLERS:
_logger.warning("Couldn't recognize sampler %s.", trace_sampler)
trace_sampler = "parentbased_always_on"

if trace_sampler in ("traceidratio", "parentbased_traceidratio"):
try:
rate = float(os.getenv(OTEL_TRACE_SAMPLER_ARG))
rate = float(os.getenv(OTEL_TRACES_SAMPLER_ARG))
except ValueError:
_logger.warning("Could not convert TRACE_SAMPLER_ARG to float.")
_logger.warning("Could not convert TRACES_SAMPLER_ARG to float.")
rate = 1.0
return _KNOWN_SAMPLERS[trace_sampler](rate)

Expand Down
10 changes: 5 additions & 5 deletions opentelemetry-sdk/tests/trace/test_trace.py
Original file line number Diff line number Diff line change
Expand Up @@ -30,8 +30,8 @@
OTEL_SPAN_ATTRIBUTE_COUNT_LIMIT,
OTEL_SPAN_EVENT_COUNT_LIMIT,
OTEL_SPAN_LINK_COUNT_LIMIT,
OTEL_TRACE_SAMPLER,
OTEL_TRACE_SAMPLER_ARG,
OTEL_TRACES_SAMPLER,
OTEL_TRACES_SAMPLER_ARG,
)
from opentelemetry.sdk.trace import Resource, sampling
from opentelemetry.sdk.trace.ids_generator import RandomIdsGenerator
Expand Down Expand Up @@ -194,7 +194,7 @@ def test_sampler_no_sampling(self):
trace_api.TraceFlags.DEFAULT,
)

@mock.patch.dict("os.environ", {OTEL_TRACE_SAMPLER: "always_off"})
@mock.patch.dict("os.environ", {OTEL_TRACES_SAMPLER: "always_off"})
def test_sampler_with_env(self):
# pylint: disable=protected-access
reload(trace)
Expand All @@ -213,8 +213,8 @@ def test_sampler_with_env(self):
@mock.patch.dict(
"os.environ",
{
OTEL_TRACE_SAMPLER: "parentbased_traceidratio",
OTEL_TRACE_SAMPLER_ARG: "0.25",
OTEL_TRACES_SAMPLER: "parentbased_traceidratio",
OTEL_TRACES_SAMPLER_ARG: "0.25",
},
)
def test_ratio_sampler_with_env(self):
Expand Down