61 Apply ID instrumentation to a component tree *if enabled*.
63 - No manual recursion (instrument_ids handles that)
64 - No structural ID rewrites
65 - Logs only when instrumentation debug level is high enough
68 if not instrumentation_active():
71 if instrumentation_verbose():
72 _dbg(
"INSTRUMENTATION",
"middleware",
"Applying instrumentation", level=3)
74 if isinstance(component, (list, tuple)):
75 return type(component)(instrument_ids(c)
for c
in component)
77 return instrument_ids(component)
86 Wrap all callbacks in app.callback_map so that their outputs
87 are automatically passed through apply_instrumentation().
89 This is the mechanism already proven to work in the main app.
92 callback_map = getattr(app,
"callback_map",
None)
95 if instrumentation_verbose():
96 _dbg(
"INSTRUMENTATION",
"dispatcher",
"No callback_map found", level=2)
99 for output_id, cb_def
in callback_map.items():
101 if "callback" not in cb_def:
102 if instrumentation_verbose():
106 f
"Skipping callback without 'callback' key: {output_id}",
111 original = cb_def[
"callback"]
114 if getattr(original,
"_is_instrumentation_wrapper",
False):
121 def make_wrapper(original_callback, out_id=output_id):
122 def wrapper(*args, **kwargs):
123 result = original_callback(*args, **kwargs)
125 if not instrumentation_active():
128 if instrumentation_verbose():
132 f
"Instrumenting callback output for {out_id}",
138 wrapper._is_instrumentation_wrapper =
True
141 cb_def[
"callback"] = make_wrapper(original)