@@ -45,6 +45,7 @@ def parse_version(version):
45
45
TELEMETRY_ENABLED = "DD_INJECTION_ENABLED" in os .environ
46
46
DEBUG_MODE = os .environ .get ("DD_TRACE_DEBUG" , "" ).lower () in ("true" , "1" , "t" )
47
47
INSTALLED_PACKAGES = {}
48
+ DDTRACE_VERSION = "unknown"
48
49
PYTHON_VERSION = "unknown"
49
50
PYTHON_RUNTIME = "unknown"
50
51
PKGS_ALLOW_LIST = {}
@@ -133,7 +134,7 @@ def create_count_metric(metric, tags=None):
133
134
}
134
135
135
136
136
- def gen_telemetry_payload (telemetry_events , ddtrace_version = "unknown" ):
137
+ def gen_telemetry_payload (telemetry_events , ddtrace_version ):
137
138
return {
138
139
"metadata" : {
139
140
"language_name" : "python" ,
@@ -233,6 +234,7 @@ def get_first_incompatible_sysarg():
233
234
234
235
235
236
def _inject ():
237
+ global DDTRACE_VERSION
236
238
global INSTALLED_PACKAGES
237
239
global PYTHON_VERSION
238
240
global PYTHON_RUNTIME
@@ -353,10 +355,7 @@ def _inject():
353
355
if not os .path .exists (site_pkgs_path ):
354
356
_log ("ddtrace site-packages not found in %r, aborting" % site_pkgs_path , level = "error" )
355
357
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 ]),
360
359
)
361
360
return
362
361
@@ -369,14 +368,9 @@ def _inject():
369
368
except BaseException as e :
370
369
_log ("failed to load ddtrace module: %s" % e , level = "error" )
371
370
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
+ ),
380
374
)
381
375
382
376
return
@@ -408,28 +402,18 @@ def _inject():
408
402
409
403
_log ("successfully configured ddtrace package, python path is %r" % os .environ ["PYTHONPATH" ])
410
404
TELEMETRY_DATA .append (
411
- gen_telemetry_payload (
405
+ create_count_metric (
406
+ "library_entrypoint.complete" ,
412
407
[
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 (),
419
409
],
420
- DDTRACE_VERSION ,
421
- )
410
+ ),
422
411
)
423
412
except Exception as e :
424
413
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
+ ),
433
417
)
434
418
_log ("failed to load ddtrace.bootstrap.sitecustomize: %s" % e , level = "error" )
435
419
return
@@ -451,12 +435,11 @@ def _inject():
451
435
_inject ()
452
436
except Exception as e :
453
437
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 ()])
457
439
)
458
440
finally :
459
441
if TELEMETRY_DATA :
460
- send_telemetry (TELEMETRY_DATA )
442
+ payload = gen_telemetry_payload (TELEMETRY_DATA , DDTRACE_VERSION )
443
+ send_telemetry (payload )
461
444
except Exception :
462
445
pass # absolutely never allow exceptions to propagate to the app
0 commit comments