Skip to content

Commit

Permalink
Use env var constants
Browse files Browse the repository at this point in the history
  • Loading branch information
pmcollins committed Nov 18, 2024
1 parent d759f5a commit dfdad0f
Show file tree
Hide file tree
Showing 3 changed files with 11 additions and 13 deletions.
4 changes: 2 additions & 2 deletions src/splunk_otel/configurator.py
Original file line number Diff line number Diff line change
Expand Up @@ -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()
12 changes: 6 additions & 6 deletions src/splunk_otel/distro.py
Original file line number Diff line number Diff line change
Expand Up @@ -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,
)
Expand Down Expand Up @@ -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()
Expand Down
8 changes: 3 additions & 5 deletions src/splunk_otel/profile.py
Original file line number Diff line number Diff line change
Expand Up @@ -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="<YOUR_SERVICE_NAME_HERE>"`"""
_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="<YOUR_SERVICE_NAME_HERE>"`"""
_DEFAULT_SERVICE_NAME = "unnamed-python-service"

_profile_timer = None
Expand Down

0 comments on commit dfdad0f

Please sign in to comment.