Skip to content

chore(telemetry): integration error telemetry logs are sent through a function call #13510

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

Conversation

dubloom
Copy link
Contributor

@dubloom dubloom commented May 27, 2025

Motivation

Integration related error telemetry logs were added in #11732. However, it is using a LogHandler. After a discussion in a previous guild meeting, it appeared that we don't want to use LogHandler as it could have an impact on the customer logger.

In addition, to be able to report integration error logs to telemetry you needed to enable debug logs (as in the integration the errors are logged using debug level). However, telemetry activation should be tied to the log level.

What does this PR do ?

  • Remove the log handler
  • Add a call tied to the writer to report integration error logs to telemetry
  • Bump the level of the telemetry logs to error (so it appears in telemetry).
  • Modification to the redaction process: add <REDACTED> for every lines we are redacting (before we were only adding one <REDACTED> for the redaction of two lines)

What this PR doesn't do

  • The PR does not effectively report any errors to telemetry. A discussion should take place in IDM to chose which errors are worth reporting to telemetry.

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

@dubloom dubloom requested review from a team as code owners May 27, 2025 14:40
Copy link
Contributor

github-actions bot commented May 27, 2025

CODEOWNERS have been resolved as:

ddtrace/internal/telemetry/writer.py                                    @DataDog/apm-core-python
tests/telemetry/test_writer.py                                          @DataDog/apm-python

@dubloom dubloom added the changelog/no-changelog A changelog entry is not required for this PR. label May 27, 2025
Copy link
Contributor

github-actions bot commented May 27, 2025

Bootstrap import analysis

Comparison of import times between this PR and base.

Summary

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

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

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

Import time breakdown

The following import paths have disappeared:

ddtrace.auto 0.335 ms (0.14%)
ddtrace 0.335 ms (0.14%)
ddtrace._logger 0.335 ms (0.14%)
ddtrace.internal.telemetry 0.335 ms (0.14%)
ddtrace.internal.telemetry.writer 0.335 ms (0.14%)
ddtrace.internal.telemetry.logging 0.335 ms (0.14%)

The following import paths have grown:

ddtrace.auto 0.113 ms (0.05%)
ddtrace 0.113 ms (0.05%)
ddtrace.settings._config 0.113 ms (0.05%)
ddtrace.internal.gitmetadata 0.113 ms (0.05%)
ddtrace.ext.ci 0.113 ms (0.05%)
ddtrace.ext.git 0.113 ms (0.05%)
shutil 0.057 ms (0.02%)
lzma 0.057 ms (0.02%)
_lzma 0.057 ms (0.02%)

The following import paths have shrunk:

