-
-
Notifications
You must be signed in to change notification settings - Fork 803
Align messaging diagnostics #9488
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Merged
Merged
Changes from all commits
Commits
Show all changes
5 commits
Select commit
Hold shift + click to select a range
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -100,6 +100,7 @@ Linq | |
| Liquibase | ||
| Marek | ||
| matchesBrics | ||
| maxage | ||
| MCPEXP | ||
| MediatR | ||
| Memberwise | ||
|
|
||
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
85 changes: 85 additions & 0 deletions
85
src/Mocha/src/Mocha/Instrumentation/AggregateMessagingDiagnosticEvents.cs
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,85 @@ | ||
| using Mocha.Middlewares; | ||
|
|
||
| namespace Mocha; | ||
|
|
||
| internal sealed class AggregateMessagingDiagnosticEvents(IMessagingDiagnosticEventListener[] listeners) | ||
| : IMessagingDiagnosticEvents | ||
| { | ||
| public IDisposable Dispatch(IDispatchContext context) | ||
| { | ||
| var scopes = new IDisposable[listeners.Length]; | ||
|
|
||
| for (var i = 0; i < listeners.Length; i++) | ||
| { | ||
| scopes[i] = listeners[i].Dispatch(context); | ||
| } | ||
|
|
||
| return new AggregateActivityScope(scopes); | ||
| } | ||
|
|
||
| public void DispatchError(IDispatchContext context, Exception exception) | ||
| { | ||
| for (var i = 0; i < listeners.Length; i++) | ||
| { | ||
| listeners[i].DispatchError(context, exception); | ||
| } | ||
| } | ||
|
|
||
| public IDisposable Receive(IReceiveContext context) | ||
| { | ||
| var scopes = new IDisposable[listeners.Length]; | ||
|
|
||
| for (var i = 0; i < listeners.Length; i++) | ||
| { | ||
| scopes[i] = listeners[i].Receive(context); | ||
| } | ||
|
|
||
| return new AggregateActivityScope(scopes); | ||
| } | ||
|
|
||
| public void ReceiveError(IReceiveContext context, Exception exception) | ||
| { | ||
| for (var i = 0; i < listeners.Length; i++) | ||
| { | ||
| listeners[i].ReceiveError(context, exception); | ||
| } | ||
| } | ||
|
|
||
| public IDisposable Consume(IConsumeContext context) | ||
| { | ||
| var scopes = new IDisposable[listeners.Length]; | ||
|
|
||
| for (var i = 0; i < listeners.Length; i++) | ||
| { | ||
| scopes[i] = listeners[i].Consume(context); | ||
| } | ||
|
|
||
| return new AggregateActivityScope(scopes); | ||
| } | ||
|
|
||
| public void ConsumeError(IConsumeContext context, Exception exception) | ||
| { | ||
| for (var i = 0; i < listeners.Length; i++) | ||
| { | ||
| listeners[i].ConsumeError(context, exception); | ||
| } | ||
| } | ||
|
|
||
| private sealed class AggregateActivityScope(IDisposable[] scopes) : IDisposable | ||
| { | ||
| private bool _disposed; | ||
|
|
||
| public void Dispose() | ||
| { | ||
| if (!_disposed) | ||
| { | ||
| for (var i = 0; i < scopes.Length; i++) | ||
| { | ||
| scopes[i].Dispose(); | ||
| } | ||
|
|
||
| _disposed = true; | ||
| } | ||
| } | ||
| } | ||
| } |
9 changes: 9 additions & 0 deletions
9
src/Mocha/src/Mocha/Instrumentation/IMessagingDiagnosticEventListener.cs
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,9 @@ | ||
| namespace Mocha; | ||
|
|
||
| /// <summary> | ||
| /// Register an implementation of this interface in the DI container to | ||
| /// listen to diagnostic events. Multiple implementations can be registered | ||
| /// and they will all be called in registration order. | ||
| /// </summary> | ||
| /// <seealso cref="MessagingDiagnosticEventListener"/> | ||
| public interface IMessagingDiagnosticEventListener : IMessagingDiagnosticEvents; |
41 changes: 41 additions & 0 deletions
41
src/Mocha/src/Mocha/Instrumentation/IMessagingDiagnosticEvents.cs
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,41 @@ | ||
| using Mocha.Middlewares; | ||
|
|
||
| namespace Mocha; | ||
|
|
||
| /// <summary> | ||
| /// Provides diagnostic events that can be triggered by the messaging pipeline. | ||
| /// These events allow monitoring and instrumentation of dispatch, receive, and consume operations. | ||
| /// </summary> | ||
| /// <seealso cref="IMessagingDiagnosticEventListener"/> | ||
| public interface IMessagingDiagnosticEvents | ||
| { | ||
| /// <summary> | ||
| /// Called when a message begins dispatching. Returns a disposable scope. | ||
| /// </summary> | ||
| IDisposable Dispatch(IDispatchContext context); | ||
|
|
||
| /// <summary> | ||
| /// Called when an exception occurs during dispatch. | ||
| /// </summary> | ||
| void DispatchError(IDispatchContext context, Exception exception); | ||
|
|
||
| /// <summary> | ||
| /// Called when a message begins being received. Returns a disposable scope. | ||
| /// </summary> | ||
| IDisposable Receive(IReceiveContext context); | ||
|
|
||
| /// <summary> | ||
| /// Called when an exception occurs during receive. | ||
| /// </summary> | ||
| void ReceiveError(IReceiveContext context, Exception exception); | ||
|
|
||
| /// <summary> | ||
| /// Called when a message begins being consumed. Returns a disposable scope. | ||
| /// </summary> | ||
| IDisposable Consume(IConsumeContext context); | ||
|
|
||
| /// <summary> | ||
| /// Called when an exception occurs during consume. | ||
| /// </summary> | ||
| void ConsumeError(IConsumeContext context, Exception exception); | ||
| } |
37 changes: 37 additions & 0 deletions
37
src/Mocha/src/Mocha/Instrumentation/MessagingDiagnosticEventListener.cs
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,37 @@ | ||
| using Mocha.Middlewares; | ||
|
|
||
| namespace Mocha; | ||
|
|
||
| /// <summary> | ||
| /// A base class for diagnostic event listeners with default no-op implementations. | ||
| /// Extend this class and override the methods you need. | ||
| /// </summary> | ||
| /// <seealso cref="IMessagingDiagnosticEventListener"/> | ||
| public class MessagingDiagnosticEventListener : IMessagingDiagnosticEventListener | ||
| { | ||
| protected MessagingDiagnosticEventListener() { } | ||
|
|
||
| /// <summary> | ||
| /// Gets a shared no-op <see cref="IDisposable"/> scope. | ||
| /// Calling <see cref="IDisposable.Dispose"/> on this instance is safe and performs no operation. | ||
| /// Use this as a default return value from diagnostic methods when no diagnostic activity is needed. | ||
| /// </summary> | ||
| protected internal static IDisposable EmptyScope { get; } = new EmptyActivityScope(); | ||
|
|
||
| public virtual IDisposable Dispatch(IDispatchContext context) => EmptyScope; | ||
|
|
||
| public virtual void DispatchError(IDispatchContext context, Exception exception) { } | ||
|
|
||
| public virtual IDisposable Receive(IReceiveContext context) => EmptyScope; | ||
|
|
||
| public virtual void ReceiveError(IReceiveContext context, Exception exception) { } | ||
|
|
||
| public virtual IDisposable Consume(IConsumeContext context) => EmptyScope; | ||
|
|
||
| public virtual void ConsumeError(IConsumeContext context, Exception exception) { } | ||
|
|
||
| private sealed class EmptyActivityScope : IDisposable | ||
| { | ||
| public void Dispose() { } | ||
| } | ||
| } |
11 changes: 11 additions & 0 deletions
11
src/Mocha/src/Mocha/Instrumentation/NoopMessagingDiagnosticEvents.cs
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,11 @@ | ||
| namespace Mocha; | ||
|
|
||
| internal sealed class NoopMessagingDiagnosticEvents | ||
| : MessagingDiagnosticEventListener | ||
| { | ||
| private NoopMessagingDiagnosticEvents() | ||
| { | ||
| } | ||
|
|
||
| public static NoopMessagingDiagnosticEvents Instance { get; } = new(); | ||
| } |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Uh oh!
There was an error while loading. Please reload this page.