Skip to content

Commit cd3d4b6

Browse files
committed
style: fix error [SIM103] - Return the condition bool(<CONDITION>) directly.
Used Ruff (vscode and pre-commit) to: - Black-compatible code formatting. - fix all auto-fixable violations. - isort-compatible import sorting. - flake8-simplify manual fixes. Signed-off-by: Paulo Vital <paulo.vital@ibm.com>
1 parent f772eb2 commit cd3d4b6

2 files changed

Lines changed: 19 additions & 31 deletions

File tree

src/instana/collector/host.py

Lines changed: 1 addition & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -70,9 +70,7 @@ def prepare_and_report_data(self) -> None:
7070

7171
def should_send_snapshot_data(self) -> bool:
7272
delta = int(time()) - self.snapshot_data_last_sent
73-
if delta > self.snapshot_data_interval:
74-
return True
75-
return False
73+
return delta > self.snapshot_data_interval
7674

7775
def prepare_payload(self) -> DefaultDict[Any, Any]:
7876
payload = DictionaryOfStan()

src/instana/span/stack_trace.py

Lines changed: 18 additions & 28 deletions
Original file line numberDiff line numberDiff line change
@@ -26,54 +26,50 @@
2626
def _should_collect_stack(level: str, is_errored: bool) -> bool:
2727
"""
2828
Determine if stack trace should be collected based on level and error state.
29-
29+
3030
Args:
3131
level: Stack trace collection level ("all", "error", or "none")
3232
is_errored: Whether the span has errors (ec > 0)
33-
33+
3434
Returns:
3535
True if stack trace should be collected, False otherwise
3636
"""
3737
if level == "all":
3838
return True
39-
if level == "error" and is_errored:
40-
return True
41-
return False
39+
return bool(level == "error" and is_errored)
4240

4341

4442
def _should_exclude_frame(frame) -> bool:
4543
"""
4644
Check if a frame should be excluded from the stack trace.
47-
45+
4846
Frames are excluded if they are part of Instana's internal code,
4947
unless INSTANA_DEBUG is set.
50-
48+
5149
Args:
5250
frame: A frame from traceback.extract_stack()
53-
51+
5452
Returns:
5553
True if frame should be excluded, False otherwise
5654
"""
5755
if "INSTANA_DEBUG" in os.environ:
5856
return False
5957
if _re_tracer_frame.search(frame[0]):
6058
return True
61-
if _re_with_stan_frame.search(frame[2]):
62-
return True
63-
return False
59+
return bool(_re_with_stan_frame.search(frame[2]))
6460

6561

6662
def _apply_stack_limit(
6763
sanitized_stack: List[dict], limit: int, use_full_stack: bool
6864
) -> List[dict]:
6965
"""
7066
Apply frame limit to the sanitized stack.
71-
67+
7268
Args:
7369
sanitized_stack: List of stack frames
7470
limit: Maximum number of frames to include
7571
use_full_stack: If True, ignore the limit
76-
72+
7773
Returns:
7874
Limited stack trace
7975
"""
@@ -84,20 +80,18 @@ def _apply_stack_limit(
8480
return sanitized_stack[(limit * -1) :]
8581

8682

87-
def add_stack(
88-
level: str, limit: int, is_errored: bool = False
89-
) -> Optional[List[dict]]:
83+
def add_stack(level: str, limit: int, is_errored: bool = False) -> Optional[List[dict]]:
9084
"""
9185
Capture and return a stack trace based on configuration.
92-
86+
9387
This function collects the current call stack, filters out Instana
9488
internal frames, and applies the configured limit.
95-
89+
9690
Args:
9791
level: Stack trace collection level ("all", "error", or "none")
9892
limit: Maximum number of frames to include (1-40)
9993
is_errored: Whether the span has errors (ec > 0)
100-
94+
10195
Returns:
10296
List of stack frames in format [{"c": file, "n": line, "m": method}, ...]
10397
or None if stack trace should not be collected
@@ -134,25 +128,21 @@ def add_stack(
134128
def add_stack_trace_if_needed(span: "InstanaSpan") -> None:
135129
"""
136130
Add stack trace to span based on configuration before span ends.
137-
131+
138132
This function checks if the span is an EXIT span and if so, captures
139133
a stack trace based on the configured level and limit. It supports
140134
technology-specific configuration overrides via get_stack_trace_config().
141-
135+
142136
Args:
143137
span: The InstanaSpan to potentially add stack trace to
144138
"""
145139
if span.name in EXIT_SPANS:
146140
# Get configuration from agent options (with technology-specific overrides)
147141
options = span._span_processor.agent.options
148142
level, limit = options.get_stack_trace_config(span.name)
149-
143+
150144
# Check if span is errored
151145
is_errored = span.attributes.get("ec", 0) > 0
152-
146+
153147
# Capture stack trace using add_stack function
154-
span.stack = add_stack(
155-
level=level,
156-
limit=limit,
157-
is_errored=is_errored
158-
)
148+
span.stack = add_stack(level=level, limit=limit, is_errored=is_errored)

0 commit comments

Comments
 (0)