: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)
| 109 | |
| 110 | |
| 111 | def 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 | |
| 154 | def get_trace_db_by_live_action(liveaction): |
no test coverage detected