Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

V2 profiling #541

Merged
merged 14 commits into from
Nov 19, 2024
4 changes: 4 additions & 0 deletions pyproject.toml
Original file line number Diff line number Diff line change
Expand Up @@ -101,3 +101,7 @@ exclude_lines = [
"if __name__ == .__main__.:",
"if TYPE_CHECKING:",
]

[tool.ruff.lint]
ignore = ["FA100", "ARG002"]
exclude = ["src/splunk_otel/profile_pb2.py"]
8 changes: 7 additions & 1 deletion src/splunk_otel/configurator.py
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,12 @@

from opentelemetry.sdk._configuration import _OTelSDKConfigurator

from splunk_otel.env import SPLUNK_PROFILER_ENABLED, Env
from splunk_otel.profile import start_profiling


class SplunkConfigurator(_OTelSDKConfigurator):
pass
def _configure(self, **kwargs):
super()._configure(**kwargs)
if Env().is_true(SPLUNK_PROFILER_ENABLED):
start_profiling()
14 changes: 11 additions & 3 deletions src/splunk_otel/distro.py
Original file line number Diff line number Diff line change
Expand Up @@ -21,15 +21,17 @@

from splunk_otel.env import (
DEFAULTS,
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,
)
from splunk_otel.propagator import ServerTimingResponsePropagator

X_SF_TOKEN = "x-sf-token" # noqa S105


class SplunkDistro(BaseDistro):
"""
Expand All @@ -41,15 +43,21 @@ def __init__(self):
self.env = Env()
self.logger = logging.getLogger(__name__)

def _configure(self, **kwargs): # noqa: ARG002
def _configure(self, **kwargs):
self.set_env_defaults()
self.set_profiling_env()
self.configure_headers()
self.set_server_timing_propagator()

def set_env_defaults(self):
for key, value in DEFAULTS.items():
self.env.setdefault(key, value)

def set_profiling_env(self):
if self.env.is_true(SPLUNK_PROFILER_ENABLED):
pmcollins marked this conversation as resolved.
Show resolved Hide resolved
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()
if tok:
Expand Down
11 changes: 9 additions & 2 deletions src/splunk_otel/env.py
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,7 @@
"OTEL_PYTHON_LOG_CORRELATION": "true", # FIXME: revisit
"OTEL_TRACES_EXPORTER": "otlp",
"OTEL_METRICS_EXPORTER": "otlp",
"OTEL_LOGS_EXPORTER": "otlp",
"OTEL_EXPORTER_OTLP_PROTOCOL": "grpc", # FIXME: revisit
"OTEL_ATTRIBUTE_COUNT_LIMIT": "",
"OTEL_SPAN_ATTRIBUTE_COUNT_LIMIT": "",
Expand All @@ -28,11 +29,17 @@
"OTEL_ATTRIBUTE_VALUE_LENGTH_LIMIT": "12000",
}

OTEL_TRACE_ENABLED = "OTEL_TRACE_ENABLED"
OTEL_METRICS_ENABLED = "OTEL_METRICS_ENABLED"
OTEL_LOGS_ENABLED = "OTEL_LOGS_ENABLED"
OTEL_PYTHON_LOGGING_AUTO_INSTRUMENTATION_ENABLED = "OTEL_PYTHON_LOGGING_AUTO_INSTRUMENTATION_ENABLED"

SPLUNK_OTEL_SYSTEM_METRICS_ENABLED = "SPLUNK_OTEL_SYSTEM_METRICS_ENABLED"
SPLUNK_ACCESS_TOKEN = "SPLUNK_ACCESS_TOKEN" # noqa: S105
SPLUNK_TRACE_RESPONSE_HEADER_ENABLED = "SPLUNK_TRACE_RESPONSE_HEADER_ENABLED"
SPLUNK_PROFILER_ENABLED = "SPLUNK_PROFILER_ENABLED"

OTEL_METRICS_ENABLED = "OTEL_METRICS_ENABLED"
X_SF_TOKEN = "x-sf-token" # noqa S105


class Env:
Expand All @@ -45,7 +52,7 @@ def __init__(self, store=None):
self.store = os.environ if store is None else store

def is_true(self, key, default=""):
return is_true_str(self.getval(key, default).strip())
return is_true_str(self.getval(key, default))

def list_append(self, key, value):
curr = self.getval(key)
Expand Down
Loading
Loading