ddtrace.auto 10.323 ms (4.41%)
ddtrace 5.299 ms (2.27%)
ddtrace._logger 2.863 ms (1.22%)
ddtrace.internal.telemetry 2.634 ms (1.13%)
ddtrace.internal.telemetry.writer 1.818 ms (0.78%)
ddtrace.internal.utils.version 0.735 ms (0.31%)
ddtrace.vendor.packaging.version 0.735 ms (0.31%)
ddtrace.vendor.packaging 0.533 ms (0.23%)
ddtrace.vendor 0.533 ms (0.23%)
ddtrace.internal.module 0.533 ms (0.23%)
ddtrace.internal.wrapping.context 0.261 ms (0.11%)
ddtrace.internal.wrapping 0.232 ms (0.10%)
bytecode 0.212 ms (0.09%)
bytecode.bytecode 0.128 ms (0.05%)
bytecode.flags 0.128 ms (0.05%)
bytecode.instr 0.107 ms (0.05%)
bytecode.cfg 0.084 ms (0.04%)
bytecode.concrete 0.036 ms (0.02%)
contextvars 0.029 ms (0.01%)
_contextvars 0.029 ms (0.01%)
ddtrace.vendor.packaging._structures 0.027 ms (0.01%)
http.client 0.462 ms (0.20%)
ssl 0.204 ms (0.09%)
_ssl 0.077 ms (0.03%)
email.parser 0.170 ms (0.07%)
email.feedparser 0.170 ms (0.07%)
email._policybase 0.170 ms (0.07%)
email.utils 0.132 ms (0.06%)
email._parseaddr 0.102 ms (0.04%)
calendar 0.102 ms (0.04%)
locale 0.067 ms (0.03%)
random 0.029 ms (0.01%)
email.header 0.038 ms (0.02%)
email.message 0.029 ms (0.01%)
ddtrace.internal.telemetry.data 0.247 ms (0.11%)
ddtrace.internal.packages 0.176 ms (0.08%)
_sysconfigdata__linux_x86_64-linux-gnu 0.081 ms (0.03%)
sysconfig 0.048 ms (0.02%)
ddtrace.internal.runtime 0.102 ms (0.04%)
uuid 0.087 ms (0.04%)
platform 0.048 ms (0.02%)
ddtrace.internal.telemetry.metrics_namespaces 0.079 ms (0.03%)
ddtrace.settings._telemetry 0.074 ms (0.03%)
ddtrace.settings._inferred_base_service 0.033 ms (0.01%)
ddtrace.internal.forksafe 0.070 ms (0.03%)
wrapt 0.050 ms (0.02%)
wrapt.__wrapt__ 0.050 ms (0.02%)
wrapt._wrappers 0.026 ms (0.01%)
wrapt.wrappers 0.023 ms (0.01%)
ddtrace.internal.encoding 0.035 ms (0.02%)
ddtrace.internal._encoding 0.035 ms (0.02%)
ddtrace.internal.atexit 0.014 ms (0.01%)
ddtrace.settings._agent 0.655 ms (0.28%)
socket 0.383 ms (0.16%)
selectors 0.276 ms (0.12%)
_socket 0.032 ms (0.01%)
array 0.018 ms (0.01%)
ddtrace.settings 0.247 ms (0.11%)
ddtrace.settings.http 0.247 ms (0.11%)
ddtrace.internal.utils.cache 0.158 ms (0.07%)
inspect 0.158 ms (0.07%)
ast 0.058 ms (0.02%)
ddtrace.internal.utils.http 0.089 ms (0.04%)
email.encoders 0.019 ms (0.01%)
base64 0.019 ms (0.01%)
struct 0.019 ms (0.01%)
_struct 0.019 ms (0.01%)
ddtrace.settings._core 0.024 ms (0.01%)
ddtrace.internal.utils.formats 0.077 ms (0.03%)
ddtrace.internal.compat 0.077 ms (0.03%)
pathlib 0.077 ms (0.03%)
urllib.parse 0.034 ms (0.01%)
math 0.034 ms (0.01%)
logging 0.212 ms (0.09%)
traceback 0.212 ms (0.09%)
contextlib 0.212 ms (0.09%)
ddtrace.settings._config 0.861 ms (0.37%)
ddtrace.internal.gitmetadata 0.444 ms (0.19%)
ddtrace.ext.ci 0.444 ms (0.19%)
ddtrace.ext.git 0.278 ms (0.12%)
shutil 0.209 ms (0.09%)
lzma 0.090 ms (0.04%)
zlib 0.024 ms (0.01%)
bz2 0.024 ms (0.01%)
_bz2 0.024 ms (0.01%)
subprocess 0.068 ms (0.03%)
ddtrace.internal.schema 0.036 ms (0.02%)
ddtrace.internal.schema.span_attribute_schema 0.036 ms (0.02%)
ddtrace.trace 0.673 ms (0.29%)
ddtrace._trace.filters 0.419 ms (0.18%)
ddtrace._trace.processor 0.419 ms (0.18%)
ddtrace._trace.sampler 0.163 ms (0.07%)
ddtrace._trace.span 0.163 ms (0.07%)
ddtrace.internal._rand 0.046 ms (0.02%)
ddtrace.internal.sampling 0.034 ms (0.01%)
pprint 0.032 ms (0.01%)
ddtrace.internal.dogstatsd 0.104 ms (0.04%)
ddtrace.vendor.dogstatsd 0.084 ms (0.04%)
ddtrace.vendor.dogstatsd.base 0.084 ms (0.04%)
queue 0.021 ms (0.01%)
ddtrace.internal.writer 0.104 ms (0.04%)
ddtrace.internal.writer.writer 0.104 ms (0.04%)
gzip 0.053 ms (0.02%)
ddtrace._trace.tracer 0.101 ms (0.04%)
ddtrace.internal.debug 0.037 ms (0.02%)
ddtrace._trace.context 0.050 ms (0.02%)
ddtrace._monkey 0.190 ms (0.08%)
ddtrace.appsec._listeners 0.107 ms (0.05%)
ddtrace.internal.core 0.087 ms (0.04%)
ddtrace.internal.core.event_hub 0.087 ms (0.04%)
ddtrace.settings.asm 0.042 ms (0.02%)
ddtrace.internal._unpatched 0.050 ms (0.02%)
json 0.022 ms (0.01%)
json.decoder 0.022 ms (0.01%)
json.scanner 0.022 ms (0.01%)
_json 0.022 ms (0.01%)
ddtrace.bootstrap.sitecustomize 5.023 ms (2.15%)
ddtrace.bootstrap.preload 4.497 ms (1.92%)
ddtrace.internal.remoteconfig.client 1.194 ms (0.51%)
ddtrace.internal.remoteconfig.constants 0.019 ms (0.01%)
ddtrace.settings.profiling 0.577 ms (0.25%)
ddtrace.vendor.psutil 0.410 ms (0.18%)
ddtrace.vendor.psutil._pslinux 0.192 ms (0.08%)
ddtrace.vendor.psutil._psutil_linux 0.029 ms (0.01%)
glob 0.028 ms (0.01%)
ddtrace.vendor.psutil._common 0.100 ms (0.04%)
ddtrace.vendor.psutil._compat 0.022 ms (0.01%)
ddtrace.internal.datadog.profiling.ddup 0.054 ms (0.02%)
ddtrace.internal.datadog.profiling.ddup._ddup 0.054 ms (0.02%)
ddtrace.internal.datadog.profiling.stack_v2 0.027 ms (0.01%)
ddtrace.internal.datadog.profiling.stack_v2._stack_v2 0.027 ms (0.01%)
ddtrace.internal.runtime.runtime_metrics 0.362 ms (0.15%)
ddtrace.internal.runtime.metric_collectors 0.322 ms (0.14%)
ddtrace.internal.runtime.collector 0.322 ms (0.14%)
ddtrace.internal.products 0.260 ms (0.11%)
importlib.metadata 0.260 ms (0.11%)
zipfile 0.072 ms (0.03%)
csv 0.064 ms (0.03%)
_csv 0.038 ms (0.02%)
importlib.metadata._meta 0.024 ms (0.01%)
ddtrace.internal.symbol_db.remoteconfig 0.173 ms (0.07%)
ddtrace.internal.symbol_db.symbols 0.103 ms (0.04%)
multiprocessing 0.153 ms (0.07%)
multiprocessing.context 0.153 ms (0.07%)
multiprocessing.reduction 0.153 ms (0.07%)
pickle 0.125 ms (0.05%)
_pickle 0.032 ms (0.01%)
_compat_pickle 0.024 ms (0.01%)
ddtrace.internal.flare.flare 0.126 ms (0.05%)
logging.handlers 0.060 ms (0.03%)
ddtrace.settings.crashtracker 0.068 ms (0.03%)
ddtrace.internal.datadog.profiling.crashtracker 0.068 ms (0.03%)
ddtrace.internal.datadog.profiling.crashtracker._crashtracker 0.068 ms (0.03%)
multiprocessing.sharedctypes 0.063 ms (0.03%)
multiprocessing.heap 0.031 ms (0.01%)
mmap 0.031 ms (0.01%)
ddtrace.internal.remoteconfig.worker 0.056 ms (0.02%)
ddtrace.internal.remoteconfig._connectors 0.052 ms (0.02%)
ctypes 0.052 ms (0.02%)
_ctypes 0.052 ms (0.02%)
ddtrace.appsec._remoteconfiguration 0.046 ms (0.02%)
ddtrace.settings.dynamic_instrumentation 0.036 ms (0.02%)
ddtrace.settings.code_origin 0.025 ms (0.01%)
ddtrace.internal.remoteconfig._pubsub 0.015 ms (0.01%)
ddtrace._trace.trace_handlers 0.213 ms (0.09%)
ddtrace._trace._inferred_proxy 0.119 ms (0.05%)
ddtrace.propagation.http 0.119 ms (0.05%)
ddtrace.internal._tagset 0.039 ms (0.02%)
ddtrace.contrib.trace_utils 0.027 ms (0.01%)
ddtrace.contrib.internal.trace_utils 0.027 ms (0.01%)
ddtrace.contrib.internal.trace_utils_base 0.027 ms (0.01%)
ddtrace.appsec._common_module_patches 0.089 ms (0.04%)
ddtrace.appsec._asm_request_context 0.089 ms (0.04%)
ddtrace.appsec._utils 0.030 ms (0.01%)
shlex 0.036 ms (0.02%)

