Skip to content

Commit

Permalink
[pinpoint-apm#10041] Add auto option to profiler.span.collected.uri
Browse files Browse the repository at this point in the history
  • Loading branch information
ga-ram committed Jun 15, 2023
1 parent 7f01d6d commit a88bc20
Show file tree
Hide file tree
Showing 3 changed files with 21 additions and 11 deletions.
7 changes: 4 additions & 3 deletions agent/src/main/resources/pinpoint-root.config
Original file line number Diff line number Diff line change
Expand Up @@ -408,9 +408,10 @@ pinpoint.banner.configs=pinpoint.profiler.profiles.active,\
###########################################################
# SPAN COLLECTED URL TYPE #
###########################################################
# Collected URI Type for profiler : TEMPLATE (default), RAW
# Collected URI Type for profiler : TEMPLATE, RAW, AUTO (default)
# e.g.)
# Collected URI for each type for a request `/randomResponseTime/50` mapped to `@RequestMapping("/randomResponseTime/**")`
# TEMPLATE (default) : `/randomResponseTime/**`
# TEMPLATE : `/randomResponseTime/**`
# RAW : `/randomResponseTime/50`
profiler.span.collected.uri.type=TEMPLATE
# AUTO (default) : `/randomResponseTime/**` for supported frameworks, `/randomResponseTime/50` for unsupported frameworks
profiler.span.collected.uri.type=AUTO
Original file line number Diff line number Diff line change
Expand Up @@ -81,7 +81,7 @@ public class GrpcSpanMessageConverter implements MessageConverter<SpanType, Gene
private final PAnnotation.Builder pAnnotationBuilder = PAnnotation.newBuilder();

public enum SpanUriType {
TEMPLATE, RAW
TEMPLATE, RAW, AUTO
}

private final SpanUriType spanCollectedUriType;
Expand Down Expand Up @@ -196,12 +196,7 @@ private PAcceptEvent newAcceptEvent(Span span) {
}

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

if (StringUtils.isEmpty(rpc)) {
hasEmptyValue = true;
Expand All @@ -228,6 +223,20 @@ private PAcceptEvent newAcceptEvent(Span span) {
return builder.build();
}

private String getCollectedUri(Shared shared, SpanUriType spanCollectedUriType) {
if (spanCollectedUriType == SpanUriType.RAW) {
return shared.getRpcName();
} else if (spanCollectedUriType == SpanUriType.TEMPLATE){
return shared.getUriTemplate();
} else {
String uriTemplate = shared.getUriTemplate();
if (StringUtils.isEmpty(uriTemplate)) {
return shared.getRpcName();
}
return uriTemplate;
}
}

private PParentInfo newParentInfo(Span span) {
final PParentInfo.Builder builder = PParentInfo.newBuilder();
// For the Queue service type, the acceptorHost value can be stored even without the parentApplicationName value.
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -52,7 +52,7 @@ public GrpcSpanMessageConverterProvider(@AgentId String agentId, @ApplicationSer
this.applicationServiceTypeCode = applicationServiceType.getCode();
this.spanPostProcessor = Objects.requireNonNull(spanPostProcessor, "spanPostProcessor");
Objects.requireNonNull(profilerConfig, "profilerConfig");
this.spanCollectedUriType = profilerConfig.readString(SPAN_COLLECTED_URI_CONFIG, "TEMPLATE");
this.spanCollectedUriType = profilerConfig.readString(SPAN_COLLECTED_URI_CONFIG, "AUTO");
}

@Override
Expand Down

0 comments on commit a88bc20

Please sign in to comment.