Skip to content

chore(tracer): add abstract base class for AgentWriterInterface #13876

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 3 commits into
base: main
Choose a base branch
from

Conversation

brettlangdon
Copy link
Member

@brettlangdon brettlangdon commented Jul 3, 2025

Preparing the code for a future where we have multiple implementations of the AgentWriter.

I grabbed some minor adjacent type hinting stuff as well.

Split from #13071

We expect no major changes from this change. The only interesting change is the agent_url -> intake_url change which this is an internal/private class.

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

Preparing the code for a future where we have multiple implementations of the AgentWriter
@brettlangdon brettlangdon added the changelog/no-changelog A changelog entry is not required for this PR. label Jul 3, 2025
@brettlangdon brettlangdon requested review from a team as code owners July 3, 2025 18:27
Copy link
Contributor

github-actions bot commented Jul 3, 2025

CODEOWNERS have been resolved as:

ddtrace/_trace/processor/__init__.py                                    @DataDog/apm-sdk-api-python
ddtrace/_trace/tracer.py                                                @DataDog/apm-sdk-api-python
ddtrace/internal/ci_visibility/git_client.py                            @DataDog/ci-app-libraries
ddtrace/internal/ci_visibility/recorder.py                              @DataDog/ci-app-libraries
ddtrace/internal/debug.py                                               @DataDog/apm-core-python
ddtrace/internal/writer/__init__.py                                     @DataDog/apm-core-python
ddtrace/internal/writer/writer.py                                       @DataDog/apm-core-python
ddtrace/opentracer/tracer.py                                            @DataDog/apm-sdk-api-python
tests/appsec/integrations/utils_testagent.py                            @DataDog/asm-python
tests/commands/ddtrace_run_hostname.py                                  @DataDog/apm-core-python
tests/integration/test_debug.py                                         @DataDog/apm-core-python
tests/integration/test_integration.py                                   @DataDog/apm-core-python
tests/integration/test_integration_snapshots.py                         @DataDog/apm-core-python
tests/tracer/test_tracer.py                                             @DataDog/apm-sdk-api-python
tests/tracer/test_writer.py                                             @DataDog/apm-sdk-api-python
tests/utils.py                                                          @DataDog/python-guild

@brettlangdon brettlangdon enabled auto-merge (squash) July 3, 2025 18:32
Copy link
Contributor

github-actions bot commented Jul 3, 2025

Bootstrap import analysis

Comparison of import times between this PR and base.

Summary

The average import time from this PR is: 290 ± 10 ms.

The average import time from base is: 278 ± 3 ms.

The import time difference between this PR and base is: 14.9 ± 0.5 ms.

Import time breakdown

The following import paths have grown:

