Skip to content

Commit

Permalink
rename call_stack_interval to call_stack_interval_millis
Browse files Browse the repository at this point in the history
  • Loading branch information
seemk committed Nov 9, 2023
1 parent b437ec4 commit 463699d
Show file tree
Hide file tree
Showing 3 changed files with 18 additions and 17 deletions.
10 changes: 5 additions & 5 deletions splunk_otel/profiling/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -257,7 +257,7 @@ def _to_log_record(

def _profiler_loop(profiler: Profiler):
options = profiler.options
call_stack_interval_millis = options.call_stack_interval
call_stack_interval_millis = options.call_stack_interval_millis

ignored_thread_ids = _get_ignored_thread_ids(
profiler.batch_processor, include_internal_stacks=options.include_internal_stacks
Expand Down Expand Up @@ -361,8 +361,8 @@ def _start_profiling(options):
_profiler.running = True

logger.debug(
"starting profiling call_stack_interval=%s endpoint=%s",
options.call_stack_interval,
"starting profiling call_stack_interval_millis=%s endpoint=%s",
options.call_stack_interval_millis,
options.endpoint,
)
wrapt.wrap_function_wrapper(opentelemetry.context, "attach", _wrapped_context_attach)
Expand All @@ -380,13 +380,13 @@ def start_profiling(
service_name: Optional[str] = None,
resource_attributes: Optional[Dict[str, Union[str, bool, int, float]]] = None,
endpoint: Optional[str] = None,
call_stack_interval: Optional[int] = None,
call_stack_interval_millis: Optional[int] = None,
):
# pylint: disable-next=protected-access
resource = splunk_otel.options._Options._get_resource(
service_name, resource_attributes
)
options = _Options(resource, endpoint, call_stack_interval)
options = _Options(resource, endpoint, call_stack_interval_millis)
_start_profiling(options)


Expand Down
21 changes: 11 additions & 10 deletions splunk_otel/profiling/options.py
Original file line number Diff line number Diff line change
Expand Up @@ -21,8 +21,7 @@
from splunk_otel.util import _is_truthy

logger = logging.getLogger(__name__)
_DEFAULT_CALL_STACK_INTERVAL = 1_000
_DEFAULT_INCLUDE_INTERNAL_STACKS = False
_DEFAULT_CALL_STACK_INTERVAL_MILLIS = 1_000


def _sanitize_interval(interval):
Expand All @@ -31,34 +30,36 @@ def _sanitize_interval(interval):
logger.warning(
"call stack interval has to be positive, got %s, defaulting to %s",
interval,
_DEFAULT_CALL_STACK_INTERVAL,
_DEFAULT_CALL_STACK_INTERVAL_MILLIS,
)
return _DEFAULT_CALL_STACK_INTERVAL
return _DEFAULT_CALL_STACK_INTERVAL_MILLIS

return interval

logger.warning(
"call stack interval not an integer, defaulting to %s",
_DEFAULT_CALL_STACK_INTERVAL,
_DEFAULT_CALL_STACK_INTERVAL_MILLIS,
)
return _DEFAULT_CALL_STACK_INTERVAL
return _DEFAULT_CALL_STACK_INTERVAL_MILLIS


class _Options:
resource: Resource
endpoint: str
call_stack_interval: int
call_stack_interval_millis: int

def __init__(
self,
resource: Resource,
endpoint: Optional[str] = None,
call_stack_interval: Optional[int] = None,
call_stack_interval_millis: Optional[int] = None,
include_internal_stacks: Optional[bool] = None,
):
self.resource = resource
self.endpoint = _Options._get_endpoint(endpoint)
self.call_stack_interval = _Options._get_call_stack_interval(call_stack_interval)
self.call_stack_interval_millis = _Options._get_call_stack_interval(
call_stack_interval_millis
)
self.include_internal_stacks = _Options._include_internal_stacks(
include_internal_stacks
)
Expand All @@ -81,7 +82,7 @@ def _get_call_stack_interval(interval: Optional[int]) -> int:
if interval:
return _sanitize_interval(int(interval))

return _DEFAULT_CALL_STACK_INTERVAL
return _DEFAULT_CALL_STACK_INTERVAL_MILLIS

return _sanitize_interval(interval)

Expand Down
4 changes: 2 additions & 2 deletions tests/unit/test_profiling.py
Original file line number Diff line number Diff line change
Expand Up @@ -93,7 +93,7 @@ def tearDown(self):
def profile_capture_thread_ids(self):
start_profiling(
service_name="prof-thread-filter",
call_stack_interval=10,
call_stack_interval_millis=10,
)

do_work(100)
Expand Down Expand Up @@ -180,7 +180,7 @@ def test_profiling_export(self):
start_profiling(
service_name="prof-export-test",
resource_attributes={"foo": "bar"},
call_stack_interval=100,
call_stack_interval_millis=100,
)

with tracer.start_as_current_span("add-some-numbers") as span:
Expand Down

0 comments on commit 463699d

Please sign in to comment.