in apm-agent-plugins/apm-es-restclient-plugin/apm-es-restclient-plugin-common/src/main/java/co/elastic/apm/agent/esrestclient/ElasticsearchRestClientInstrumentationHelper.java [90:139]
public Span<?> createClientSpan(String method, String httpPath, @Nullable HttpEntity httpEntity, boolean isSync) {
ElasticsearchEndpointDefinition endpoint = currentRequestEndpoint.getAndRemove();
Span<?> span = tracer.currentContext().createExitSpan();
// Don't record nested spans. In 5.x clients the instrumented sync method is calling the instrumented async method
if (span == null) {
return null;
}
span.withType(SPAN_TYPE)
.withSubtype(ELASTICSEARCH)
.withAction(SPAN_ACTION)
.withSync(isSync);
StringBuilder name = span.getAndOverrideName(AbstractSpan.PRIORITY_HIGH_LEVEL_FRAMEWORK);
if (endpoint != null) {
if (name != null) {
name.append("Elasticsearch: ").append(endpoint.getEndpointName());
}
span.withOtelAttribute("db.operation", endpoint.getEndpointName());
endpoint.addPathPartAttributes(httpPath, span);
} else {
if (name != null) {
name.append("Elasticsearch: ").append(method).append(" ").append(httpPath);
}
}
span.getContext().getDb().withType(ELASTICSEARCH);
span.getContext().getServiceTarget().withType(ELASTICSEARCH);
span.activate();
if (span.isSampled()) {
span.getContext().getHttp().withMethod(method);
if (WildcardMatcher.isAnyMatch(config.getCaptureBodyUrls(), httpPath)) {
if (httpEntity != null && httpEntity.isRepeatable()) {
try {
IOUtils.readUtf8Stream(httpEntity.getContent(), span.getContext().getDb().withStatementBuffer());
} catch (UnsupportedOperationException e) {
// special case for hibernatesearch versions pre 6.0:
// those don't support httpEntity.getContent() and throw an UnsupportedException when called.
unsupportedOperationOnceLogger.error(
"Failed to read Elasticsearch client query from request body, most likely because you are using hibernatesearch pre 6.0", e);
} catch (Exception e) {
logger.error("Failed to read Elasticsearch client query from request body", e);
}
}
}
}
return span;
}