ddtrace.auto 11.701 ms (3.99%)
ddtrace 6.469 ms (2.21%)
ddtrace._logger 3.924 ms (1.34%)
ddtrace.internal.telemetry 3.834 ms (1.31%)
ddtrace.internal.telemetry.writer 1.849 ms (0.63%)
http.client 0.909 ms (0.31%)
email.parser 0.469 ms (0.16%)
email.feedparser 0.469 ms (0.16%)
email._policybase 0.433 ms (0.15%)
email.header 0.324 ms (0.11%)
email.charset 0.276 ms (0.09%)
email.utils 0.109 ms (0.04%)
email._parseaddr 0.063 ms (0.02%)
calendar 0.063 ms (0.02%)
random 0.046 ms (0.02%)
ssl 0.352 ms (0.12%)
_ssl 0.098 ms (0.03%)
ddtrace.internal.telemetry.data 0.297 ms (0.10%)
ddtrace.internal.packages 0.166 ms (0.06%)
_sysconfigdata__linux_x86_64-linux-gnu 0.078 ms (0.03%)
ddtrace.internal.runtime.container 0.057 ms (0.02%)
sysconfig 0.049 ms (0.02%)
ddtrace.settings._telemetry 0.123 ms (0.04%)
ddtrace.settings._inferred_base_service 0.044 ms (0.02%)
ddtrace.internal.runtime 0.115 ms (0.04%)
uuid 0.115 ms (0.04%)
platform 0.073 ms (0.02%)
ddtrace.internal.utils.version 0.088 ms (0.03%)
ddtrace.vendor.packaging.version 0.088 ms (0.03%)
ddtrace.internal.telemetry.metrics_namespaces 0.074 ms (0.03%)
ddtrace.internal.encoding 0.071 ms (0.02%)
ddtrace.internal._encoding 0.071 ms (0.02%)
ddtrace.internal.periodic 0.071 ms (0.02%)
ddtrace.internal._threads 0.071 ms (0.02%)
ddtrace.internal.telemetry.modules 0.018 ms (0.01%)
ddtrace.settings._agent 1.753 ms (0.60%)
ddtrace.settings 1.345 ms (0.46%)
ddtrace.settings.integration 0.700 ms (0.24%)
ddtrace.vendor.debtcollector 0.678 ms (0.23%)
ddtrace.vendor 0.339 ms (0.12%)
ddtrace.internal.module 0.339 ms (0.12%)
ddtrace.internal.wrapping.context 0.283 ms (0.10%)
ddtrace.internal.wrapping 0.150 ms (0.05%)
bytecode 0.119 ms (0.04%)
bytecode.cfg 0.060 ms (0.02%)
bytecode.concrete 0.060 ms (0.02%)
bytecode.bytecode 0.038 ms (0.01%)
bytecode.version 0.021 ms (0.01%)
ddtrace.internal.utils.inspection 0.110 ms (0.04%)
ddtrace.internal.safety 0.080 ms (0.03%)
wrapt 0.063 ms (0.02%)
wrapt.__wrapt__ 0.063 ms (0.02%)
wrapt.wrappers 0.034 ms (0.01%)
wrapt._wrappers 0.029 ms (0.01%)
contextvars 0.023 ms (0.01%)
_contextvars 0.023 ms (0.01%)
ddtrace.vendor.debtcollector._utils 0.184 ms (0.06%)
ddtrace.vendor.debtcollector.moves 0.057 ms (0.02%)
ddtrace.vendor.debtcollector.removals 0.054 ms (0.02%)
ddtrace.settings.http 0.645 ms (0.22%)
ddtrace.internal.utils.cache 0.454 ms (0.15%)
inspect 0.454 ms (0.15%)
ast 0.080 ms (0.03%)
dis 0.022 ms (0.01%)
opcode 0.022 ms (0.01%)
_opcode 0.022 ms (0.01%)
ddtrace.internal.utils.http 0.190 ms (0.06%)
dataclasses 0.048 ms (0.02%)
email.encoders 0.031 ms (0.01%)
base64 0.031 ms (0.01%)
struct 0.031 ms (0.01%)
_struct 0.031 ms (0.01%)
socket 0.240 ms (0.08%)
_socket 0.082 ms (0.03%)
array 0.042 ms (0.01%)
ddtrace.settings._core 0.132 ms (0.04%)
envier 0.084 ms (0.03%)
envier.env 0.084 ms (0.03%)
ddtrace.internal.native 0.048 ms (0.02%)
ddtrace.internal.native._native 0.048 ms (0.02%)
ddtrace.internal.utils.formats 0.118 ms (0.04%)
ddtrace.internal.compat 0.118 ms (0.04%)
pathlib 0.118 ms (0.04%)
urllib.parse 0.062 ms (0.02%)
ddtrace.settings._otel_remapper 0.036 ms (0.01%)
logging 0.089 ms (0.03%)
ddtrace.trace 1.219 ms (0.42%)
ddtrace._trace.filters 0.640 ms (0.22%)
ddtrace._trace.processor 0.640 ms (0.22%)
ddtrace._trace.sampler 0.288 ms (0.10%)
ddtrace._trace.span 0.254 ms (0.09%)
pprint 0.051 ms (0.02%)
ddtrace.internal._rand 0.050 ms (0.02%)
ddtrace.internal.sampling 0.046 ms (0.02%)
ddtrace.internal.rate_limiter 0.046 ms (0.02%)
ddtrace._trace._span_pointer 0.038 ms (0.01%)
ddtrace.internal.dogstatsd 0.146 ms (0.05%)
ddtrace.vendor.dogstatsd 0.146 ms (0.05%)
ddtrace.vendor.dogstatsd.base 0.146 ms (0.05%)
ddtrace.vendor.dogstatsd.container 0.049 ms (0.02%)
ddtrace.internal.writer 0.132 ms (0.04%)
ddtrace.internal.writer.writer 0.132 ms (0.04%)
ddtrace._trace.tracer 0.309 ms (0.11%)
ddtrace.internal.processor.endpoint_call_counter 0.180 ms (0.06%)
ddtrace.internal.debug 0.042 ms (0.01%)
ddtrace.settings.peer_service 0.019 ms (0.01%)
ddtrace._trace.context 0.123 ms (0.04%)
ddtrace._trace._span_link 0.066 ms (0.02%)
ddtrace.settings._config 0.809 ms (0.28%)
ddtrace.internal.gitmetadata 0.482 ms (0.16%)
ddtrace.ext.ci 0.482 ms (0.16%)
ddtrace.ext.git 0.430 ms (0.15%)
tempfile 0.313 ms (0.11%)
shutil 0.117 ms (0.04%)
zlib 0.036 ms (0.01%)
ddtrace.internal._file_queue 0.121 ms (0.04%)
secrets 0.089 ms (0.03%)
hmac 0.089 ms (0.03%)
_hashlib 0.089 ms (0.03%)
ddtrace.internal.schema 0.039 ms (0.01%)
ddtrace.internal.schema.span_attribute_schema 0.039 ms (0.01%)
ddtrace._monkey 0.307 ms (0.10%)
ddtrace.appsec._listeners 0.156 ms (0.05%)
ddtrace.internal.core 0.156 ms (0.05%)
ddtrace.internal.core.event_hub 0.106 ms (0.04%)
ddtrace.settings.asm 0.073 ms (0.02%)
ddtrace.internal._unpatched 0.211 ms (0.07%)
subprocess 0.188 ms (0.06%)
contextlib 0.159 ms (0.05%)
selectors 0.030 ms (0.01%)
json 0.023 ms (0.01%)
json.decoder 0.023 ms (0.01%)
json.scanner 0.023 ms (0.01%)
_json 0.023 ms (0.01%)
ddtrace.bootstrap.sitecustomize 5.232 ms (1.78%)
ddtrace.bootstrap.preload 3.838 ms (1.31%)
ddtrace.internal.products 0.831 ms (0.28%)
importlib.metadata 0.831 ms (0.28%)
zipfile 0.421 ms (0.14%)
zipfile._path 0.330 ms (0.11%)
csv 0.157 ms (0.05%)
importlib.metadata._collections 0.085 ms (0.03%)
importlib.metadata._meta 0.043 ms (0.01%)
ddtrace.settings.profiling 0.766 ms (0.26%)
ddtrace.vendor.psutil 0.524 ms (0.18%)
ddtrace.vendor.psutil._pslinux 0.239 ms (0.08%)
glob 0.035 ms (0.01%)
ddtrace.vendor.psutil._psutil_linux 0.033 ms (0.01%)
ddtrace.vendor.psutil._common 0.108 ms (0.04%)
ddtrace.vendor.psutil._compat 0.041 ms (0.01%)
ddtrace.internal.datadog.profiling.ddup 0.090 ms (0.03%)
ddtrace.internal.datadog.profiling.ddup._ddup 0.090 ms (0.03%)
ddtrace.internal.datadog.profiling.stack_v2 0.045 ms (0.02%)
ddtrace.internal.datadog.profiling.stack_v2._stack_v2 0.045 ms (0.02%)
ddtrace.internal.core.crashtracking 0.490 ms (0.17%)
multiprocessing.sharedctypes 0.388 ms (0.13%)
multiprocessing.heap 0.388 ms (0.13%)
mmap 0.353 ms (0.12%)
multiprocessing.util 0.035 ms (0.01%)
ddtrace.internal.symbol_db.remoteconfig 0.307 ms (0.10%)
ddtrace.internal.symbol_db.symbols 0.195 ms (0.07%)
ddtrace.settings.symbol_db 0.033 ms (0.01%)
multiprocessing 0.240 ms (0.08%)
multiprocessing.context 0.240 ms (0.08%)
multiprocessing.reduction 0.166 ms (0.06%)
pickle 0.166 ms (0.06%)
_pickle 0.041 ms (0.01%)
_compat_pickle 0.033 ms (0.01%)
multiprocessing.process 0.032 ms (0.01%)
ddtrace.internal.flare.flare 0.176 ms (0.06%)
logging.handlers 0.068 ms (0.02%)
ddtrace.appsec._remoteconfiguration 0.146 ms (0.05%)
ddtrace.appsec._capabilities 0.064 ms (0.02%)
ddtrace.internal.remoteconfig._connectors 0.116 ms (0.04%)
ctypes 0.116 ms (0.04%)
_ctypes 0.085 ms (0.03%)
ctypes._endian 0.031 ms (0.01%)
ddtrace.debugging._import 0.107 ms (0.04%)
ddtrace.debugging._function.discovery 0.079 ms (0.03%)
ddtrace.settings.crashtracker 0.094 ms (0.03%)
ddtrace.internal.datadog.profiling.crashtracker 0.094 ms (0.03%)
ddtrace.internal.datadog.profiling.crashtracker._crashtracker 0.094 ms (0.03%)
ddtrace.internal.remoteconfig.worker 0.057 ms (0.02%)
ddtrace.settings.dynamic_instrumentation 0.049 ms (0.02%)
ddtrace.internal.runtime.runtime_metrics 0.045 ms (0.02%)
ddtrace.internal.flare._subscribers 0.026 ms (0.01%)
ddtrace.appsec._common_module_patches 0.499 ms (0.17%)
ddtrace.appsec._asm_request_context 0.458 ms (0.16%)
ddtrace.appsec._utils 0.384 ms (0.13%)
ddtrace._trace.trace_handlers 0.485 ms (0.17%)
ddtrace._trace._inferred_proxy 0.240 ms (0.08%)
ddtrace.propagation.http 0.208 ms (0.07%)
ddtrace.internal._tagset 0.052 ms (0.02%)
ddtrace.propagation 0.021 ms (0.01%)
ddtrace.contrib.trace_utils 0.125 ms (0.04%)
ddtrace.contrib.internal.trace_utils 0.093 ms (0.03%)
ddtrace.contrib.internal.trace_utils_base 0.047 ms (0.02%)
ddtrace.contrib.internal.redis_utils 0.032 ms (0.01%)
shlex 0.034 ms (0.01%)

