Skip to content

chore: refactor SpanAggregator <> TraceWriter interface #13894

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

Open
wants to merge 8 commits into
base: main
Choose a base branch
from

Conversation

brettlangdon
Copy link
Member

@brettlangdon brettlangdon commented Jul 7, 2025

Help remove some implementation details from SpanAggregator into a the writer module.

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

Help remove some implementation details from SpanAggregator into a the writer module.
@brettlangdon brettlangdon added the changelog/no-changelog A changelog entry is not required for this PR. label Jul 7, 2025
@brettlangdon
Copy link
Member Author

This is going to have conflicts with #13876

Copy link
Contributor

github-actions bot commented Jul 7, 2025

CODEOWNERS have been resolved as:

ddtrace/_trace/processor/__init__.py                                    @DataDog/apm-sdk-api-python
ddtrace/internal/ci_visibility/writer.py                                @DataDog/ci-app-libraries
ddtrace/internal/writer/__init__.py                                     @DataDog/apm-core-python
ddtrace/internal/writer/writer.py                                       @DataDog/apm-core-python
tests/utils.py                                                          @DataDog/python-guild

@@ -80,8 +84,7 @@ def _human_size(nbytes):

class TraceWriter(metaclass=abc.ABCMeta):
@abc.abstractmethod
def recreate(self):
# type: () -> TraceWriter
def recreate(self, appsec_enabled: Optional[bool] = None) -> "TraceWriter":
Copy link
Member Author

Choose a reason for hiding this comment

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

I couldn't find a good way around this, since the value is coming from tracer.configure and not tied to a specific config option... we probably need to keep this until we can deprecate appsec_enabled from tracer.configure() :/

Copy link
Contributor

github-actions bot commented Jul 7, 2025

Bootstrap import analysis

Comparison of import times between this PR and base.

Summary

The average import time from this PR is: 280 ± 3 ms.

The average import time from base is: 282 ± 2 ms.

The import time difference between this PR and base is: -1.6 ± 0.1 ms.

Import time breakdown

The following import paths have appeared:

ddtrace.auto 4.868 ms (1.74%)
ddtrace 4.868 ms (1.74%)
ddtrace.trace 4.868 ms (1.74%)
ddtrace._trace.filters 4.868 ms (1.74%)
ddtrace._trace.processor 4.868 ms (1.74%)
ddtrace.internal.writer 4.868 ms (1.74%)
ddtrace.internal.writer.writer 4.868 ms (1.74%)
ddtrace.internal.dogstatsd 4.868 ms (1.74%)
ddtrace.vendor.dogstatsd 4.579 ms (1.63%)
ddtrace.vendor.dogstatsd.base 4.316 ms (1.54%)
queue 1.363 ms (0.49%)
heapq 0.573 ms (0.20%)
_heapq 0.286 ms (0.10%)
_queue 0.298 ms (0.11%)
ddtrace.vendor.dogstatsd.context 0.787 ms (0.28%)
ddtrace.vendor.dogstatsd.context_async 0.470 ms (0.17%)
ddtrace.vendor.dogstatsd.container 0.565 ms (0.20%)
ddtrace.vendor.dogstatsd.format 0.326 ms (0.12%)
ddtrace.vendor.dogstatsd.route 0.277 ms (0.10%)
ddtrace.vendor.dogstatsd.compat 0.250 ms (0.09%)

The following import paths have disappeared:

ddtrace.auto 4.853 ms (1.73%)
ddtrace 4.853 ms (1.73%)
ddtrace.trace 4.853 ms (1.73%)
ddtrace._trace.filters 4.853 ms (1.73%)
ddtrace._trace.processor 4.853 ms (1.73%)
ddtrace.internal.dogstatsd 4.853 ms (1.73%)
ddtrace.vendor.dogstatsd 4.551 ms (1.62%)
ddtrace.vendor.dogstatsd.base 4.294 ms (1.53%)
queue 1.253 ms (0.45%)
heapq 0.574 ms (0.20%)
_heapq 0.288 ms (0.10%)
_queue 0.299 ms (0.11%)
ddtrace.vendor.dogstatsd.context 0.786 ms (0.28%)
ddtrace.vendor.dogstatsd.context_async 0.466 ms (0.17%)
ddtrace.vendor.dogstatsd.container 0.669 ms (0.24%)
ddtrace.vendor.dogstatsd.format 0.320 ms (0.11%)
ddtrace.vendor.dogstatsd.route 0.278 ms (0.10%)
ddtrace.vendor.dogstatsd.compat 0.251 ms (0.09%)

The following import paths have grown:

ddtrace.auto 0.020 ms (0.01%)
ddtrace 0.020 ms (0.01%)
ddtrace.trace 0.020 ms (0.01%)
ddtrace._trace.filters 0.020 ms (0.01%)
ddtrace._trace.processor 0.020 ms (0.01%)
ddtrace.internal.writer 0.020 ms (0.01%)
ddtrace.internal.writer.writer 0.020 ms (0.01%)
ddtrace.internal.sma 0.020 ms (0.01%)

The following import paths have shrunk:

ddtrace.auto 2.011 ms (0.72%)
ddtrace.bootstrap.sitecustomize 1.295 ms (0.46%)
ddtrace.bootstrap.preload 1.295 ms (0.46%)
ddtrace.internal.remoteconfig.client 0.646 ms (0.23%)
ddtrace 0.716 ms (0.26%)
ddtrace.trace 0.040 ms (0.01%)
ddtrace._trace.filters 0.040 ms (0.01%)
ddtrace._trace.processor 0.040 ms (0.01%)
ddtrace.internal._unpatched 0.030 ms (0.01%)
json 0.030 ms (0.01%)
json.decoder 0.030 ms (0.01%)
re 0.030 ms (0.01%)
enum 0.030 ms (0.01%)
types 0.030 ms (0.01%)

@pr-commenter
Copy link

pr-commenter bot commented Jul 7, 2025

Benchmarks

Benchmark execution time: 2025-07-11 19:07:45

Comparing candidate commit a8f2f56 in PR branch LANGPLAT-134/abstract-writer-create with baseline commit c7c99b3 in branch main.

Found 0 performance improvements and 1 performance regressions! Performance is the same for 539 metrics, 2 unstable metrics.

scenario:iastaspects-replace_aspect

  • 🟥 execution_time [+368.360ns; +571.703ns] or [+7.767%; +12.054%]

Copy link
Contributor

@VianneyRuhlmann VianneyRuhlmann left a comment

Choose a reason for hiding this comment

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

LGTM, this will also be helpful for the DummyWriter creation with NativeWriter

@brettlangdon brettlangdon marked this pull request as ready for review July 11, 2025 18:21
@brettlangdon brettlangdon requested review from a team as code owners July 11, 2025 18:21
@brettlangdon brettlangdon enabled auto-merge (squash) July 11, 2025 19:14
@brettlangdon brettlangdon requested review from gnufede and vitor-de-araujo and removed request for nikita-tkachenko-datadog July 15, 2025 10:05
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
changelog/no-changelog A changelog entry is not required for this PR.
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants