in src/Traits/EndpointTrait.php [209:239]
protected function addOtelAttributes(
array $params,
array $requiredPathParts,
ServerRequestInterface $request,
string $endpoint
): ServerRequestInterface
{
// Check if OpenTelemetry instrumentation is enbaled
if (!getenv(OpenTelemetry::ENV_VARIABLE_ENABLED)) {
return $request;
}
$otel = [];
foreach ($requiredPathParts as $part) {
if (isset($params[$part])) {
$otel["db.elasticsearch.path_parts.$part"] = $params[$part];
}
}
if (in_array($endpoint, Client::SEARCH_ENDPOINTS)) {
$body = $request->getBody()->getContents();
if (!empty($body)) {
$otel['db.query.text'] = OpenTelemetry::redactBody($body);
}
}
return $request->withAttribute(
OpenTelemetry::PSR7_OTEL_ATTRIBUTE_NAME,
array_merge($otel, [
'db.system' => 'elasticsearch',
'db.operation.name' => $endpoint
])
);
}