19
19
from os import environ , execl , getcwd
20
20
from os .path import abspath , dirname , pathsep
21
21
from shutil import which
22
+ from re import sub
22
23
23
24
from pkg_resources import iter_entry_points
24
25
@@ -31,10 +32,22 @@ def run() -> None:
31
32
description = """
32
33
opentelemetry-instrument automatically instruments a Python
33
34
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.
34
47
"""
35
48
)
36
49
37
- otel_environment_variables = []
50
+ argument_otel_environment_variable = {}
38
51
39
52
for entry_point in iter_entry_points (
40
53
"opentelemetry_environment_variables"
@@ -45,11 +58,13 @@ def run() -> None:
45
58
46
59
if attribute .startswith ("OTEL_" ):
47
60
61
+ argument = sub (r"OTEL_(PYTHON_)?" , "" , attribute ).lower ()
62
+
48
63
parser .add_argument (
49
- f" --{ attribute } " ,
64
+ f' --{ argument } ' ,
50
65
required = False ,
51
66
)
52
- otel_environment_variables . append ( attribute )
67
+ argument_otel_environment_variable [ argument ] = attribute
53
68
54
69
parser .add_argument ("command" , help = "Your Python application." )
55
70
parser .add_argument (
@@ -60,8 +75,10 @@ def run() -> None:
60
75
61
76
args = parser .parse_args ()
62
77
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 )
65
82
if value is not None :
66
83
67
84
environ [otel_environment_variable ] = value
0 commit comments