The following import paths have shrunk:

ddtrace.auto 1.190 ms (0.41%)
ddtrace 0.715 ms (0.24%)
ddtrace.trace 0.108 ms (0.04%)
ddtrace._trace.tracer 0.108 ms (0.04%)
ddtrace.internal.schema.processor 0.108 ms (0.04%)
ddtrace.bootstrap.sitecustomize 0.474 ms (0.16%)
ddtrace.bootstrap.preload 0.474 ms (0.16%)
ddtrace.internal.remoteconfig.client 0.337 ms (0.12%)
ddtrace.internal.products 0.137 ms (0.05%)
importlib.metadata 0.137 ms (0.05%)
csv 0.070 ms (0.02%)
_csv 0.070 ms (0.02%)
importlib.metadata._itertools 0.067 ms (0.02%)

@brettlangdon brettlangdon requested a review from a team as a code owner July 3, 2025 18:50
@brettlangdon brettlangdon requested a review from liashenko July 3, 2025 18:50
@brettlangdon brettlangdon marked this pull request as draft July 3, 2025 19:06
auto-merge was automatically disabled July 3, 2025 19:06

Pull request was converted to draft

@pr-commenter
Copy link

pr-commenter bot commented Jul 3, 2025

Benchmarks

Benchmark execution time: 2025-07-03 20:14:29

Comparing candidate commit b7c2c69 in PR branch LANGPLAT-134/agent-writer-interface with baseline commit d4aa8cd in branch main.

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

scenario:telemetryaddmetric-1-distribution-metric-1-times

  • 🟥 execution_time [+392.193ns; +418.479ns] or [+13.528%; +14.435%]

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

Comment on lines +228 to +230
if isinstance(self._span_aggregator.writer, HTTPWriter):
# For AgentWriterInterface, we can return the intake_url directly
return self._span_aggregator.writer.intake_url
Copy link
Contributor

Choose a reason for hiding this comment

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

Should we also support AgentWriterInterface instances which are not HTTPWritter ?

Suggested change
if isinstance(self._span_aggregator.writer, HTTPWriter):
# For AgentWriterInterface, we can return the intake_url directly
return self._span_aggregator.writer.intake_url
if isinstance(self._span_aggregator.writer, HTTPWriter) or isinstance(self._span_aggregator.writer, AgentWriterInterface):
# For AgentWriterInterface, we can return the intake_url directly
return self._span_aggregator.writer.intake_url

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