feat: add injection metadata fields to telemetry forwarder
Overview
This change adds additional fields to the telemetry forwarder used during injection. These fields will be used to add additional context that will be surfaced to the end user in the following Figma:
See Injection Metadata for more details.
Testing Strategy
I used this forwarder file to write output.json
#!/bin/bash
TELEMETRY_PAYLOAD=$(cat)
echo $TELEMETRY_PAYLOAD > /Users/sydney.tung/go/src/github.com/DataDog/sydney/output.json
I used this python app
#!/usr/bin/env python3
print("app complete")
I used this script
#!/bin/bash
[ -f /Users/sydney.tung/go/src/github.com/DataDog/sydney/output.json ] && rm /Users/sydney.tung/go/src/github.com/DataDog/sydney/output.json
export DD_APM_INSTRUMENTATION_DEBUG="true" #injector debug logging
export DD_INJECTION_ENABLED=true #injecting enable & forwarding
export DD_TRACE_DEBUG=true #debug logging for dd-trace-py
export PYTHONPATH=/Users/sydney.tung/go/src/github.com/DataDog/dd-trace-py/lib-injection/sources:$PYTHONPATH #path -> sitecustomize.py
export DD_TELEMETRY_FORWARDER_PATH=/Users/sydney.tung/go/src/github.com/DataDog/sydney/forwarder.sh #which forwarder excuted
python3 /Users/sydney.tung/go/src/github.com/DataDog/sydney/app.py #random app
cat /Users/sydney.tung/go/src/github.com/DataDog/sydney/output.json | jq
This is a sample output
{
"metadata": {
"language_name": "python",
"language_version": "3.13.3",
"runtime_name": "cpython",
"runtime_version": "3.13.3",
"tracer_version": "unknown",
"pid": 49533,
"result": "unknown",
"result_reason": "unknown",
"result_class": "unknown"
},
"points": [
{
"name": "library_entrypoint.error",
"tags": [
"error_type:main_filenotfounderror"
]
}
]
}
Checklist
- [x] 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
- [x] 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
CODEOWNERS have been resolved as:
releasenotes/notes/add-injection-metadata-fields-5f2d35cc9636c864.yaml @DataDog/apm-python
lib-injection/sources/sitecustomize.py @DataDog/apm-core-python
Bootstrap import analysis
Comparison of import times between this PR and base.
Summary
The average import time from this PR is: 290 ± 3 ms.
The average import time from base is: 294 ± 3 ms.
The import time difference between this PR and base is: -3.6 ± 0.1 ms.
Import time breakdown
The following import paths have shrunk:
ddtrace.auto
2.132 ms
(0.74%)
ddtrace.bootstrap.sitecustomize
1.439 ms
(0.50%)
ddtrace.bootstrap.preload
1.439 ms
(0.50%)
ddtrace.internal.remoteconfig.client
0.687 ms
(0.24%)
ddtrace
0.692 ms
(0.24%)
ddtrace.internal._unpatched
0.036 ms
(0.01%)
json
0.036 ms
(0.01%)
json.decoder
0.036 ms
(0.01%)
re
0.036 ms
(0.01%)
enum
0.036 ms
(0.01%)
types
0.036 ms
(0.01%)
Benchmarks
Benchmark execution time: 2025-06-30 17:40:22
Comparing candidate commit b118569f4832f8d0822da400497b5e2b26e3591f in PR branch sydney.tung/INPLAT-616-add-injection-metadata with baseline commit 009ecef543e543264ff260da4fc2f488020c4d23 in branch main.
Found 0 performance improvements and 2 performance regressions! Performance is the same for 546 metrics, 2 unstable metrics.
scenario:iastaspects-format_map_aspect
- 🟥
execution_time[+400.926ns; +483.686ns] or [+12.348%; +14.897%]
scenario:telemetryaddmetric-1-gauge-metric-1-times
- 🟥
execution_time[+193.846ns; +234.577ns] or [+9.368%; +11.336%]