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

chore(telemetry): decouple telemetry writer from global config #10863

Draft
wants to merge 2 commits into
base: main
Choose a base branch
from

Conversation

mabdinur
Copy link
Contributor

Currently, the telemetry writer relies on ddtrace.config to enable and send telemetry payloads, while also queuing telemetry configuration events. This creates a circular dependency that can be painful to manage.

With this change, ddtrace.config will no longer be used to initialize or send telemetry events. The telemerty_writer will access environment directly from os.os.environ. The telemetry_writer can now queue configurations, metrics, and logs before the global config object is initialized,.

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

Copy link
Contributor

CODEOWNERS have been resolved as:

ddtrace/settings/_core.py                                               @DataDog/apm-core-python
ddtrace/internal/agent.py                                               @DataDog/apm-core-python
ddtrace/internal/runtime/runtime_metrics.py                             @DataDog/apm-core-python
ddtrace/internal/telemetry/constants.py                                 @DataDog/apm-core-python
ddtrace/internal/telemetry/data.py                                      @DataDog/apm-core-python
ddtrace/internal/telemetry/writer.py                                    @DataDog/apm-core-python
ddtrace/settings/asm.py                                                 @DataDog/asm-python
ddtrace/settings/config.py                                              @DataDog/python-guild @DataDog/apm-sdk-api-python
ddtrace/settings/crashtracker.py                                        @DataDog/apm-core-python
ddtrace/settings/dynamic_instrumentation.py                             @DataDog/debugger-python
ddtrace/settings/exception_replay.py                                    @DataDog/apm-core-python
ddtrace/settings/peer_service.py                                        @DataDog/apm-core-python
ddtrace/settings/profiling.py                                           @DataDog/profiling-python
ddtrace/settings/symbol_db.py                                           @DataDog/apm-core-python
tests/telemetry/test_telemetry.py                                       @DataDog/apm-core-python
tests/telemetry/test_writer.py                                          @DataDog/apm-core-python

def test_app_started_event_configuration_override(
test_agent_session, run_python_code_in_subprocess, tmpdir, env_var, value, expected_value
):
# @pytest.mark.skip(reason="FIXME: This test needs to be updated.")
Copy link
Contributor

Choose a reason for hiding this comment

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

Code Quality Violation

Suggested change
# @pytest.mark.skip(reason="FIXME: This test needs to be updated.")
# @pytest.mark.skip(reason="FIXME(<owner>): This test needs to be updated.")
comments must have ownership (...read more)

When using TODO or FIXME, specify who write the annotation. It's a best practice to remind you who created the annotation and have potential context and information about this issue.

View in Datadog  Leave us feedback  Documentation

self._app_client_configuration_changed_event(cs)

def _telemetry_entry(self, cfg_name: str) -> Tuple[str, str, _ConfigSource]:
def _telemetry_entry(self, config: Any, cfg_name: str) -> Tuple[str, str, Any]:
Copy link
Contributor

Choose a reason for hiding this comment

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

🟠 Code Quality Violation

do not use Any, use a concrete type (...read more)

Use the Any type very carefully. Most of the time, the Any type is used because we do not know exactly what type is being used. If you want to specify that a value can be of any type, use object instead of Any.

Learn More

View in Datadog  Leave us feedback  Documentation

test_agent_session, run_python_code_in_subprocess, tmpdir, env_var, value, expected_value
):
# @pytest.mark.skip(reason="FIXME: This test needs to be updated.")
def test_app_started_event_configuration_override(test_agent_session, run_python_code_in_subprocess, tmpdir):
Copy link
Contributor

Choose a reason for hiding this comment

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

🔴 Code Quality Violation

function exceeds 200 lines (...read more)

This rule stipulates that functions in Python should not exceed 200 lines of code. The primary reason for this rule is to promote readability and maintainability of the code. When functions are concise and focused, they are easier to understand, test, and debug.

Long functions often indicate that a single function is doing too much. Adhering to the Single Responsibility Principle (SRP) can help avoid this. SRP states that a function should have only one reason to change. If a function is doing more than one thing, it can usually be split into several smaller, more specific functions.

In practice, to adhere to this rule, you can often break up long functions into smaller helper functions. If a piece of code within a function is independent and can be isolated, it is a good candidate to be moved into a separate function. This also increases code reusability. For instance, if a function process_data() is too long, you can identify independent tasks within it - such as clean_data(), transform_data(), and save_data() - and create separate functions for them. This makes the code easier to reason about and test, and promotes good coding practices.

View in Datadog  Leave us feedback  Documentation

@P403n1x87
Copy link
Contributor

That's great! Did we consider a callback/core event hub alternative approach to break the circular dependency?

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants