Skip to content

feat: add injection metadata fields to telemetry forwarder #13679

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

Open
wants to merge 13 commits into
base: main
Choose a base branch
from

Conversation

sydney-tung
Copy link

@sydney-tung sydney-tung commented Jun 16, 2025

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:
Screenshot 2025-06-16 at 11 13 35 AM

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

  • 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

@sydney-tung sydney-tung requested review from brettlangdon, a team and natitsechanski June 17, 2025 18:44
sydney-tung and others added 3 commits June 17, 2025 14:54
Assigns result, result_reason, and result_class variables to telemetry data.
@sydney-tung sydney-tung force-pushed the sydney.tung/INPLAT-616-add-injection-metadata branch from baaf356 to 1ce9728 Compare June 17, 2025 18:55
Copy link
Contributor

github-actions bot commented Jun 17, 2025

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

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.

merge conflict, but otherwise lgtm.

make sure to add a release note, e.g. reno new <slug>, the release note should be written to customers not to peer devs.

@betterengineering betterengineering changed the title feat: add injection metadata to lib-injection feat: add injection metadata fields to telemetry forwarder Jun 17, 2025
Copy link
Contributor

github-actions bot commented Jun 17, 2025

Bootstrap import analysis

Comparison of import times between this PR and base.

Summary

The average import time from this PR is: 277 ± 4 ms.

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

The import time difference between this PR and base is: -1.3 ± 0.1 ms.

Import time breakdown

The following import paths have shrunk:

ddtrace.auto 1.948 ms (0.70%)
ddtrace.bootstrap.sitecustomize 1.273 ms (0.46%)
ddtrace.bootstrap.preload 1.273 ms (0.46%)
ddtrace.internal.remoteconfig.client 0.620 ms (0.22%)
ddtrace 0.675 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%)

@pr-commenter
Copy link

pr-commenter bot commented Jun 17, 2025

Benchmarks

Benchmark execution time: 2025-06-18 16:13:08

Comparing candidate commit a590aaa in PR branch sydney.tung/INPLAT-616-add-injection-metadata with baseline commit a4c9ba0 in branch main.

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

scenario:iastaspects-upper_aspect

  • 🟥 execution_time [+193.518ns; +233.032ns] or [+8.592%; +10.347%]

scenario:telemetryaddmetric-1-gauge-metric-1-times

  • 🟥 execution_time [+163.418ns; +239.341ns] or [+7.603%; +11.135%]

@sydney-tung sydney-tung marked this pull request as ready for review June 17, 2025 20:51
@sydney-tung sydney-tung requested review from a team as code owners June 17, 2025 20:51
@betterengineering betterengineering self-requested a review June 18, 2025 11:51
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.

just a few nits, then should be ready.

are there system tests that cover these new behaviors?

@@ -65,7 +68,6 @@ def parse_version(version):
SITE_PKGS_MARKER = "site-packages-ddtrace-py"
BOOTSTRAP_MARKER = "bootstrap"


Copy link
Member

Choose a reason for hiding this comment

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

this empty line is needed for style formatting

@@ -457,12 +479,18 @@ def _inject():
],
),
)
RESULT = "success"
RESULT_REASON = "Successfully configured ddtrace package"
RESULT_CLASS = "success"
Copy link
Member

Choose a reason for hiding this comment

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

We may want to denote if this was forced. Something like success_forced?

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.

3 participants