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

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

Conversation

brettlangdon
Copy link
Member

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: 282 ± 4 ms.

The average import time from base is: 286 ± 4 ms.

The import time difference between this PR and base is: -3.8 ± 0.2 ms.

Import time breakdown

The following import paths have appeared:

ddtrace.auto 4.886 ms (1.73%)
ddtrace 4.886 ms (1.73%)
ddtrace.trace 4.886 ms (1.73%)
ddtrace._trace.filters 4.886 ms (1.73%)
ddtrace._trace.processor 4.886 ms (1.73%)
ddtrace.internal.writer 4.886 ms (1.73%)
ddtrace.internal.writer.writer 4.886 ms (1.73%)
ddtrace.internal.dogstatsd 4.886 ms (1.73%)
ddtrace.vendor.dogstatsd 4.598 ms (1.63%)
ddtrace.vendor.dogstatsd.base 4.335 ms (1.54%)
queue 1.367 ms (0.48%)
heapq 0.579 ms (0.21%)
_heapq 0.292 ms (0.10%)
_queue 0.299 ms (0.11%)
ddtrace.vendor.dogstatsd.context 0.789 ms (0.28%)
ddtrace.vendor.dogstatsd.context_async 0.469 ms (0.17%)
ddtrace.vendor.dogstatsd.container 0.564 ms (0.20%)
ddtrace.vendor.dogstatsd.format 0.328 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.930 ms (1.75%)
ddtrace 4.930 ms (1.75%)
ddtrace.trace 4.930 ms (1.75%)
ddtrace._trace.filters 4.930 ms (1.75%)
ddtrace._trace.processor 4.930 ms (1.75%)
ddtrace.internal.dogstatsd 4.930 ms (1.75%)
ddtrace.vendor.dogstatsd 4.625 ms (1.64%)
ddtrace.vendor.dogstatsd.base 4.361 ms (1.54%)
queue 1.279 ms (0.45%)
heapq 0.590 ms (0.21%)
_heapq 0.300 ms (0.11%)
_queue 0.303 ms (0.11%)
ddtrace.vendor.dogstatsd.context 0.789 ms (0.28%)
ddtrace.vendor.dogstatsd.context_async 0.470 ms (0.17%)
ddtrace.vendor.dogstatsd.container 0.681 ms (0.24%)
ddtrace.vendor.dogstatsd.format 0.329 ms (0.12%)
ddtrace.vendor.dogstatsd.route 0.279 ms (0.10%)
ddtrace.vendor.dogstatsd.compat 0.251 ms (0.09%)

The following import paths have shrunk:

ddtrace.auto 2.139 ms (0.76%)
ddtrace.bootstrap.sitecustomize 1.411 ms (0.50%)
ddtrace.bootstrap.preload 1.411 ms (0.50%)
ddtrace.internal.remoteconfig.client 0.685 ms (0.24%)
ddtrace 0.728 ms (0.26%)
ddtrace.trace 0.046 ms (0.02%)
ddtrace._trace.filters 0.046 ms (0.02%)
ddtrace._trace.processor 0.046 ms (0.02%)
ddtrace.internal._unpatched 0.032 ms (0.01%)
json 0.032 ms (0.01%)
json.decoder 0.032 ms (0.01%)
re 0.032 ms (0.01%)
enum 0.032 ms (0.01%)
types 0.032 ms (0.01%)

@pr-commenter
Copy link

pr-commenter bot commented Jul 7, 2025

Benchmarks

Benchmark execution time: 2025-07-10 16:01:41

Comparing candidate commit 8f58bf4 in PR branch LANGPLAT-134/abstract-writer-create with baseline commit 2d305dd in branch main.

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

scenario:iastaspectsospath-ospathbasename_aspect

  • 🟥 execution_time [+735.681ns; +854.492ns] or [+17.411%; +20.223%]

scenario:iastaspectsospath-ospathsplitext_aspect

  • 🟥 execution_time [+724.044ns; +849.369ns] or [+15.938%; +18.697%]

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

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.

2 participants