Skip to content

Commit 7a1d6b9

Browse files
github-actions[bot]brettlangdonerikayasuda
authored
fix(lib-injection): fix incorrect telemetry data payload format [backport 2.19] (#11990)
Co-authored-by: Brett Langdon <[email protected]> Co-authored-by: erikayasuda <[email protected]>
1 parent a08f68a commit 7a1d6b9

File tree

2 files changed

+21
-34
lines changed

2 files changed

+21
-34
lines changed

lib-injection/sources/sitecustomize.py

Lines changed: 17 additions & 34 deletions
Original file line numberDiff line numberDiff line change
@@ -45,6 +45,7 @@ def parse_version(version):
4545
TELEMETRY_ENABLED = "DD_INJECTION_ENABLED" in os.environ
4646
DEBUG_MODE = os.environ.get("DD_TRACE_DEBUG", "").lower() in ("true", "1", "t")
4747
INSTALLED_PACKAGES = {}
48+
DDTRACE_VERSION = "unknown"
4849
PYTHON_VERSION = "unknown"
4950
PYTHON_RUNTIME = "unknown"
5051
PKGS_ALLOW_LIST = {}
@@ -133,7 +134,7 @@ def create_count_metric(metric, tags=None):
133134
}
134135

135136

136-
def gen_telemetry_payload(telemetry_events, ddtrace_version="unknown"):
137+
def gen_telemetry_payload(telemetry_events, ddtrace_version):
137138
return {
138139
"metadata": {
139140
"language_name": "python",
@@ -233,6 +234,7 @@ def get_first_incompatible_sysarg():
233234

234235

235236
def _inject():
237+
global DDTRACE_VERSION
236238
global INSTALLED_PACKAGES
237239
global PYTHON_VERSION
238240
global PYTHON_RUNTIME
@@ -353,10 +355,7 @@ def _inject():
353355
if not os.path.exists(site_pkgs_path):
354356
_log("ddtrace site-packages not found in %r, aborting" % site_pkgs_path, level="error")
355357
TELEMETRY_DATA.append(
356-
gen_telemetry_payload(
357-
[create_count_metric("library_entrypoint.abort", ["reason:missing_" + site_pkgs_path])],
358-
DDTRACE_VERSION,
359-
)
358+
create_count_metric("library_entrypoint.abort", ["reason:missing_" + site_pkgs_path]),
360359
)
361360
return
362361

@@ -369,14 +368,9 @@ def _inject():
369368
except BaseException as e:
370369
_log("failed to load ddtrace module: %s" % e, level="error")
371370
TELEMETRY_DATA.append(
372-
gen_telemetry_payload(
373-
[
374-
create_count_metric(
375-
"library_entrypoint.error", ["error_type:import_ddtrace_" + type(e).__name__.lower()]
376-
)
377-
],
378-
DDTRACE_VERSION,
379-
)
371+
create_count_metric(
372+
"library_entrypoint.error", ["error_type:import_ddtrace_" + type(e).__name__.lower()]
373+
),
380374
)
381375

382376
return
@@ -408,28 +402,18 @@ def _inject():
408402

409403
_log("successfully configured ddtrace package, python path is %r" % os.environ["PYTHONPATH"])
410404
TELEMETRY_DATA.append(
411-
gen_telemetry_payload(
405+
create_count_metric(
406+
"library_entrypoint.complete",
412407
[
413-
create_count_metric(
414-
"library_entrypoint.complete",
415-
[
416-
"injection_forced:" + str(runtime_incomp or integration_incomp).lower(),
417-
],
418-
)
408+
"injection_forced:" + str(runtime_incomp or integration_incomp).lower(),
419409
],
420-
DDTRACE_VERSION,
421-
)
410+
),
422411
)
423412
except Exception as e:
424413
TELEMETRY_DATA.append(
425-
gen_telemetry_payload(
426-
[
427-
create_count_metric(
428-
"library_entrypoint.error", ["error_type:init_ddtrace_" + type(e).__name__.lower()]
429-
)
430-
],
431-
DDTRACE_VERSION,
432-
)
414+
create_count_metric(
415+
"library_entrypoint.error", ["error_type:init_ddtrace_" + type(e).__name__.lower()]
416+
),
433417
)
434418
_log("failed to load ddtrace.bootstrap.sitecustomize: %s" % e, level="error")
435419
return
@@ -451,12 +435,11 @@ def _inject():
451435
_inject()
452436
except Exception as e:
453437
TELEMETRY_DATA.append(
454-
gen_telemetry_payload(
455-
[create_count_metric("library_entrypoint.error", ["error_type:main_" + type(e).__name__.lower()])]
456-
)
438+
create_count_metric("library_entrypoint.error", ["error_type:main_" + type(e).__name__.lower()])
457439
)
458440
finally:
459441
if TELEMETRY_DATA:
460-
send_telemetry(TELEMETRY_DATA)
442+
payload = gen_telemetry_payload(TELEMETRY_DATA, DDTRACE_VERSION)
443+
send_telemetry(payload)
461444
except Exception:
462445
pass # absolutely never allow exceptions to propagate to the app
Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,4 @@
1+
---
2+
fixes:
3+
- |
4+
lib-injection: Fixes incorrect telemetry data payload format.

0 commit comments

Comments
 (0)