public static OnsTraceTransferBean encoderFromContextBean()

in ons-core/ons-trace-core/src/main/java/org/apache/rocketmq/ons/open/trace/core/common/OnsTraceDataEncoder.java [99:161]


    public static OnsTraceTransferBean encoderFromContextBean(OnsTraceContext ctx) {
        if (ctx == null) {
            return null;
        }
        OnsTraceTransferBean transferBean = new OnsTraceTransferBean();
        StringBuilder sb = new StringBuilder(256);
        switch (ctx.getTraceType()) {
            case Pub: {
                OnsTraceBean bean = ctx.getTraceBeans().get(0);
                sb.append(ctx.getTraceType()).append(OnsTraceConstants.CONTENT_SPLITOR)//
                    .append(ctx.getTimeStamp()).append(OnsTraceConstants.CONTENT_SPLITOR)//
                    .append(ctx.getRegionId()).append(OnsTraceConstants.CONTENT_SPLITOR)//
                    .append(ctx.getGroupName()).append(OnsTraceConstants.CONTENT_SPLITOR)//
                    .append(bean.getTopic()).append(OnsTraceConstants.CONTENT_SPLITOR)//
                    .append(bean.getMsgId()).append(OnsTraceConstants.CONTENT_SPLITOR)//
                    .append(bean.getTags()).append(OnsTraceConstants.CONTENT_SPLITOR)//
                    .append(bean.getKeys()).append(OnsTraceConstants.CONTENT_SPLITOR)//
                    .append(bean.getStoreHost()).append(OnsTraceConstants.CONTENT_SPLITOR)//
                    .append(bean.getBodyLength()).append(OnsTraceConstants.CONTENT_SPLITOR)//
                    .append(ctx.getCostTime()).append(OnsTraceConstants.CONTENT_SPLITOR)//
                    .append(bean.getMsgType().ordinal()).append(OnsTraceConstants.CONTENT_SPLITOR)//
                    .append(bean.getOffsetMsgId()).append(OnsTraceConstants.CONTENT_SPLITOR)//
                    .append(ctx.isSuccess()).append(OnsTraceConstants.FIELD_SPLITOR);
            }
            break;
            case SubBefore: {
                for (OnsTraceBean bean : ctx.getTraceBeans()) {
                    sb.append(ctx.getTraceType()).append(OnsTraceConstants.CONTENT_SPLITOR)//
                        .append(ctx.getTimeStamp()).append(OnsTraceConstants.CONTENT_SPLITOR)//
                        .append(ctx.getRegionId()).append(OnsTraceConstants.CONTENT_SPLITOR)//
                        .append(ctx.getGroupName()).append(OnsTraceConstants.CONTENT_SPLITOR)//
                        .append(ctx.getRequestId()).append(OnsTraceConstants.CONTENT_SPLITOR)//
                        .append(bean.getMsgId()).append(OnsTraceConstants.CONTENT_SPLITOR)//
                        .append(bean.getRetryTimes()).append(OnsTraceConstants.CONTENT_SPLITOR)//
                        .append(bean.getKeys()).append(OnsTraceConstants.FIELD_SPLITOR);//
                }
            }
            break;
            case SubAfter: {
                for (OnsTraceBean bean : ctx.getTraceBeans()) {
                    sb.append(ctx.getTraceType()).append(OnsTraceConstants.CONTENT_SPLITOR)//
                        // .append(ctx.getTimeStamp()).append(OnsTraceConstants.CONTENT_SPLITOR)//
                        .append(ctx.getRequestId()).append(OnsTraceConstants.CONTENT_SPLITOR)//
                        .append(bean.getMsgId()).append(OnsTraceConstants.CONTENT_SPLITOR)//
                        .append(ctx.getCostTime()).append(OnsTraceConstants.CONTENT_SPLITOR)//
                        .append(ctx.isSuccess()).append(OnsTraceConstants.CONTENT_SPLITOR)//
                        .append(bean.getKeys()).append(OnsTraceConstants.CONTENT_SPLITOR)//
                        .append(ctx.getContextCode()).append(OnsTraceConstants.CONTENT_SPLITOR)//
                        .append(ctx.getExactlyOnceStatus()).append(OnsTraceConstants.FIELD_SPLITOR);
                }
            }
            break;
            default:
        }
        transferBean.setTransData(sb.toString());
        for (OnsTraceBean bean : ctx.getTraceBeans()) {
            transferBean.getTransKey().add(bean.getMsgId());
            if (bean.getKeys() != null && bean.getKeys().length() > 0) {
                transferBean.getTransKey().add(bean.getKeys());
            }
        }
        return transferBean;
    }