@pr-commenter
Copy link

pr-commenter bot commented May 27, 2025

Benchmarks

Benchmark execution time: 2025-05-28 09:30:43

Comparing candidate commit 85ab73a in PR branch dubloom/integration-telemetry-logs-refactoring with baseline commit 58700c8 in branch main.

Found 2 performance improvements and 10 performance regressions! Performance is the same for 503 metrics, 5 unstable metrics.

scenario:iast_aspects-ljust_aspect

  • 🟥 execution_time [+1.397µs; +1.503µs] or [+10.755%; +11.570%]

scenario:iast_aspects-lower_aspect

  • 🟥 execution_time [+220.254ns; +276.903ns] or [+9.717%; +12.216%]

scenario:iast_aspects-lstrip_aspect

  • 🟥 execution_time [+1.441µs; +1.645µs] or [+11.091%; +12.661%]

scenario:iast_aspects-ospathbasename_aspect

  • 🟥 execution_time [+899.025ns; +967.920ns] or [+21.229%; +22.856%]

scenario:iast_aspects-ospathnormcase_aspect

  • 🟥 execution_time [+326.387ns; +442.571ns] or [+9.435%; +12.793%]

scenario:iast_aspects-ospathsplit_aspect

  • 🟥 execution_time [+822.781ns; +943.426ns] or [+16.813%; +19.279%]

