Code Duplication    Length = 27-27 lines in 2 locations

kytos/core/helpers.py 2 locations

@@ 241-267 (lines=27) @@
238
                    cls.controller.dead_letter.add_event(kytos_event)
239
            return result
240
241
        async def handler_context_apm(*args, apm_client=None):
242
            """Async handler's execution context with APM instrumentation."""
243
            cls, kytos_event = args[0], args[1]
244
            trace_parent = kytos_event.trace_parent
245
            tx_type = "kytos_event"
246
            tx = apm_client.begin_transaction(transaction_type=tx_type,
247
                                              trace_parent=trace_parent)
248
            kytos_event.trace_parent = tx.trace_parent
249
            tx.name = f"{kytos_event.name}@{cls.napp_id}"
250
            try:
251
                result = await handler(*args)
252
                tx.result = result
253
            except Exception as exc:
254
                result = None
255
                traceback_str = traceback.format_exc()
256
                LOG.error(f"alisten_to handler: {handler}, "
257
                          f"args: {args} traceback: {traceback_str}")
258
                if hasattr(cls, "controller"):
259
                    cls.controller.dead_letter.add_event(kytos_event)
260
                apm_client.capture_exception(
261
                    exc_info=(type(exc), exc, exc.__traceback__),
262
                    context={"args": args},
263
                    handled=False,
264
                )
265
            tx.end()
266
            apm_client.tracer.queue_func("transaction", tx.to_dict())
267
            return result
268
269
        handler_func, kwargs = handler_context, {}
270
        if get_apm_name() == "es":
@@ 151-177 (lines=27) @@
148
                    cls.controller.dead_letter.add_event(kytos_event)
149
            return result
150
151
        def handler_context_apm(*args, apm_client=None):
152
            """Handler's context for ThreadPool APM instrumentation."""
153
            cls, kytos_event = args[0], args[1]
154
            trace_parent = kytos_event.trace_parent
155
            tx_type = "kytos_event"
156
            tx = apm_client.begin_transaction(transaction_type=tx_type,
157
                                              trace_parent=trace_parent)
158
            kytos_event.trace_parent = tx.trace_parent
159
            tx.name = f"{kytos_event.name}@{cls.napp_id}"
160
            try:
161
                result = handler(*args)
162
                tx.result = result
163
            except Exception as exc:
164
                result = None
165
                traceback_str = traceback.format_exc()
166
                LOG.error(f"listen_to handler: {handler}, "
167
                          f"args: {args} traceback: {traceback_str}")
168
                if hasattr(cls, "controller"):
169
                    cls.controller.dead_letter.add_event(kytos_event)
170
                apm_client.capture_exception(
171
                    exc_info=(type(exc), exc, exc.__traceback__),
172
                    context={"args": args},
173
                    handled=False,
174
                )
175
            tx.end()
176
            apm_client.tracer.queue_func("transaction", tx.to_dict())
177
            return result
178
179
        handler_func, kwargs = handler_context, {}
180
        if get_apm_name() == "es":