Skip to content

fix(lib-injection): don't close stdout/stderr #13926

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

Merged

Conversation

betterengineering
Copy link
Member

@betterengineering betterengineering commented Jul 9, 2025

Overview

This commit resolves an issue where telemetry forwarding never completes when DD_APM_INSTRUMENTATION_DEBUG is enabled. We are closing the pipe from the Python side, which means the telemetry forwarder will fill the buffer and be unable to complete.

Test

I updated the telemetry-forwarder.sh to look like the following:

#!/usr/bin/env bash

# Generate 64KB of output on stderr (writes to fd 2)
# This creates 1024 lines of 64 bytes each = 64KB
for i in {1..1024}; do
  echo "This is a line of telemetry data to fill the pipe buffer ---- $i" >&2
done

# Write stdin + $1 to a file as before
echo "$1	$(</dev/stdin)" >>mock-telemetry.out

I then ran this on main and this branch to confirm mock-telemetry.out is written on this branch but never gets written on main:

DD_APM_INSTRUMENTATION_DEBUG="true" DD_INJECTION_ENABLED=true DD_TRACE_DEBUG=true PYTHONPATH=/Users/mark.spicer/go/src/github.com/DataDog/dd-trace-py/lib-injection/sources:$PYTHONPATH DD_TELEMETRY_FORWARDER_PATH=/Users/mark.spicer/go/src/github.com/DataDog/dd-trace-py/lib-injection/sources/telemetry-forwarder.sh python3 /Users/mark.spicer/go/src/github.com/DataDog/injector-dev/apps/python/app.py

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

github-actions bot commented Jul 9, 2025

CODEOWNERS have been resolved as:

releasenotes/notes/resolve-telemetry-forwarder-bug-e71f154d954eda4c.yaml  @DataDog/apm-python
lib-injection/sources/sitecustomize.py                                  @DataDog/apm-core-python

@betterengineering betterengineering marked this pull request as ready for review July 9, 2025 15:13
@betterengineering betterengineering requested review from a team as code owners July 9, 2025 15:13
Copy link
Member

@brettlangdon brettlangdon left a comment

Choose a reason for hiding this comment

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

is there a system test we are able to pair with this as well to show it is working in this PR?

Copy link
Contributor

github-actions bot commented Jul 9, 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: 283 ± 4 ms.

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

Import time breakdown

The following import paths have shrunk:

ddtrace.auto 1.901 ms (0.67%)
ddtrace.bootstrap.sitecustomize 1.225 ms (0.43%)
ddtrace.bootstrap.preload 1.225 ms (0.43%)
ddtrace.internal.remoteconfig.client 0.637 ms (0.23%)
ddtrace 0.676 ms (0.24%)
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%)

@betterengineering
Copy link
Member Author

@brettlangdon associated system-tests: DataDog/system-tests#4910

@pr-commenter
Copy link

pr-commenter bot commented Jul 9, 2025

Benchmarks

Benchmark execution time: 2025-07-14 21:28:20

Comparing candidate commit 089ecaa in PR branch mark.spicer/INPLAT-448-resolve-telemetry-forwarder-bug with baseline commit ab1f13d in branch main.

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

scenario:iastaspects-format_map_aspect

  • 🟥 execution_time [+442.538ns; +532.894ns] or [+13.671%; +16.463%]

scenario:iastaspects-replace_aspect

  • 🟥 execution_time [+661.858ns; +763.145ns] or [+13.967%; +16.104%]

scenario:iastaspectsospath-ospathjoin_aspect

  • 🟥 execution_time [+821.735ns; +996.715ns] or [+13.447%; +16.310%]

betterengineering and others added 3 commits July 9, 2025 17:01
This commit resolves an issue where telemetry forwarding never
completes when DD_APM_INSTRUMENTATION_DEBUG is enabled. We are closing
the pipe from the Python side, which means the telemetry forwarder will
fill the buffer and be unable to complete.
…eda4c.yaml

Co-authored-by: Brett Langdon <brett.langdon@datadoghq.com>
@betterengineering betterengineering force-pushed the mark.spicer/INPLAT-448-resolve-telemetry-forwarder-bug branch from 87367bf to 510f30f Compare July 9, 2025 21:02
@betterengineering betterengineering changed the title fix(INPLAT-448): don't close stdout/stderr fix(lib-inject): don't close stdout/stderr Jul 9, 2025
@betterengineering betterengineering changed the title fix(lib-inject): don't close stdout/stderr fix(lib-injection): don't close stdout/stderr Jul 9, 2025
Copy link
Member

@brettlangdon brettlangdon left a comment

Choose a reason for hiding this comment

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

if we can clean up the unnecessary changes to system-tests.yml, then lgtm

@betterengineering betterengineering force-pushed the mark.spicer/INPLAT-448-resolve-telemetry-forwarder-bug branch from 510f30f to cd01263 Compare July 10, 2025 16:58
Copy link
Member

@brettlangdon brettlangdon left a comment

Choose a reason for hiding this comment

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

system tests changes are coming, but we need the fix merged first.

I have verified with @betterengineering that locally the system tests are passing with this change.

@brettlangdon brettlangdon merged commit 904966d into main Jul 14, 2025
396 checks passed
@brettlangdon brettlangdon deleted the mark.spicer/INPLAT-448-resolve-telemetry-forwarder-bug branch July 14, 2025 21:29
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