-
Notifications
You must be signed in to change notification settings - Fork 426
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
We implement trigger probes. These allows triggering the capture of debug information along a trace, ensuring all the relevant probes are also triggered.
- Loading branch information
Showing
10 changed files
with
228 additions
and
48 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,22 @@ | ||
import typing as t | ||
|
||
from ddtrace.debugging._session import Session | ||
from ddtrace.internal import core | ||
|
||
|
||
def handle_distributed_context(context: t.Any) -> None: | ||
debug_tag = context._meta.get("_dd.p.debug") | ||
if debug_tag is None: | ||
return | ||
|
||
ident, _, level = debug_tag.partition(":") | ||
|
||
Session(ident=ident, level=int(level)).link_to_trace(context) | ||
|
||
|
||
def enable() -> None: | ||
core.on("distributed_context.activated", handle_distributed_context, "live_debugger") | ||
|
||
|
||
def disable() -> None: | ||
core.reset_listeners("distributed_context.activated", handle_distributed_context) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,31 @@ | ||
from ddtrace.settings.live_debugging import config | ||
|
||
|
||
# TODO[gab]: Uncomment when the product is ready | ||
# requires = ["tracer"] | ||
|
||
|
||
def post_preload(): | ||
pass | ||
|
||
|
||
def start() -> None: | ||
if config.enabled: | ||
from ddtrace.debugging._live import enable | ||
|
||
enable() | ||
|
||
|
||
def restart() -> None: | ||
pass | ||
|
||
|
||
def stop(join: bool = False): | ||
if config.enabled: | ||
from ddtrace.debugging._live import disable | ||
|
||
disable() | ||
|
||
|
||
def at_exit(join: bool = False): | ||
stop(join=join) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,34 @@ | ||
from dataclasses import dataclass | ||
import typing as t | ||
from weakref import WeakKeyDictionary as wkdict | ||
|
||
from ddtrace import tracer | ||
|
||
|
||
@dataclass | ||
class Session: | ||
ident: str | ||
level: int | ||
|
||
def link_to_trace(self, trace_context: t.Optional[t.Any] = None): | ||
SessionManager.link_session_to_trace(self, trace_context) | ||
|
||
@classmethod | ||
def get_for_trace(cls) -> t.Optional["Session"]: | ||
return SessionManager.get_session_for_trace() | ||
|
||
|
||
class SessionManager: | ||
_session_trace_map: wkdict = wkdict() # Trace context to Session mapping | ||
|
||
@classmethod | ||
def link_session_to_trace(cls, session, trace_context: t.Optional[t.Any] = None) -> None: | ||
cls._session_trace_map[trace_context or tracer.current_root_span()] = session | ||
|
||
@classmethod | ||
def get_session_for_trace(cls) -> t.Optional[Session]: | ||
root = tracer.current_root_span() | ||
if root is None: | ||
return None | ||
|
||
return cls._session_trace_map.get(root.context or root) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,16 @@ | ||
from envier import En | ||
|
||
|
||
class LiveDebuggerConfig(En): | ||
__prefix__ = "dd.live_debugging" | ||
|
||
enabled = En.v( | ||
bool, | ||
"enabled", | ||
default=False, | ||
help_type="Boolean", | ||
help="Enable the live debugger.", | ||
) | ||
|
||
|
||
config = LiveDebuggerConfig() |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.