Skip to content
This repository was archived by the owner on Jan 23, 2024. It is now read-only.

Commit 37ff148

Browse files
cbaueratworkEmre Kultursay
authored andcommitted
Adding environment label collector for Python.
This collects all the borg information. trace/span ids can be added in a followup cl ------------- Created by MOE: https://github.com/google/moe MOE_MIGRATED_REVID=180696208
1 parent 0a5ddbe commit 37ff148

1 file changed

Lines changed: 13 additions & 3 deletions

File tree

src/googleclouddebugger/capture_collector.py

Lines changed: 13 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -41,6 +41,9 @@
4141
# Externally defined function to collect the end user id.
4242
user_id_collector = lambda: (None, None)
4343

44+
# Externally defined function to collect the end user id.
45+
breakpoint_labels_collector = lambda: {}
46+
4447
_PRIMITIVE_TYPES = (int, long, float, complex, types.StringTypes, bool,
4548
types.NoneType, types.SliceType, bytearray)
4649
_DATE_TYPES = (datetime.date, datetime.time, datetime.timedelta)
@@ -351,6 +354,7 @@ def Collect(self, top_frame):
351354
# didn't make it point to var_index of 0 ("buffer full")
352355
self.TrimVariableTable(num_vars)
353356

357+
self._CaptureEnvironmentLabels()
354358
self._CaptureRequestLogId()
355359
self._CaptureUserId()
356360

@@ -613,6 +617,15 @@ def ProcessBufferFull(variables):
613617
ProcessBufferFull(stack_frame['locals'])
614618
ProcessBufferFull(self._var_table)
615619

620+
def _CaptureEnvironmentLabels(self):
621+
"""Captures information about the environment, if possible."""
622+
if 'labels' not in self.breakpoint:
623+
self.breakpoint['labels'] = {}
624+
625+
if callable(breakpoint_labels_collector):
626+
for (key, value) in breakpoint_labels_collector().iteritems():
627+
self.breakpoint['labels'][key] = value
628+
616629
def _CaptureRequestLogId(self):
617630
"""Captures the request log id if possible.
618631
@@ -623,9 +636,6 @@ def _CaptureRequestLogId(self):
623636
request_log_id = request_log_id_collector()
624637
if request_log_id:
625638
# We have a request_log_id, save it into the breakpoint labels
626-
if 'labels' not in self.breakpoint:
627-
self.breakpoint['labels'] = {}
628-
629639
self.breakpoint['labels'][
630640
labels.Breakpoint.REQUEST_LOG_ID] = request_log_id
631641

0 commit comments

Comments
 (0)