scenario:iast_aspects-replace_aspect

  • 🟥 execution_time [+633.585ns; +712.021ns] or [+13.373%; +15.029%]

scenario:iast_aspects-rstrip_aspect

  • 🟥 execution_time [+1.583µs; +1.666µs] or [+12.394%; +13.043%]

scenario:iast_aspects-strip_aspect

  • 🟥 execution_time [+1.552µs; +1.648µs] or [+11.919%; +12.656%]

scenario:iast_aspects-upper_aspect

  • 🟥 execution_time [+204.327ns; +267.104ns] or [+9.032%; +11.807%]

scenario:iastdjangostartup-appsec

  • 🟩 execution_time [-1.077s; -0.971s] or [-54.785%; -49.368%]

scenario:iastdjangostartup-tracer

  • 🟩 execution_time [-887.173ms; -785.833ms] or [-50.421%; -44.661%]

@dubloom dubloom marked this pull request as draft May 27, 2025 15:36
@dubloom dubloom marked this pull request as ready for review May 28, 2025 08:23
@dubloom dubloom force-pushed the dubloom/integration-telemetry-logs-refactoring branch from 698887b to 4c81fcd Compare May 28, 2025 08:25
@dubloom dubloom force-pushed the dubloom/integration-telemetry-logs-refactoring branch from 4c81fcd to 74378d8 Compare May 28, 2025 08:45
@dubloom dubloom marked this pull request as draft May 28, 2025 09:32
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.

1 participant