<commit_before>package com.nhn.pinpoint.common.bo;

import java.util.ArrayList;
import java.util.List;

import com.nhn.pinpoint.common.ServiceType;
import com.nhn.pinpoint.common.buffer.AutomaticBuffer;
import com.nhn.pinpoint.common.buffer.OffsetFixedBuffer;
import com.nhn.pinpoint.common.util.TransactionId;
import com.nhn.pinpoint.common.util.TransactionIdUtils;
import com.nhn.pinpoint.thrift.dto.TAnnotation;
import com.nhn.pinpoint.thrift.dto.TIntStringValue;
import com.nhn.pinpoint.thrift.dto.TSpan;
import com.nhn.pinpoint.common.buffer.Buffer;

/**
 * @author emeroad
 */
public class SpanBo implements com.nhn.pinpoint.common.bo.Span {

    private static final int VERSION_SIZE = 1;
    // version 0 = prefix의 사이즈를 int로

    private byte version = 0;


//    private AgentKeyBo agentKeyBo;
    private String agentId;
    private String applicationId;
    private long agentStartTime;

    private String traceAgentId;
    private long traceAgentStartTime;
    private long traceTransactionSequence;
    private long spanId;
    private long parentSpanId;

    private long startTime;
    private int elapsed;

    private String rpc;
    private ServiceType serviceType;
    private String endPoint;
    private int apiId;

    private List<AnnotationBo> annotationBoList;
    private short flag; // optional
    private int errCode;

    private List<SpanEventBo> spanEventBoList;

    private long collectorAcceptTime;

    private boolean hasException = false;
    private int exceptionId;
    private String exceptionMessage;
    private String exceptionClass;

    
    private String remoteAddr; // optional

    public SpanBo(TSpan span) {
        if (span == null) {
            throw new NullPointerException("span must not be null");
        }
        this.agentId = span.getAgentId();
        this.applicationId = span.getApplicationName();
        this.agentStartTime = span.getAgentStartTime();

        final TransactionId transactionId = TransactionIdUtils.parseTransactionId(span.getTransactionId());
        this.traceAgentId = transactionId.getAgentId();
        if (traceAgentId == null) {
            traceAgentId = this.agentId;
        }
        this.traceAgentStartTime = transactionId.getAgentStartTime();
        this.traceTransactionSequence = transactionId.getTransactionSequence();

        this.spanId = span.getSpanId();
        this.parentSpanId = span.getParentSpanId();

        this.startTime = span.getStartTime();
        this.elapsed = span.getElapsed();

        this.rpc = span.getRpc();

        this.serviceType = ServiceType.findServiceType(span.getServiceType());
        this.endPoint = span.getEndPoint();
        this.flag = span.getFlag();
        this.apiId = span.getApiId();

        this.errCode = span.getErr();
        
        this.remoteAddr = span.getRemoteAddr();

        final TIntStringValue exceptionInfo = span.getExceptionInfo();
        if (exceptionInfo != null) {
            this.hasException = true;
            this.exceptionId = exceptionInfo.getIntValue();
            this.exceptionMessage = exceptionInfo.getStringValue();
        }
        
        setAnnotationList(span.getAnnotations());
    }

