MCPcopy Create free account
hub / github.com/StackStorm/st2 / get_trace

Function get_trace

st2common/st2common/services/trace.py:111–151  ·  view source on GitHub ↗

:param trace_context: context object using which a trace can be found. :type trace_context: ``dict`` or ``TraceContext`` :param ignore_trace_tag: Even if a trace_tag is provided will be ignored. :type ignore_trace_tag: ``str`` :rtype: ``TraceDB``

(trace_context, ignore_trace_tag=False)

Source from the content-addressed store, hash-verified

109
110
111def get_trace(trace_context, ignore_trace_tag=False):
112 """
113 :param trace_context: context object using which a trace can be found.
114 :type trace_context: ``dict`` or ``TraceContext``
115
116 :param ignore_trace_tag: Even if a trace_tag is provided will be ignored.
117 :type ignore_trace_tag: ``str``
118
119 :rtype: ``TraceDB``
120 """
121
122 trace_context = _get_valid_trace_context(trace_context)
123
124 if not trace_context.id_ and not trace_context.trace_tag:
125 raise ValueError("Atleast one of id_ or trace_tag should be specified.")
126
127 if trace_context.id_:
128 try:
129 return Trace.get_by_id(trace_context.id_)
130 except (ValidationError, ValueError):
131 LOG.warning(
132 'Database lookup for Trace with id="%s" failed.',
133 trace_context.id_,
134 exc_info=True,
135 )
136 raise StackStormDBObjectNotFoundError(
137 'Unable to find Trace with id="%s"' % trace_context.id_
138 )
139
140 if ignore_trace_tag:
141 return None
142
143 traces = Trace.query(trace_tag=trace_context.trace_tag)
144
145 # Assume this method only handles 1 trace.
146 if len(traces) > 1:
147 raise UniqueTraceNotFoundException(
148 "More than 1 Trace matching %s found." % trace_context.trace_tag
149 )
150
151 return traces[0]
152
153
154def get_trace_db_by_live_action(liveaction):

Callers 2

Calls 5

_get_valid_trace_contextFunction · 0.85
get_by_idMethod · 0.45
queryMethod · 0.45

Tested by

no test coverage detected