Use ClassValue and full name cache in AWS SDK 1.1 (#1153)
* Use ClassValue and full name cache in AWS SDK 1.1 * Mysterious class * Muzzle
This commit is contained in:
parent
d21db7b0a6
commit
fa3ae0921f
|
@ -54,6 +54,7 @@ public final class AWSClientInstrumentation extends Instrumenter.Default {
|
||||||
public String[] helperClassNames() {
|
public String[] helperClassNames() {
|
||||||
return new String[] {
|
return new String[] {
|
||||||
packageName + ".AwsSdkClientTracer",
|
packageName + ".AwsSdkClientTracer",
|
||||||
|
packageName + ".AwsSdkClientTracer$NamesCache",
|
||||||
packageName + ".RequestMeta",
|
packageName + ".RequestMeta",
|
||||||
packageName + ".TracingRequestHandler",
|
packageName + ".TracingRequestHandler",
|
||||||
};
|
};
|
||||||
|
|
|
@ -56,7 +56,9 @@ public class AWSHttpClientInstrumentation extends Instrumenter.Default {
|
||||||
@Override
|
@Override
|
||||||
public String[] helperClassNames() {
|
public String[] helperClassNames() {
|
||||||
return new String[] {
|
return new String[] {
|
||||||
packageName + ".AwsSdkClientTracer", packageName + ".RequestMeta",
|
packageName + ".AwsSdkClientTracer",
|
||||||
|
packageName + ".AwsSdkClientTracer$NamesCache",
|
||||||
|
packageName + ".RequestMeta",
|
||||||
};
|
};
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -29,7 +29,6 @@ import io.opentelemetry.context.propagation.TextMapPropagator.Setter;
|
||||||
import io.opentelemetry.instrumentation.api.tracer.HttpClientTracer;
|
import io.opentelemetry.instrumentation.api.tracer.HttpClientTracer;
|
||||||
import io.opentelemetry.trace.Span;
|
import io.opentelemetry.trace.Span;
|
||||||
import java.net.URI;
|
import java.net.URI;
|
||||||
import java.util.Map;
|
|
||||||
import java.util.concurrent.ConcurrentHashMap;
|
import java.util.concurrent.ConcurrentHashMap;
|
||||||
|
|
||||||
public class AwsSdkClientTracer extends HttpClientTracer<Request<?>, Request<?>, Response<?>> {
|
public class AwsSdkClientTracer extends HttpClientTracer<Request<?>, Request<?>, Response<?>> {
|
||||||
|
@ -38,8 +37,7 @@ public class AwsSdkClientTracer extends HttpClientTracer<Request<?>, Request<?>,
|
||||||
|
|
||||||
public static final AwsSdkClientTracer TRACER = new AwsSdkClientTracer();
|
public static final AwsSdkClientTracer TRACER = new AwsSdkClientTracer();
|
||||||
|
|
||||||
private final Map<String, String> serviceNames = new ConcurrentHashMap<>();
|
private final NamesCache namesCache = new NamesCache();
|
||||||
private final Map<Class, String> operationNames = new ConcurrentHashMap<>();
|
|
||||||
|
|
||||||
public AwsSdkClientTracer() {}
|
public AwsSdkClientTracer() {}
|
||||||
|
|
||||||
|
@ -50,7 +48,7 @@ public class AwsSdkClientTracer extends HttpClientTracer<Request<?>, Request<?>,
|
||||||
}
|
}
|
||||||
String awsServiceName = request.getServiceName();
|
String awsServiceName = request.getServiceName();
|
||||||
Class<?> awsOperation = request.getOriginalRequest().getClass();
|
Class<?> awsOperation = request.getOriginalRequest().getClass();
|
||||||
return remapServiceName(awsServiceName) + "." + remapOperationName(awsOperation);
|
return qualifiedOperation(awsServiceName, awsOperation);
|
||||||
}
|
}
|
||||||
|
|
||||||
public Span startSpan(Request<?> request, RequestMeta requestMeta) {
|
public Span startSpan(Request<?> request, RequestMeta requestMeta) {
|
||||||
|
@ -95,18 +93,17 @@ public class AwsSdkClientTracer extends HttpClientTracer<Request<?>, Request<?>,
|
||||||
return super.onResponse(span, response);
|
return super.onResponse(span, response);
|
||||||
}
|
}
|
||||||
|
|
||||||
private String remapServiceName(String serviceName) {
|
private String qualifiedOperation(String service, Class<?> operation) {
|
||||||
if (!serviceNames.containsKey(serviceName)) {
|
ConcurrentHashMap<String, String> cache = namesCache.get(operation);
|
||||||
serviceNames.put(serviceName, serviceName.replace("Amazon", "").trim());
|
String qualified = cache.get(service);
|
||||||
|
if (qualified == null) {
|
||||||
|
qualified =
|
||||||
|
service.replace("Amazon", "").trim()
|
||||||
|
+ '.'
|
||||||
|
+ operation.getSimpleName().replace("Request", "");
|
||||||
|
cache.put(service, qualified);
|
||||||
}
|
}
|
||||||
return serviceNames.get(serviceName);
|
return qualified;
|
||||||
}
|
|
||||||
|
|
||||||
private String remapOperationName(Class<?> awsOperation) {
|
|
||||||
if (!operationNames.containsKey(awsOperation)) {
|
|
||||||
operationNames.put(awsOperation, awsOperation.getSimpleName().replace("Request", ""));
|
|
||||||
}
|
|
||||||
return operationNames.get(awsOperation);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
|
@ -143,4 +140,11 @@ public class AwsSdkClientTracer extends HttpClientTracer<Request<?>, Request<?>,
|
||||||
protected String getInstrumentationName() {
|
protected String getInstrumentationName() {
|
||||||
return "io.opentelemetry.auto.aws-sdk-1.11";
|
return "io.opentelemetry.auto.aws-sdk-1.11";
|
||||||
}
|
}
|
||||||
|
|
||||||
|
static final class NamesCache extends ClassValue<ConcurrentHashMap<String, String>> {
|
||||||
|
@Override
|
||||||
|
protected ConcurrentHashMap<String, String> computeValue(Class<?> type) {
|
||||||
|
return new ConcurrentHashMap<>();
|
||||||
|
}
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
Loading…
Reference in New Issue