io.crnk.spring.cloud.sleuth.internal.SleuthUtil Maven / Gradle / Ivy
package io.crnk.spring.cloud.sleuth.internal;
import java.util.Map;
import java.util.Set;
import io.crnk.core.engine.dispatcher.RepositoryRequestSpec;
import io.crnk.core.engine.information.resource.ResourceField;
import io.crnk.core.engine.internal.utils.StringUtils;
import io.crnk.core.engine.query.QueryAdapter;
import io.crnk.core.engine.registry.ResourceRegistry;
import io.crnk.core.queryspec.DefaultQuerySpecSerializer;
import io.crnk.core.queryspec.QuerySpec;
import io.crnk.core.queryspec.internal.QuerySpecAdapter;
// TODO replicated from BraveUtil
public class SleuthUtil {
private SleuthUtil() {
}
public static String getQuery(RepositoryRequestSpec request, ResourceRegistry resourceRegistry) {
QueryAdapter queryAdapter = request.getQueryAdapter();
StringBuilder builder = new StringBuilder();
builder.append("?");
if (queryAdapter instanceof QuerySpecAdapter) {
QuerySpec querySpec = request.getQuerySpec(queryAdapter.getResourceInformation());
DefaultQuerySpecSerializer serializer = new DefaultQuerySpecSerializer(resourceRegistry);
Map> parameters = serializer.serialize(querySpec);
for (Map.Entry> entry : parameters.entrySet()) {
if (builder.length() > 1) {
builder.append("&");
}
builder.append(entry.getKey());
builder.append("=");
builder.append(StringUtils.join(",", entry.getValue()));
}
return builder.toString();
}
return null;
}
public static String getSpanName(RepositoryRequestSpec request) {
ResourceField relationshipField = request.getRelationshipField();
StringBuilder pathBuilder = new StringBuilder();
String method = request.getMethod().toString();
pathBuilder.append(SleuthRepositoryFilter.COMPONENT_NAME);
pathBuilder.append(SleuthRepositoryFilter.COMPONENT_NAME_SEPARATOR);
pathBuilder.append(method);
pathBuilder.append(SleuthRepositoryFilter.COMPONENT_NAME_SEPARATOR);
pathBuilder.append("/");
if (relationshipField == null) {
pathBuilder.append(request.getQueryAdapter().getResourceInformation().getResourceType());
}
else {
pathBuilder.append(relationshipField.getParentResourceInformation().getResourceType());
}
Iterable