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

refactor(di): encapsulate common signal code #11153

Open
wants to merge 1 commit into
base: main
Choose a base branch
from

Conversation

P403n1x87
Copy link
Contributor

We encapsulate common signal boilerplate code to simplify the coding of signals and ensure homogeneous behaviour among them.

Checklist

  • PR author has checked that all the criteria below are met
  • The PR description includes an overview of the change
  • The PR description articulates the motivation for the change
  • The change includes tests OR the PR description describes a testing strategy
  • The PR description notes risks associated with the change, if any
  • Newly-added code is easy to change
  • The change follows the library release note guidelines
  • The change includes or references documentation updates if necessary
  • Backport labels are set (if applicable)

Reviewer Checklist

  • Reviewer has checked that all the criteria below are met
  • Title is accurate
  • All changes are related to the pull request's stated goal
  • Avoids breaking API changes
  • Testing strategy adequately addresses listed risks
  • Newly-added code is easy to change
  • Release note makes sense to a user of the library
  • If necessary, author has acknowledged and discussed the performance implications of this PR as reported in the benchmarks PR comment
  • Backport labels are set in a manner that is consistent with the release branch maintenance policy

@P403n1x87 P403n1x87 added changelog/no-changelog A changelog entry is not required for this PR. Dynamic Instrumentation Dynamic Instrumentation/Live Debugger labels Oct 24, 2024
@P403n1x87 P403n1x87 self-assigned this Oct 24, 2024
@P403n1x87 P403n1x87 force-pushed the refactor/probe-management-boilerplate branch 2 times, most recently from 397d10d to ee8aa65 Compare October 24, 2024 10:57
Copy link
Contributor

github-actions bot commented Oct 24, 2024

CODEOWNERS have been resolved as:

ddtrace/debugging/_signal/context.py                                    @DataDog/debugger-python
ddtrace/debugging/_debugger.py                                          @DataDog/debugger-python
ddtrace/debugging/_exception/replay.py                                  @DataDog/debugger-python
ddtrace/debugging/_expressions.py                                       @DataDog/debugger-python
ddtrace/debugging/_origin/span.py                                       @DataDog/debugger-python
ddtrace/debugging/_probe/model.py                                       @DataDog/debugger-python
ddtrace/debugging/_probe/remoteconfig.py                                @DataDog/debugger-python
ddtrace/debugging/_signal/collector.py                                  @DataDog/debugger-python
ddtrace/debugging/_signal/metric_sample.py                              @DataDog/debugger-python
ddtrace/debugging/_signal/model.py                                      @DataDog/debugger-python
ddtrace/debugging/_signal/snapshot.py                                   @DataDog/debugger-python
ddtrace/debugging/_signal/tracing.py                                    @DataDog/debugger-python
tests/debugging/probe/test_remoteconfig.py                              @DataDog/debugger-python
tests/debugging/signal/test_collector.py                                @DataDog/debugger-python
tests/debugging/signal/test_model.py                                    @DataDog/debugger-python
tests/debugging/test_debugger.py                                        @DataDog/debugger-python
tests/debugging/test_debugger_span_decoration.py                        @DataDog/debugger-python
tests/debugging/test_encoding.py                                        @DataDog/debugger-python
tests/debugging/utils.py                                                @DataDog/debugger-python

@pr-commenter
Copy link

pr-commenter bot commented Oct 24, 2024

Benchmarks

Benchmark execution time: 2024-10-24 15:35:54

Comparing candidate commit 1d33870 in PR branch refactor/probe-management-boilerplate with baseline commit 26ad98b in branch main.

Found 0 performance improvements and 0 performance regressions! Performance is the same for 365 metrics, 53 unstable metrics.

@P403n1x87 P403n1x87 force-pushed the refactor/probe-management-boilerplate branch from ee8aa65 to 29823fb Compare October 24, 2024 14:26
We encapsulate common signal boilerplate code to simplify the coding of
signals and ensure homogeneous behaviour among them.
@P403n1x87 P403n1x87 force-pushed the refactor/probe-management-boilerplate branch from 29823fb to 1d33870 Compare October 24, 2024 14:50
@P403n1x87 P403n1x87 marked this pull request as ready for review October 24, 2024 14:57
@P403n1x87 P403n1x87 requested a review from a team as a code owner October 24, 2024 14:57
Copy link
Contributor

@shatzi shatzi left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Awesome stuff man!!!

I would like to see everything encapsulated under SignalContext, and remove the last few places like in debugger.py that still check for RateLimit and Condtion Mixins.

ddtrace/debugging/_expressions.py Show resolved Hide resolved
@@ -188,7 +190,9 @@ def on_span_exception(
)

# Capture
snapshot.line()
snapshot.line(ChainMap(frame.f_locals, frame.f_globals))
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

we call this ChainMap multiple locations - I think it better to have an util method e.g; createScopeFromFrame(frame) -> to avoid problems down the line if we decide to limit or remove globals...

or maybe line() should just get the frame object instead.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The arguments are all different so I don't think we can make a single helper in this case 🙁

DEFAULT = "DEFAULT"
ENTER = "ENTER"
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

scary...

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The RFC mentions ENTRY as accepted value so I'm aligning with that

self._timing = ProbeEvalTiming.ENTRY

probe = signal.probe
if isinstance(probe, TimingMixin):
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

nit: would easier to read if there is else under this if with self._timing = ProbeEvalTiming.ENTRY


scope = ChainMap(signal.args, signal.frame.f_globals)
if isinstance(probe, ProbeConditionMixin) and not signal._eval_condition(scope):
return
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

if this is a bug?

we can have a probe with a condition, the condition is false. it return without setting signal.state
at the exit() - we check if signal == None - go ahead and capture.

so, probe with eval==ENTRY will capture always on exit. I think we should mark this as SKIP_COND?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

_eval_condition sets the state

self.state = SignalState.SKIP_COND
so we should be good

@@ -412,13 +426,28 @@ def _dd_debugger_hook(self, probe: Probe) -> None:
log.error("Unsupported probe type: %r", type(probe))
return

signal.line()
scope = ChainMap(actual_frame.f_locals, actual_frame.f_globals)
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

would love to see this also get moved under SignalContext - so there is only one place in our code that deal with those Mixin-s, what do you think?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Hmm but we don't need a context for a line probe 🤔

snapshot.line()
snapshot.line(ChainMap(frame.f_locals, frame.f_globals))

snapshot.state = SignalState.DONE

# Collect
self.__uploader__.get_collector().push(snapshot)
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

where does the rate-limit of exception replay happen?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

rate-limiting is done at the very beginning

if span.get_tag(DEBUG_INFO_TAG) == "true" or not can_capture(span):
# Debug info for span already captured or no budget to capture

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
changelog/no-changelog A changelog entry is not required for this PR. Dynamic Instrumentation Dynamic Instrumentation/Live Debugger
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants