Skip to content
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

fix(lib-injection): fix incorrect telemetry data payload format [backport 2.19] #11990

Open
wants to merge 2 commits into
base: 2.19
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
51 changes: 17 additions & 34 deletions lib-injection/sources/sitecustomize.py
Original file line number Diff line number Diff line change
Expand Up @@ -45,6 +45,7 @@ def parse_version(version):
TELEMETRY_ENABLED = "DD_INJECTION_ENABLED" in os.environ
DEBUG_MODE = os.environ.get("DD_TRACE_DEBUG", "").lower() in ("true", "1", "t")
INSTALLED_PACKAGES = {}
DDTRACE_VERSION = "unknown"
PYTHON_VERSION = "unknown"
PYTHON_RUNTIME = "unknown"
PKGS_ALLOW_LIST = {}
Expand Down Expand Up @@ -133,7 +134,7 @@ def create_count_metric(metric, tags=None):
}


def gen_telemetry_payload(telemetry_events, ddtrace_version="unknown"):
def gen_telemetry_payload(telemetry_events, ddtrace_version):
return {
"metadata": {
"language_name": "python",
Expand Down Expand Up @@ -233,6 +234,7 @@ def get_first_incompatible_sysarg():


def _inject():
global DDTRACE_VERSION
global INSTALLED_PACKAGES
global PYTHON_VERSION
global PYTHON_RUNTIME
Expand Down Expand Up @@ -353,10 +355,7 @@ def _inject():
if not os.path.exists(site_pkgs_path):
_log("ddtrace site-packages not found in %r, aborting" % site_pkgs_path, level="error")
TELEMETRY_DATA.append(
gen_telemetry_payload(
[create_count_metric("library_entrypoint.abort", ["reason:missing_" + site_pkgs_path])],
DDTRACE_VERSION,
)
create_count_metric("library_entrypoint.abort", ["reason:missing_" + site_pkgs_path]),
)
return

Expand All @@ -369,14 +368,9 @@ def _inject():
except BaseException as e:
_log("failed to load ddtrace module: %s" % e, level="error")
TELEMETRY_DATA.append(
gen_telemetry_payload(
[
create_count_metric(
"library_entrypoint.error", ["error_type:import_ddtrace_" + type(e).__name__.lower()]
)
],
DDTRACE_VERSION,
)
create_count_metric(
"library_entrypoint.error", ["error_type:import_ddtrace_" + type(e).__name__.lower()]
),
)

return
Expand Down Expand Up @@ -408,28 +402,18 @@ def _inject():

_log("successfully configured ddtrace package, python path is %r" % os.environ["PYTHONPATH"])
TELEMETRY_DATA.append(
gen_telemetry_payload(
create_count_metric(
"library_entrypoint.complete",
[
create_count_metric(
"library_entrypoint.complete",
[
"injection_forced:" + str(runtime_incomp or integration_incomp).lower(),
],
)
"injection_forced:" + str(runtime_incomp or integration_incomp).lower(),
],
DDTRACE_VERSION,
)
),
)
except Exception as e:
TELEMETRY_DATA.append(
gen_telemetry_payload(
[
create_count_metric(
"library_entrypoint.error", ["error_type:init_ddtrace_" + type(e).__name__.lower()]
)
],
DDTRACE_VERSION,
)
create_count_metric(
"library_entrypoint.error", ["error_type:init_ddtrace_" + type(e).__name__.lower()]
),
)
_log("failed to load ddtrace.bootstrap.sitecustomize: %s" % e, level="error")
return
Expand All @@ -451,12 +435,11 @@ def _inject():
_inject()
except Exception as e:
TELEMETRY_DATA.append(
gen_telemetry_payload(
[create_count_metric("library_entrypoint.error", ["error_type:main_" + type(e).__name__.lower()])]
)
create_count_metric("library_entrypoint.error", ["error_type:main_" + type(e).__name__.lower()])
)
finally:
if TELEMETRY_DATA:
send_telemetry(TELEMETRY_DATA)
payload = gen_telemetry_payload(TELEMETRY_DATA, DDTRACE_VERSION)
send_telemetry(payload)
except Exception:
pass # absolutely never allow exceptions to propagate to the app
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
---
fixes:
- |
lib-injection: Fixes incorrect telemetry data payload format.
Loading