Skip to content
Draft
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
10 changes: 9 additions & 1 deletion ddtrace/internal/telemetry/data.py
Original file line number Diff line number Diff line change
Expand Up @@ -56,9 +56,12 @@ def _get_application(key):
This helper packs and unpacks get_application arguments to support caching.
Cached() annotation only supports functions with one argument
"""
# avoid circular dependency
from ddtrace.internal import process_tags
Copy link
Contributor

Choose a reason for hiding this comment

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

This is not the best way of avoiding circular references. Let's try to find a different approach where the dependency goes in only one direction.


service, version, env = key

return {
application = {
"service_name": service or DEFAULT_SERVICE_NAME, # mandatory field, can not be empty
"service_version": version or "",
"env": env or "",
Expand All @@ -69,6 +72,11 @@ def _get_application(key):
"runtime_version": _format_version_info(sys.implementation.version),
}

if p_tags := process_tags.process_tags:
application["process_tags"] = p_tags

return application


def update_imported_dependencies(already_imported: Dict[str, str], new_modules: Iterable[str]) -> List[Dict[str, str]]:
deps = []
Expand Down
15 changes: 15 additions & 0 deletions tests/telemetry/test_data.py
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,7 @@
from ddtrace.internal.telemetry.data import get_application
from ddtrace.internal.telemetry.data import get_host_info
from ddtrace.internal.telemetry.data import get_hostname
from tests.utils import process_tag_reload


def test_get_application():
Expand Down Expand Up @@ -43,6 +44,20 @@ def test_get_application_with_values():
assert application["env"] == "staging"


def test_get_application_with_process_tags():
from ddtrace.internal.settings._config import config

try:
config._process_tags_enabled = True
process_tag_reload()

application = get_application("", "", "")
assert "process_tags" in application
finally:
config._process_tags_enabled = False
process_tag_reload()


def test_application_with_setenv(run_python_code_in_subprocess, monkeypatch):
"""
validates the return value of get_application when DD_SERVICE, DD_VERSION, and DD_ENV environment variables are set
Expand Down
Loading