-
Notifications
You must be signed in to change notification settings - Fork 439
chore: introduce APM_TRACING RC product #11980
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
Merged
Merged
Changes from all commits
Commits
Show all changes
17 commits
Select commit
Hold shift + click to select a range
35eeb9a
chore: introduce APM_TRACING RC product
P403n1x87 b71c12e
Merge branch 'main' into chore/apm-tracing-rc
P403n1x87 ac960ab
remove commented out code
P403n1x87 f27447d
eager-loading DI
P403n1x87 c6ce9ed
minimal imports
P403n1x87 8a6e98f
Merge branch 'main' into chore/apm-tracing-rc
mabdinur 89b3d7e
migrate tracing to product interface
P403n1x87 67b394c
Merge remote-tracking branch 'origin/main' into chore/apm-tracing-rc
P403n1x87 2677d3f
remove double-registration
P403n1x87 46741c7
Merge remote-tracking branch 'origin/main' into chore/apm-tracing-rc
P403n1x87 e2fcdec
adapt to RC refactor
P403n1x87 1761ef3
remove DI changes
P403n1x87 a3c24be
add test helper
P403n1x87 252be2c
fix settings tests
P403n1x87 0383218
make testagent tests verbose
P403n1x87 e7e9df7
fix testagent tests
P403n1x87 76de753
Merge branch 'main' into chore/apm-tracing-rc
P403n1x87 File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or 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 hidden or 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
Empty file.
This file contains hidden or 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,82 @@ | ||
import typing as t | ||
|
||
from ddtrace import config | ||
from ddtrace.internal.core.event_hub import dispatch | ||
from ddtrace.internal.core.event_hub import on | ||
from ddtrace.internal.logger import get_logger | ||
from ddtrace.internal.remoteconfig import Payload | ||
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 | ||
|
||
|
||
requires = ["remote-configuration"] | ||
|
||
|
||
log = get_logger(__name__) | ||
|
||
|
||
def _rc_callback(payloads: t.Sequence[Payload]) -> None: | ||
for payload in payloads: | ||
if payload.metadata is None or (content := payload.content) is None: | ||
continue | ||
|
||
if (service_target := t.cast(t.Optional[dict], content.get("service_target"))) is not None: | ||
if (service := t.cast(str, service_target.get("service"))) is not None and service != config.service: | ||
continue | ||
|
||
if (env := t.cast(str, service_target.get("env"))) is not None and env != config.env: | ||
continue | ||
|
||
if (lib_config := t.cast(dict, content.get("lib_config"))) is not None: | ||
dispatch("apm-tracing.rc", (lib_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") | ||
|
||
|
||
def post_preload(): | ||
pass | ||
|
||
|
||
def start(): | ||
if config._remote_config_enabled: | ||
from ddtrace.internal.products import manager | ||
from ddtrace.internal.remoteconfig.worker import remoteconfig_poller | ||
|
||
remoteconfig_poller.register( | ||
P403n1x87 marked this conversation as resolved.
Show resolved
Hide resolved
|
||
"APM_TRACING", | ||
APMTracingAdapter(), | ||
restart_on_fork=True, | ||
capabilities=[ | ||
cap for product in manager.__products__.values() for cap in getattr(product, "APMCapabilities", []) | ||
], | ||
) | ||
|
||
# Register remote config handlers | ||
for name, product in manager.__products__.items(): | ||
if (rc_handler := getattr(product, "apm_tracing_rc", None)) is not None: | ||
on("apm-tracing.rc", rc_handler, name) | ||
|
||
|
||
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) |
This file contains hidden or 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 hidden or 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 hidden or 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 hidden or 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 hidden or 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.
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Uh oh!
There was an error while loading. Please reload this page.