Skip to content

Commit

Permalink
[pinpoint-apm#9669] Add log to accept event converter
Browse files Browse the repository at this point in the history
  • Loading branch information
jaehong-kim committed Jan 31, 2023
1 parent 5c9fb5e commit 1953691
Showing 1 changed file with 33 additions and 7 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,7 @@
import com.google.protobuf.StringValue;
import com.navercorp.pinpoint.bootstrap.context.TraceId;
import com.navercorp.pinpoint.common.annotations.VisibleForTesting;
import com.navercorp.pinpoint.common.profiler.logging.ThrottledLogger;
import com.navercorp.pinpoint.common.util.CollectionUtils;
import com.navercorp.pinpoint.common.util.IntStringValue;
import com.navercorp.pinpoint.common.util.StringUtils;
Expand Down Expand Up @@ -48,6 +49,8 @@
import com.navercorp.pinpoint.profiler.context.id.Shared;
import com.navercorp.pinpoint.profiler.context.id.TraceRoot;
import com.navercorp.pinpoint.profiler.context.thrift.MessageConverter;
import org.apache.logging.log4j.LogManager;
import org.apache.logging.log4j.Logger;

import java.util.ArrayList;
import java.util.List;
Expand All @@ -63,6 +66,9 @@ public class GrpcSpanMessageConverter implements MessageConverter<SpanType, Gene
public static final String DEFAULT_RPC_NAME = "UNKNOWN";
public static final String DEFAULT_REMOTE_ADDRESS = "UNKNOWN";

private final Logger logger = LogManager.getLogger(this.getClass());
private final ThrottledLogger throttledLogger = ThrottledLogger.getLogger(this.logger, 100);

private final String agentId;
private final short applicationServiceType;

Expand All @@ -79,7 +85,6 @@ public GrpcSpanMessageConverter(String agentId, short applicationServiceType,
this.agentId = Objects.requireNonNull(agentId, "agentId");
this.applicationServiceType = applicationServiceType;
this.spanProcessor = Objects.requireNonNull(spanProcessor, "spanProcessor");

}

@Override
Expand Down Expand Up @@ -174,13 +179,34 @@ private boolean isCompressedType(TraceId traceId) {
private PAcceptEvent newAcceptEvent(Span span) {
PAcceptEvent.Builder builder = PAcceptEvent.newBuilder();

final String remoteAddr = StringUtils.defaultIfEmpty(span.getRemoteAddr(), DEFAULT_REMOTE_ADDRESS);
builder.setRemoteAddr(remoteAddr);
boolean hasEmptyValue = false;
final String remoteAddr = span.getRemoteAddr();
if (StringUtils.isEmpty(remoteAddr)) {
hasEmptyValue = true;
builder.setRemoteAddr(DEFAULT_REMOTE_ADDRESS);
} else {
builder.setRemoteAddr(remoteAddr);
}

final Shared shared = span.getTraceRoot().getShared();
final String rpc = StringUtils.defaultIfEmpty(shared.getRpcName(), DEFAULT_RPC_NAME);
builder.setRpc(rpc);
final String endPoint = StringUtils.defaultIfEmpty(shared.getEndPoint(), DEFAULT_END_POINT);
builder.setEndPoint(endPoint);
final String rpc = shared.getRpcName();
if (StringUtils.isEmpty(rpc)) {
hasEmptyValue = true;
builder.setRpc(DEFAULT_RPC_NAME);
} else {
builder.setRpc(rpc);
}

final String endPoint = shared.getEndPoint();
if (StringUtils.isEmpty(endPoint)) {
hasEmptyValue = true;
builder.setEndPoint(DEFAULT_END_POINT);
} else {
builder.setEndPoint(endPoint);
}
if (hasEmptyValue) {
throttledLogger.warn("Empty value found. serviceType={}, remoteAddr={}, rpcName={}, endPoint={}", span.getServiceType(), remoteAddr, rpc, endPoint);
}

PParentInfo pParentInfo = newParentInfo(span);
if (pParentInfo != null) {
Expand Down

0 comments on commit 1953691

Please sign in to comment.