    public SpanBo(String traceAgentId, long traceAgentStartTime, long traceTransactionSequence, long startTime, int elapsed, long spanId) {
        if (traceAgentId == null) {
            throw new NullPointerException("traceAgentId must not be null");
        }
        this.traceAgentId = traceAgentId;
        this.traceAgentStartTime = traceAgentStartTime;
        this.traceTransactionSequence = traceTransactionSequence;<commit_msg>[유치수] [PINPOINT-234] SpanBO에서 hasExceptin값 설정 기준이 잘못된 문제 수정. 임시로 수정한 것이고 판단 정책을 다시 세워야함.<commit_after>package com.nhn.pinpoint.common.bo;

import java.util.ArrayList;
import java.util.List;

import com.nhn.pinpoint.common.ServiceType;
import com.nhn.pinpoint.common.buffer.AutomaticBuffer;
import com.nhn.pinpoint.common.buffer.OffsetFixedBuffer;
import com.nhn.pinpoint.common.util.TransactionId;
import com.nhn.pinpoint.common.util.TransactionIdUtils;
import com.nhn.pinpoint.thrift.dto.TAnnotation;
import com.nhn.pinpoint.thrift.dto.TIntStringValue;
import com.nhn.pinpoint.thrift.dto.TSpan;
import com.nhn.pinpoint.common.buffer.Buffer;

/**
 * @author emeroad
 */
public class SpanBo implements com.nhn.pinpoint.common.bo.Span {

    private static final int VERSION_SIZE = 1;
    // version 0 = prefix의 사이즈를 int로

    private byte version = 0;


//    private AgentKeyBo agentKeyBo;
    private String agentId;
    private String applicationId;
    private long agentStartTime;

    private String traceAgentId;
    private long traceAgentStartTime;
    private long traceTransactionSequence;
    private long spanId;
    private long parentSpanId;

    private long startTime;
    private int elapsed;

    private String rpc;
    private ServiceType serviceType;
    private String endPoint;
    private int apiId;

    private List<AnnotationBo> annotationBoList;
    private short flag; // optional
    private int errCode;

    private List<SpanEventBo> spanEventBoList;

    private long collectorAcceptTime;

    private boolean hasException = false;
    private int exceptionId;
    private String exceptionMessage;
    private String exceptionClass;

    
    private String remoteAddr; // optional

    public SpanBo(TSpan span) {
        if (span == null) {
            throw new NullPointerException("span must not be null");
        }
        this.agentId = span.getAgentId();
        this.applicationId = span.getApplicationName();
        this.agentStartTime = span.getAgentStartTime();

        final TransactionId transactionId = TransactionIdUtils.parseTransactionId(span.getTransactionId());
        this.traceAgentId = transactionId.getAgentId();
        if (traceAgentId == null) {
            traceAgentId = this.agentId;
        }
        this.traceAgentStartTime = transactionId.getAgentStartTime();
        this.traceTransactionSequence = transactionId.getTransactionSequence();

        this.spanId = span.getSpanId();
        this.parentSpanId = span.getParentSpanId();

        this.startTime = span.getStartTime();
        this.elapsed = span.getElapsed();

        this.rpc = span.getRpc();

        this.serviceType = ServiceType.findServiceType(span.getServiceType());
        this.endPoint = span.getEndPoint();
        this.flag = span.getFlag();
        this.apiId = span.getApiId();

        this.errCode = span.getErr();
        
        this.remoteAddr = span.getRemoteAddr();
        
		if (span.isSetErr()) {
			this.hasException = true;
			// FIXME span.errCode는 span과 spanEvent의 에러를 모두 포함한 값.
			// exceptionInfo는 span자체의 에러정보이기 때문에 errCode가 0이 아니더라도 exceptionInfo는 null일 수 있음.
			final TIntStringValue exceptionInfo = span.getExceptionInfo();
			if (exceptionInfo != null) {
				this.exceptionId = exceptionInfo.getIntValue();
				this.exceptionMessage = exceptionInfo.getStringValue();
			}
		}
        
        setAnnotationList(span.getAnnotations());
    }

    public SpanBo(String traceAgentId, long traceAgentStartTime, long traceTransactionSequence, long startTime, int elapsed, long spanId) {
        if (traceAgentId == null) {
            throw new NullPointerException("traceAgentId must not be null");
        }
        this.traceAgentId = traceAgentId;
        this.traceAgentStartTime = traceAgentStartTime;
        this.traceTransactionSequence = traceTransactionSequence;
{'fraction_non_alphanumeric': 0.08858214955775931, 'fraction_numerical': 0.0013401232913428035, 'mean_word_length': 3.159977703455964, 'pattern_counts': {'":': 0, '<': 7, '<?xml version=': 0, '>': 7, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '7054397', 'n_tokens_mistral': 2184, 'n_tokens_neox': 2178, 'n_words': 481}