Skip to content

Commit

Permalink
chore: introduce APM_TRACING RC product
Browse files Browse the repository at this point in the history
We introduce the APM_TRACING remote configuration product that allows
dispatching remote configuration to the library for remote enablement/
configuration of library components and features.
  • Loading branch information
P403n1x87 committed Jan 16, 2025
1 parent 4183671 commit 6367ef6
Show file tree
Hide file tree
Showing 7 changed files with 82 additions and 5 deletions.
3 changes: 0 additions & 3 deletions ddtrace/debugging/_debugger.py
Original file line number Diff line number Diff line change
Expand Up @@ -274,8 +274,6 @@ def enable(cls) -> None:

di_config.enabled = True

cls.__watchdog__.install()

if di_config.metrics:
metrics.enable()

Expand Down Expand Up @@ -307,7 +305,6 @@ def disable(cls, join: bool = True) -> None:
cls._instance.stop(join=join)
cls._instance = None

cls.__watchdog__.uninstall()
if di_config.metrics:
metrics.disable()

Expand Down
20 changes: 19 additions & 1 deletion ddtrace/debugging/_products/dynamic_instrumentation.py
Original file line number Diff line number Diff line change
@@ -1,11 +1,17 @@
from ddtrace.internal.core.event_hub import on
from ddtrace.settings.dynamic_instrumentation import config


requires = ["remote-configuration"]


def post_preload():
pass
from ddtrace.debugging._debugger import Debugger

# We need to install this on start-up because if DI gets enabled remotely
# we won't be able to capture many of the code objects from the modules
# that are already loaded.
Debugger.__watchdog__.install()


def start():
Expand All @@ -29,3 +35,15 @@ def stop(join=False):

def at_exit(join=False):
stop(join=join)


def apm_tracing_rc(config):
enabled = config.get("dynamic_instrumentation_enabled")
if enabled is not None: # and config.spec.enabled.full_name not in config.source:
if (config.spec.enabled.full_name not in config.source or config.enabled) and enabled:
start()
else:
stop()


on("apm-tracing.rc", apm_tracing_rc, "dynamic-instrumentation")
Empty file.
31 changes: 31 additions & 0 deletions ddtrace/internal/remoteconfig/products/apm_tracing.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,31 @@
from ddtrace import config


requires = ["remote-configuration"]


def post_preload():
pass


def start():
if config._remote_config_enabled:
from ddtrace.internal.remoteconfig.worker import remoteconfig_poller
from ddtrace.settings.remoteconfig import APMTracingAdapter

remoteconfig_poller.register("APM_TRACING", APMTracingAdapter())


def restart(join=False):
pass


def stop(join=False):
if config._remote_config_enabled:
from ddtrace.internal.remoteconfig.worker import remoteconfig_poller

remoteconfig_poller.unregister("APM_TRACING")


def at_exit(join=False):
stop(join=join)
File renamed without changes.
30 changes: 30 additions & 0 deletions ddtrace/settings/remoteconfig.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,30 @@
from ddtrace.internal.core.event_hub import dispatch
from ddtrace.internal.logger import get_logger
from ddtrace.internal.remoteconfig._connectors import PublisherSubscriberConnector
from ddtrace.internal.remoteconfig._publishers import RemoteConfigPublisher
from ddtrace.internal.remoteconfig._pubsub import PubSub
from ddtrace.internal.remoteconfig._subscribers import RemoteConfigSubscriber


log = get_logger(__name__)


def _rc_callback(data, test_tracer=None):
for metadata, config in zip(data["metadata"], data["config"]):
if metadata is None:
continue

lib_config = config.get("lib_config")
if lib_config is not None:
dispatch("apm-tracing.rc", (lib_config,))
print("apm-tracing.rc", (config,))


class APMTracingAdapter(PubSub):
__publisher_class__ = RemoteConfigPublisher
__subscriber_class__ = RemoteConfigSubscriber
__shared_data__ = PublisherSubscriberConnector()

def __init__(self):
self._publisher = self.__publisher_class__(self.__shared_data__)
self._subscriber = self.__subscriber_class__(self.__shared_data__, _rc_callback, "APM_TRACING")
3 changes: 2 additions & 1 deletion pyproject.toml
Original file line number Diff line number Diff line change
Expand Up @@ -60,10 +60,11 @@ ddtrace = "ddtrace.contrib.pytest.plugin"
"ddtrace.pytest_benchmark" = "ddtrace.contrib.pytest_benchmark.plugin"

[project.entry-points.'ddtrace.products']
"apm-tracing-rc" = "ddtrace.internal.remoteconfig.products.apm_tracing"
"code-origin-for-spans" = "ddtrace.debugging._products.code_origin.span"
"dynamic-instrumentation" = "ddtrace.debugging._products.dynamic_instrumentation"
"exception-replay" = "ddtrace.debugging._products.exception_replay"
"remote-configuration" = "ddtrace.internal.remoteconfig.product"
"remote-configuration" = "ddtrace.internal.remoteconfig.products.client"
"symbol-database" = "ddtrace.internal.symbol_db.product"

[project.urls]
Expand Down

0 comments on commit 6367ef6

Please sign in to comment.