class Flow2Handler implements Consumer<Event<? extends Payload>> {

    @Override
    public void accept(Event<? extends Payload> event) {
        String key = (String) event.getKey();
        Payload payload = event.getData();
        String flowId = getFlowId(event);
        String flowChainId = getFlowChainId(event);
        String flowTriggerUserCrn = getFlowTriggerUserCrn(event);
        Span activeSpan = tracer.activeSpan();
        SpanContext spanContext = event.getHeaders().get(FlowConstants.SPAN_CONTEXT);
        String operationName = event.getKey().toString();
        if (FlowTracingUtil.isActiveSpanReusable(activeSpan, spanContext, operationName)) {
            LOGGER.debug("Reusing existing span. {}", activeSpan.context());
            doAccept(event, key, payload, flowId, flowChainId, flowTriggerUserCrn, spanContext);
        } else {
            Span span = FlowTracingUtil.getSpan(tracer, operationName, spanContext, flowId, flowChainId, flowTriggerUserCrn);
            spanContext = FlowTracingUtil.useOrCreateSpanContext(spanContext, span);
            try (Scope ignored = tracer.activateSpan(span)) {
                doAccept(event, key, payload, flowId, flowChainId, flowTriggerUserCrn, spanContext);
            } finally {
                span.finish();
            }
        }
    }

}