From dfdad0fc95254e04687ca1fe95f715a25e92d0f8 Mon Sep 17 00:00:00 2001 From: Pablo Collins Date: Mon, 18 Nov 2024 09:44:57 -0500 Subject: [PATCH] Use env var constants --- src/splunk_otel/configurator.py | 4 ++-- src/splunk_otel/distro.py | 12 ++++++------ src/splunk_otel/profile.py | 8 +++----- 3 files changed, 11 insertions(+), 13 deletions(-) diff --git a/src/splunk_otel/configurator.py b/src/splunk_otel/configurator.py index 0741273..39df2e0 100644 --- a/src/splunk_otel/configurator.py +++ b/src/splunk_otel/configurator.py @@ -14,12 +14,12 @@ from opentelemetry.sdk._configuration import _OTelSDKConfigurator -from splunk_otel.env import Env +from splunk_otel.env import Env, SPLUNK_PROFILER_ENABLED from splunk_otel.profile import start_profiling class SplunkConfigurator(_OTelSDKConfigurator): def _configure(self, **kwargs): super()._configure(**kwargs) - if Env().is_true("SPLUNK_PROFILER_ENABLED"): + if Env().is_true(SPLUNK_PROFILER_ENABLED): start_profiling() diff --git a/src/splunk_otel/distro.py b/src/splunk_otel/distro.py index c91520a..c55bb92 100644 --- a/src/splunk_otel/distro.py +++ b/src/splunk_otel/distro.py @@ -21,9 +21,9 @@ from splunk_otel.env import ( DEFAULTS, - OTEL_METRICS_ENABLED, - SPLUNK_ACCESS_TOKEN, - SPLUNK_TRACE_RESPONSE_HEADER_ENABLED, + OTEL_LOGS_ENABLED, OTEL_METRICS_ENABLED, + OTEL_PYTHON_LOGGING_AUTO_INSTRUMENTATION_ENABLED, SPLUNK_ACCESS_TOKEN, + SPLUNK_PROFILER_ENABLED, SPLUNK_TRACE_RESPONSE_HEADER_ENABLED, X_SF_TOKEN, Env, ) @@ -51,9 +51,9 @@ def set_env_defaults(self): self.env.setdefault(key, value) def set_profiling_env(self): - if self.env.is_true("SPLUNK_PROFILER_ENABLED"): - self.env.setdefault("OTEL_LOGS_ENABLED", "true") - self.env.setdefault("OTEL_PYTHON_LOGGING_AUTO_INSTRUMENTATION_ENABLED", "true") + if self.env.is_true(SPLUNK_PROFILER_ENABLED): + self.env.setdefault(OTEL_LOGS_ENABLED, "true") + self.env.setdefault(OTEL_PYTHON_LOGGING_AUTO_INSTRUMENTATION_ENABLED, "true") def configure_headers(self): tok = self.env.getval(SPLUNK_ACCESS_TOKEN).strip() diff --git a/src/splunk_otel/profile.py b/src/splunk_otel/profile.py index e0fc44b..5430b82 100644 --- a/src/splunk_otel/profile.py +++ b/src/splunk_otel/profile.py @@ -22,12 +22,10 @@ from splunk_otel.env import Env _SERVICE_NAME_ATTR = "service.name" - _SPLUNK_DISTRO_VERSION_ATTR = "splunk.distro.version" -_DEFAULT_OTEL_SERVICE_NAME = "unknown_service" -_NO_SERVICE_NAME_WARNING = """service.name attribute is not set, your service is unnamed and will be difficult to identify. -set your service name using the OTEL_SERVICE_NAME environment variable. -E.g. `OTEL_SERVICE_NAME=""`""" +_NO_SERVICE_NAME_WARNING = """The service.name attribute is not set, which may make your service difficult to identify. +Set your service name using the OTEL_SERVICE_NAME environment variable. +e.g. `OTEL_SERVICE_NAME=""`""" _DEFAULT_SERVICE_NAME = "unnamed-python-service" _profile_timer = None