Skip to content

Commit 8ff4c0a

Browse files
committed
Add requested changes
1 parent 023eb0f commit 8ff4c0a

File tree

2 files changed

+23
-6
lines changed
  • opentelemetry-instrumentation

2 files changed

+23
-6
lines changed

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

Lines changed: 22 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -19,6 +19,7 @@
1919
from os import environ, execl, getcwd
2020
from os.path import abspath, dirname, pathsep
2121
from shutil import which
22+
from re import sub
2223

2324
from pkg_resources import iter_entry_points
2425

@@ -31,10 +32,22 @@ def run() -> None:
3132
description="""
3233
opentelemetry-instrument automatically instruments a Python
3334
program and its dependencies and then runs the program.
35+
""",
36+
epilog="""
37+
Optional arguments (except for --help) for opentelemetry-instrument
38+
directly correspond with OpenTelemetry environment variables. The
39+
corresponding optional argument is formed by removing the OTEL_ or
40+
OTEL_PYTHON_ prefix from the environment variable and lower casing the
41+
rest. For example, the optional argument --attribute_value_length_limit
42+
corresponds with the environment variable
43+
OTEL_ATTRIBUTE_VALUE_LENGTH_LIMIT.
44+
45+
These optional arguments will override the current value of the
46+
corresponding environment variable during the execution of the command.
3447
"""
3548
)
3649

37-
otel_environment_variables = []
50+
argument_otel_environment_variable = {}
3851

3952
for entry_point in iter_entry_points(
4053
"opentelemetry_environment_variables"
@@ -45,11 +58,13 @@ def run() -> None:
4558

4659
if attribute.startswith("OTEL_"):
4760

61+
argument = sub(r"OTEL_(PYTHON_)?", "", attribute).lower()
62+
4863
parser.add_argument(
49-
f"--{attribute}",
64+
f'--{argument}',
5065
required=False,
5166
)
52-
otel_environment_variables.append(attribute)
67+
argument_otel_environment_variable[argument] = attribute
5368

5469
parser.add_argument("command", help="Your Python application.")
5570
parser.add_argument(
@@ -60,8 +75,10 @@ def run() -> None:
6075

6176
args = parser.parse_args()
6277

63-
for otel_environment_variable in otel_environment_variables:
64-
value = getattr(args, otel_environment_variable)
78+
for argument, otel_environment_variable in (
79+
argument_otel_environment_variable
80+
).items():
81+
value = getattr(args, argument)
6582
if value is not None:
6683

6784
environ[otel_environment_variable] = value

opentelemetry-instrumentation/tests/test_run.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -112,7 +112,7 @@ def test_exporter(self, _): # pylint: disable=no-self-use
112112

113113
with patch(
114114
"sys.argv",
115-
["instrument", "--OTEL_TRACES_EXPORTER", "jaeger", "1", "2"],
115+
["instrument", "--traces_exporter", "jaeger", "1", "2"],
116116
):
117117
auto_instrumentation.run()
118118
self.assertEqual(environ.get(OTEL_TRACES_EXPORTER), "jaeger")

0 commit comments

Comments
 (0)