Skip to content

Commit 20bfbed

Browse files
authored
Expose ChannelDiagnosticsListener (#28)
1 parent 1198997 commit 20bfbed

File tree

2 files changed

+20
-12
lines changed

2 files changed

+20
-12
lines changed

src/Elastic.Channels/BufferedChannelBase.cs

Lines changed: 7 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -61,7 +61,9 @@ public abstract class BufferedChannelBase<TChannelOptions, TEvent, TResponse>
6161
private readonly CountdownEvent? _signal;
6262

6363
private readonly ChannelCallbackInvoker<TEvent, TResponse> _callbacks;
64-
private readonly IChannelDiagnosticsListener? _diagnosticsListener;
64+
65+
/// <inheritdoc cref="IChannelDiagnosticsListener"/>
66+
public IChannelDiagnosticsListener? DiagnosticsListener { get; }
6567

6668
/// <inheritdoc cref="BufferedChannelBase{TChannelOptions,TEvent,TResponse}"/>
6769
protected BufferedChannelBase(TChannelOptions options) : this(options, null) { }
@@ -73,14 +75,14 @@ protected BufferedChannelBase(TChannelOptions options, ICollection<IChannelCallb
7375
Options = options;
7476

7577
var listeners = callbackListeners == null ? new[] { Options } : callbackListeners.Concat(new[] { Options }).ToArray();
76-
_diagnosticsListener = listeners
78+
DiagnosticsListener = listeners
7779
.Select(l => (l is IChannelDiagnosticsListener c) ? c : null)
7880
.FirstOrDefault(e=> e != null);
79-
if (_diagnosticsListener == null && !options.DisableDiagnostics)
81+
if (DiagnosticsListener == null && !options.DisableDiagnostics)
8082
{
8183
// if no debug listener was already provided but was requested explicitly create one.
8284
var l = new ChannelDiagnosticsListener<TEvent, TResponse>(GetType().Name);
83-
_diagnosticsListener = l;
85+
DiagnosticsListener = l;
8486
listeners = listeners.Concat(new[] { l }).ToArray();
8587
}
8688
_callbacks = new ChannelCallbackInvoker<TEvent, TResponse>(listeners);
@@ -326,7 +328,7 @@ async Task<bool> AsyncSlowPath(IOutboundBuffer<TEvent> b)
326328

327329
/// <inheritdoc cref="object.ToString"/>>
328330
public override string ToString() =>
329-
_diagnosticsListener != null ? _diagnosticsListener.ToString() : base.ToString();
331+
DiagnosticsListener != null ? DiagnosticsListener.ToString() : base.ToString();
330332

331333
/// <inheritdoc cref="IDisposable.Dispose"/>
332334
public virtual void Dispose()

src/Elastic.Channels/Diagnostics/ChannelDiagnosticsListener.cs

Lines changed: 13 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -10,10 +10,18 @@
1010
namespace Elastic.Channels.Diagnostics;
1111

1212
/// <summary>
13-
/// Marker interface used by <see cref="BufferedChannelBase{TChannelOptions,TEvent,TResponse}"/> to improve
14-
/// its to string if a <see cref="ChannelDiagnosticsListener{TEvent,TResponse}"/> gets injected.
13+
/// Active Diagnostics listener used by <see cref="BufferedChannelBase{TChannelOptions,TEvent,TResponse}"/>
1514
/// </summary>
16-
internal interface IChannelDiagnosticsListener {}
15+
public interface IChannelDiagnosticsListener
16+
{
17+
/// <summary>
18+
/// Keeps track of the first observed exception to calls to <see cref="BufferedChannelBase{TChannelOptions,TEvent,TResponse}.Export"/>
19+
/// </summary>
20+
public Exception? ObservedException { get; }
21+
22+
/// <summary> Indicates if the overall publishing thus far was successful</summary>
23+
bool PublishSuccess { get; }
24+
}
1725

1826
/// <summary>
1927
/// A very rudimentary diagnostics object tracking various important metrics to provide insights into the
@@ -62,12 +70,10 @@ public ChannelDiagnosticsListener(string? name = null)
6270
ExportRetryableCountCallback = i => _returnedRetryableObjects = true;
6371
}
6472

65-
/// <summary>
66-
/// Keeps track of the first observed exception to calls to <see cref="BufferedChannelBase{TChannelOptions,TEvent,TResponse}.Export"/>
67-
/// </summary>
73+
/// <inheritdoc cref="IChannelDiagnosticsListener.ObservedException"/>
6874
public Exception? ObservedException { get; private set; }
6975

70-
/// <summary> Indicates if the overall publishing was successful</summary>
76+
/// <inheritdoc cref="IChannelDiagnosticsListener.PublishSuccess"/>
7177
public bool PublishSuccess => !_returnedRetryableObjects && ObservedException == null && _exportedBuffers > 0 && _maxRetriesExceeded == 0 && _items > 0;
7278

7379
/// <inheritdoc cref="IChannelCallbacks{TEvent,TResponse}.ExportExceptionCallback"/>

0 commit comments

Comments
 (0)