Skip to content

Commit 84b1b0c

Browse files
authored
Rename env vars from OTEL_TRACE -> OTEL_TRACES (#1595)
1 parent 59f5bab commit 84b1b0c

File tree

9 files changed

+30
-28
lines changed

9 files changed

+30
-28
lines changed

CHANGELOG.md

+2
Original file line numberDiff line numberDiff line change
@@ -9,6 +9,8 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0
99
### Changed
1010
- Tracer and Meter provider environment variables are now consistent with the rest
1111
([#1571](https://github.com/open-telemetry/opentelemetry-python/pull/1571)])
12+
- Rename `TRACE_` to `TRACES_` for environment variables
13+
([#1595](https://github.com/open-telemetry/opentelemetry-python/pull/1595)])
1214

1315
### Added
1416
- Added `end_on_exit` argument to `start_as_current_span`

opentelemetry-api/src/opentelemetry/environment_variables/__init__.py

+1-1
Original file line numberDiff line numberDiff line change
@@ -17,5 +17,5 @@
1717
OTEL_PYTHON_DISABLED_INSTRUMENTATIONS = "OTEL_PYTHON_DISABLED_INSTRUMENTATIONS"
1818
OTEL_PYTHON_IDS_GENERATOR = "OTEL_PYTHON_IDS_GENERATOR"
1919
OTEL_PYTHON_SERVICE_NAME = "OTEL_PYTHON_SERVICE_NAME"
20-
OTEL_TRACE_EXPORTER = "OTEL_TRACE_EXPORTER"
20+
OTEL_TRACES_EXPORTER = "OTEL_TRACES_EXPORTER"
2121
OTEL_PYTHON_TRACER_PROVIDER = "OTEL_PYTHON_TRACER_PROVIDER"

opentelemetry-distro/src/opentelemetry/distro/__init__.py

+3-3
Original file line numberDiff line numberDiff line change
@@ -23,7 +23,7 @@
2323
from opentelemetry.environment_variables import (
2424
OTEL_PYTHON_IDS_GENERATOR,
2525
OTEL_PYTHON_SERVICE_NAME,
26-
OTEL_TRACE_EXPORTER,
26+
OTEL_TRACES_EXPORTER,
2727
)
2828
from opentelemetry.instrumentation.configurator import BaseConfigurator
2929
from opentelemetry.instrumentation.distro import BaseDistro
@@ -54,7 +54,7 @@ def _get_service_name() -> str:
5454

5555

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

5959
exporters = set()
6060

@@ -175,4 +175,4 @@ class OpenTelemetryDistro(BaseDistro):
175175
"""
176176

177177
def _configure(self, **kwargs):
178-
os.environ.setdefault(OTEL_TRACE_EXPORTER, "otlp_span")
178+
os.environ.setdefault(OTEL_TRACES_EXPORTER, "otlp_span")

opentelemetry-distro/tests/test_distro.py

+3-3
Original file line numberDiff line numberDiff line change
@@ -19,7 +19,7 @@
1919
from pkg_resources import DistributionNotFound, require
2020

2121
from opentelemetry.distro import OpenTelemetryDistro
22-
from opentelemetry.environment_variables import OTEL_TRACE_EXPORTER
22+
from opentelemetry.environment_variables import OTEL_TRACES_EXPORTER
2323

2424

2525
class TestDistribution(TestCase):
@@ -31,6 +31,6 @@ def test_package_available(self):
3131

3232
def test_default_configuration(self):
3333
distro = OpenTelemetryDistro()
34-
self.assertIsNone(os.environ.get(OTEL_TRACE_EXPORTER))
34+
self.assertIsNone(os.environ.get(OTEL_TRACES_EXPORTER))
3535
distro.configure()
36-
self.assertEqual("otlp_span", os.environ.get(OTEL_TRACE_EXPORTER))
36+
self.assertEqual("otlp_span", os.environ.get(OTEL_TRACES_EXPORTER))

opentelemetry-instrumentation/src/opentelemetry/instrumentation/auto_instrumentation/__init__.py

+2-2
Original file line numberDiff line numberDiff line change
@@ -23,7 +23,7 @@
2323
from opentelemetry.environment_variables import (
2424
OTEL_PYTHON_IDS_GENERATOR,
2525
OTEL_PYTHON_SERVICE_NAME,
26-
OTEL_TRACE_EXPORTER,
26+
OTEL_TRACES_EXPORTER,
2727
)
2828

2929
logger = getLogger(__file__)
@@ -82,7 +82,7 @@ def parse_args():
8282

8383
def load_config_from_cli_args(args):
8484
if args.trace_exporter:
85-
environ[OTEL_TRACE_EXPORTER] = args.trace_exporter
85+
environ[OTEL_TRACES_EXPORTER] = args.trace_exporter
8686
if args.service_name:
8787
environ[OTEL_PYTHON_SERVICE_NAME] = args.service_name
8888
if args.ids_generator:

opentelemetry-instrumentation/tests/test_run.py

+3-3
Original file line numberDiff line numberDiff line change
@@ -20,7 +20,7 @@
2020

2121
from opentelemetry.environment_variables import (
2222
OTEL_PYTHON_SERVICE_NAME,
23-
OTEL_TRACE_EXPORTER,
23+
OTEL_TRACES_EXPORTER,
2424
)
2525
from opentelemetry.instrumentation import auto_instrumentation
2626

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

116116
with patch(
117117
"sys.argv", ["instrument", "--trace-exporter", "jaeger", "1", "2"]
118118
):
119119
auto_instrumentation.run()
120-
self.assertEqual(environ.get(OTEL_TRACE_EXPORTER), "jaeger")
120+
self.assertEqual(environ.get(OTEL_TRACES_EXPORTER), "jaeger")
121121

122122
@patch("opentelemetry.instrumentation.auto_instrumentation.execl")
123123
def test_service_name(self, _): # pylint: disable=no-self-use

opentelemetry-sdk/src/opentelemetry/sdk/environment_variables/__init__.py

+2-2
Original file line numberDiff line numberDiff line change
@@ -14,8 +14,8 @@
1414

1515
OTEL_RESOURCE_ATTRIBUTES = "OTEL_RESOURCE_ATTRIBUTES"
1616
OTEL_LOG_LEVEL = "OTEL_LOG_LEVEL"
17-
OTEL_TRACE_SAMPLER = "OTEL_TRACE_SAMPLER"
18-
OTEL_TRACE_SAMPLER_ARG = "OTEL_TRACE_SAMPLER_ARG"
17+
OTEL_TRACES_SAMPLER = "OTEL_TRACES_SAMPLER"
18+
OTEL_TRACES_SAMPLER_ARG = "OTEL_TRACES_SAMPLER_ARG"
1919
OTEL_BSP_SCHEDULE_DELAY = "OTEL_BSP_SCHEDULE_DELAY"
2020
OTEL_BSP_EXPORT_TIMEOUT = "OTEL_BSP_EXPORT_TIMEOUT"
2121
OTEL_BSP_MAX_QUEUE_SIZE = "OTEL_BSP_MAX_QUEUE_SIZE"

opentelemetry-sdk/src/opentelemetry/sdk/trace/sampling.py

+9-9
Original file line numberDiff line numberDiff line change
@@ -60,8 +60,8 @@
6060
with trace.get_tracer(__name__).start_as_current_span("Test Span"):
6161
...
6262
63-
The tracer sampler can also be configured via environment variables ``OTEL_TRACE_SAMPLER`` and ``OTEL_TRACE_SAMPLER_ARG`` (only if applicable).
64-
The list of known values for ``OTEL_TRACE_SAMPLER`` are:
63+
The tracer sampler can also be configured via environment variables ``OTEL_TRACES_SAMPLER`` and ``OTEL_TRACES_SAMPLER_ARG`` (only if applicable).
64+
The list of known values for ``OTEL_TRACES_SAMPLER`` are:
6565
6666
* always_on - Sampler that always samples spans, regardless of the parent span's sampling decision.
6767
* always_off - Sampler that never samples spans, regardless of the parent span's sampling decision.
@@ -70,10 +70,10 @@
7070
* parentbased_always_off - Sampler that respects its parent span's sampling decision, but otherwise never samples.
7171
* parentbased_traceidratio - Sampler that respects its parent span's sampling decision, but otherwise samples probabalistically based on rate.
7272
73-
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).
73+
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).
7474
7575
76-
Prev example but with environment vairables. Please make sure to set the env ``OTEL_TRACE_SAMPLER=traceidratio`` and ``OTEL_TRACE_SAMPLER_ARG=0.001``.
76+
Prev example but with environment vairables. Please make sure to set the env ``OTEL_TRACES_SAMPLER=traceidratio`` and ``OTEL_TRACES_SAMPLER_ARG=0.001``.
7777
7878
.. code:: python
7979
@@ -105,8 +105,8 @@
105105
# pylint: disable=unused-import
106106
from opentelemetry.context import Context
107107
from opentelemetry.sdk.environment_variables import (
108-
OTEL_TRACE_SAMPLER,
109-
OTEL_TRACE_SAMPLER_ARG,
108+
OTEL_TRACES_SAMPLER,
109+
OTEL_TRACES_SAMPLER_ARG,
110110
)
111111
from opentelemetry.trace import Link, get_current_span
112112
from opentelemetry.trace.span import TraceState
@@ -370,17 +370,17 @@ def __init__(self, rate: float):
370370

371371
def _get_from_env_or_default() -> Sampler:
372372
trace_sampler = os.getenv(
373-
OTEL_TRACE_SAMPLER, "parentbased_always_on"
373+
OTEL_TRACES_SAMPLER, "parentbased_always_on"
374374
).lower()
375375
if trace_sampler not in _KNOWN_SAMPLERS:
376376
_logger.warning("Couldn't recognize sampler %s.", trace_sampler)
377377
trace_sampler = "parentbased_always_on"
378378

379379
if trace_sampler in ("traceidratio", "parentbased_traceidratio"):
380380
try:
381-
rate = float(os.getenv(OTEL_TRACE_SAMPLER_ARG))
381+
rate = float(os.getenv(OTEL_TRACES_SAMPLER_ARG))
382382
except ValueError:
383-
_logger.warning("Could not convert TRACE_SAMPLER_ARG to float.")
383+
_logger.warning("Could not convert TRACES_SAMPLER_ARG to float.")
384384
rate = 1.0
385385
return _KNOWN_SAMPLERS[trace_sampler](rate)
386386

opentelemetry-sdk/tests/trace/test_trace.py

+5-5
Original file line numberDiff line numberDiff line change
@@ -30,8 +30,8 @@
3030
OTEL_SPAN_ATTRIBUTE_COUNT_LIMIT,
3131
OTEL_SPAN_EVENT_COUNT_LIMIT,
3232
OTEL_SPAN_LINK_COUNT_LIMIT,
33-
OTEL_TRACE_SAMPLER,
34-
OTEL_TRACE_SAMPLER_ARG,
33+
OTEL_TRACES_SAMPLER,
34+
OTEL_TRACES_SAMPLER_ARG,
3535
)
3636
from opentelemetry.sdk.trace import Resource, sampling
3737
from opentelemetry.sdk.trace.ids_generator import RandomIdsGenerator
@@ -194,7 +194,7 @@ def test_sampler_no_sampling(self):
194194
trace_api.TraceFlags.DEFAULT,
195195
)
196196

197-
@mock.patch.dict("os.environ", {OTEL_TRACE_SAMPLER: "always_off"})
197+
@mock.patch.dict("os.environ", {OTEL_TRACES_SAMPLER: "always_off"})
198198
def test_sampler_with_env(self):
199199
# pylint: disable=protected-access
200200
reload(trace)
@@ -213,8 +213,8 @@ def test_sampler_with_env(self):
213213
@mock.patch.dict(
214214
"os.environ",
215215
{
216-
OTEL_TRACE_SAMPLER: "parentbased_traceidratio",
217-
OTEL_TRACE_SAMPLER_ARG: "0.25",
216+
OTEL_TRACES_SAMPLER: "parentbased_traceidratio",
217+
OTEL_TRACES_SAMPLER_ARG: "0.25",
218218
},
219219
)
220220
def test_ratio_sampler_with_env(self):

0 commit comments

Comments
 (0)