Skip to content

Commit

Permalink
[pinpoint-apm#10041] Add collected uri type option for spans
Browse files Browse the repository at this point in the history
  • Loading branch information
ga-ram committed Jun 14, 2023
1 parent c19e994 commit 15645d4
Show file tree
Hide file tree
Showing 4 changed files with 37 additions and 6 deletions.
12 changes: 11 additions & 1 deletion agent/src/main/resources/pinpoint-root.config
Original file line number Diff line number Diff line change
Expand Up @@ -403,4 +403,14 @@ pinpoint.banner.configs=pinpoint.profiler.profiles.active,\
profiler.sampling.enable,\
profiler.sampling.type,\
profiler.sampling.counting.sampling-rate,\
profiler.sampling.percent.sampling-rate
profiler.sampling.percent.sampling-rate

###########################################################
# SPAN COLLECTED URL TYPE #
###########################################################
# Collected URI Type for profiler : TEMPLATE (default), RAW
# e.g.)
# Collected URI for each type for a request `/randomResponseTime/50` mapped to `@RequestMapping("/randomResponseTime/**")`
# TEMPLATE (default) : `/randomResponseTime/**`
# RAW : `/randomResponseTime/50`
profiler.span.collected.uri.type=TEMPLATE
Original file line number Diff line number Diff line change
Expand Up @@ -80,11 +80,19 @@ public class GrpcSpanMessageConverter implements MessageConverter<SpanType, Gene

private final PAnnotation.Builder pAnnotationBuilder = PAnnotation.newBuilder();

public enum SpanUriType {
TEMPLATE, RAW
}

private final SpanUriType spanCollectedUriType;

public GrpcSpanMessageConverter(String agentId, short applicationServiceType,
SpanProcessor<PSpan.Builder, PSpanChunk.Builder> spanProcessor) {
SpanProcessor<PSpan.Builder, PSpanChunk.Builder> spanProcessor,
String spanCollectedUriType) {
this.agentId = Objects.requireNonNull(agentId, "agentId");
this.applicationServiceType = applicationServiceType;
this.spanProcessor = Objects.requireNonNull(spanProcessor, "spanProcessor");
this.spanCollectedUriType = SpanUriType.valueOf(spanCollectedUriType);
}

@Override
Expand Down Expand Up @@ -188,7 +196,13 @@ private PAcceptEvent newAcceptEvent(Span span) {
}

final Shared shared = span.getTraceRoot().getShared();
final String rpc = shared.getRpcName();
final String rpc;
if (spanCollectedUriType == SpanUriType.RAW) {
rpc = shared.getRpcName();
} else {
rpc = shared.getUriTemplate();
}

if (StringUtils.isEmpty(rpc)) {
hasEmptyValue = true;
builder.setRpc(DEFAULT_RPC_NAME);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,7 @@
import com.google.inject.Inject;
import com.google.inject.Provider;
import com.google.protobuf.GeneratedMessageV3;
import com.navercorp.pinpoint.bootstrap.config.ProfilerConfig;
import com.navercorp.pinpoint.common.profiler.message.MessageConverter;
import com.navercorp.pinpoint.common.trace.ServiceType;
import com.navercorp.pinpoint.grpc.trace.PSpan;
Expand All @@ -34,22 +35,28 @@
* @author Woonduk Kang(emeroad)
*/
public class GrpcSpanMessageConverterProvider implements Provider<MessageConverter<SpanType, GeneratedMessageV3>> {
public static final String SPAN_COLLECTED_URI_CONFIG = "profiler.span.collected.uri.type";

private final String agentId;
private final short applicationServiceTypeCode;

private final SpanProcessor<PSpan.Builder, PSpanChunk.Builder> spanPostProcessor;

private final String spanCollectedUriType;

@Inject
public GrpcSpanMessageConverterProvider(@AgentId String agentId, @ApplicationServerType ServiceType applicationServiceType,
SpanProcessor<PSpan.Builder, PSpanChunk.Builder> spanPostProcessor) {
SpanProcessor<PSpan.Builder, PSpanChunk.Builder> spanPostProcessor,
ProfilerConfig profilerConfig) {
this.agentId = Objects.requireNonNull(agentId, "agentId");
this.applicationServiceTypeCode = applicationServiceType.getCode();
this.spanPostProcessor = Objects.requireNonNull(spanPostProcessor, "spanPostProcessor");
Objects.requireNonNull(profilerConfig, "profilerConfig");
this.spanCollectedUriType = profilerConfig.readString(SPAN_COLLECTED_URI_CONFIG, "TEMPLATE");
}

@Override
public MessageConverter<SpanType, GeneratedMessageV3> get() {
return new GrpcSpanMessageConverter(agentId, applicationServiceTypeCode, spanPostProcessor);
return new GrpcSpanMessageConverter(agentId, applicationServiceTypeCode, spanPostProcessor, spanCollectedUriType);
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -37,7 +37,7 @@ public class GrpcSpanProcessorV2Test {

private SpanProcessor<PSpan.Builder, PSpanChunk.Builder> spanProcessorProtoV2 = new GrpcSpanProcessorV2();

private GrpcSpanMessageConverter converter = new GrpcSpanMessageConverter("agentId", (short) 1, spanProcessorProtoV2);
private GrpcSpanMessageConverter converter = new GrpcSpanMessageConverter("agentId", (short) 1, spanProcessorProtoV2, "TEMPLATE");

@Test
public void preProcess() {
Expand Down

0 comments on commit 15645d4

Please sign in to comment.