You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
Is your feature request related to a problem? Please describe.
I want to log requests to Elastic, primarily for development/debug purposes
Describe the solution you'd like
It could either happen automatically (for example with a Logger property on ElasticSearchClientSettings), or through some callbacks.
Describe alternatives you've considered
I'm currently using this rather horrible hack:
private class LoggingHttpTransport(IElasticsearchClientSettings settings, ILogger logger) : DefaultHttpTransport<IElasticsearchClientSettings>(settings)
{
public override TResponse Request<TResponse>(HttpMethod method, string path, PostData? data, RequestParameters? requestParameters, in OpenTelemetryData openTelemetryData)
{
LogRequest(method, path, data);
return base.Request<TResponse>(method, path, data, requestParameters, in openTelemetryData);
}
public override Task<TResponse> RequestAsync<TResponse>(HttpMethod method, string path, PostData? data, RequestParameters? requestParameters, in OpenTelemetryData openTelemetryData, CancellationToken cancellationToken = default)
{
LogRequest(method, path, data);
return base.RequestAsync<TResponse>(method, path, data, requestParameters, in openTelemetryData, cancellationToken);
}
private void LogRequest(HttpMethod method, string path, PostData? data)
{
if (data != null)
{
using var ms = new MemoryStream();
data.Write(ms, Settings);
ms.Position = 0;
using var reader = new StreamReader(ms);
var serializedBody = reader.ReadToEnd();
logger.LogDebug("Calling elastic {Method} {Url}: {Body}", method, path, serializedBody);
}
else
{
logger.LogDebug("Calling elastic {Method} {Url}", method, path);
}
}
}
Happy to help! I'm closing this for now. Feel free to open another issue if you have more questions, or if the provided methods are not sufficient for your use-case.
Is your feature request related to a problem? Please describe.
I want to log requests to Elastic, primarily for development/debug purposes
Describe the solution you'd like
It could either happen automatically (for example with a Logger property on ElasticSearchClientSettings), or through some callbacks.
Describe alternatives you've considered
I'm currently using this rather horrible hack:
combined with this:
The text was updated successfully, but these errors were encountered: