From 0dead19bffeb6cc86dfe101ce236c62b4bbceed4 Mon Sep 17 00:00:00 2001 From: Diego Hurtado Date: Wed, 25 Aug 2021 17:43:54 +0200 Subject: [PATCH] WIP --- .../auto_instrumentation/__init__.py | 59 ++++++------------- 1 file changed, 19 insertions(+), 40 deletions(-) diff --git a/opentelemetry-instrumentation/src/opentelemetry/instrumentation/auto_instrumentation/__init__.py b/opentelemetry-instrumentation/src/opentelemetry/instrumentation/auto_instrumentation/__init__.py index cbacac0238f..5f7e734f5d1 100644 --- a/opentelemetry-instrumentation/src/opentelemetry/instrumentation/auto_instrumentation/__init__.py +++ b/opentelemetry-instrumentation/src/opentelemetry/instrumentation/auto_instrumentation/__init__.py @@ -20,20 +20,10 @@ from os import environ, execl, getcwd from os.path import abspath, dirname, pathsep from shutil import which +from pkg_resources import iter_entry_points -from opentelemetry.environment_variables import ( - OTEL_PYTHON_ID_GENERATOR, - OTEL_TRACES_EXPORTER, -) -logger = getLogger(__file__) - - -def load_config_from_cli_args(args): - if args.trace_exporter: - environ[OTEL_TRACES_EXPORTER] = args.trace_exporter - if args.id_generator: - environ[OTEL_PYTHON_ID_GENERATOR] = args.id_generator +_logger = getLogger(__file__) def run() -> None: @@ -45,41 +35,30 @@ def run() -> None: """ ) - parser.add_argument( - "--trace-exporter", - required=False, - help=""" - Uses the specified exporter to export spans. - Accepts multiple exporters as comma separated values. - - Examples: - - --trace-exporter=jaeger - """, - ) + otel_environment_variables = [] - parser.add_argument( - "--id-generator", - required=False, - help=""" - The IDs Generator to be used with the Tracer Provider. + for entry_point in iter_entry_points( + "opentelemetry_environment_variables" + ): + environment_variable_module = entry_point.load() - Examples: + for attribute in dir(environment_variable_module): - --id-generator=random - """, - ) + if attribute.startswith("OTEL_"): - parser.add_argument("command", help="Your Python application.") - parser.add_argument( - "command_args", - help="Arguments for your application.", - nargs=argparse.REMAINDER, - ) + parser.add_argument( + f"--{attribute}", + required=False, + ) + otel_environment_variables.append(attribute) args = parser.parse_args() - load_config_from_cli_args(args) + for otel_environment_variable in otel_environment_variables: + value = getattr(args, otel_environment_variable) + if value is not None: + + environ[otel_environment_variable] = value python_path = environ.get("PYTHONPATH")