-
Notifications
You must be signed in to change notification settings - Fork 122
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
feat: global events and open telemetry instrumentation (#451)
Include events for message produce and consume: - MessageConsumeCompleted - MessageConsumeError - MessageConsumeStarted - MessageProduceCompleted - MessageProduceError - MessageProduceStarted Include OpenTelemetry support for traces and baggage signals.
- Loading branch information
1 parent
3912651
commit 0926b94
Showing
33 changed files
with
1,378 additions
and
25 deletions.
There are no files selected for viewing
This file contains 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 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,38 @@ | ||
namespace KafkaFlow.Configuration | ||
{ | ||
/// <summary> | ||
/// Provides access to events fired by the internals of the library | ||
/// </summary> | ||
public interface IGlobalEvents | ||
{ | ||
/// <summary> | ||
/// Gets the message consume completed event | ||
/// </summary> | ||
IEvent<MessageEventContext> MessageConsumeCompleted { get; } | ||
|
||
/// <summary> | ||
/// Gets the message consume error event | ||
/// </summary> | ||
IEvent<MessageErrorEventContext> MessageConsumeError { get; } | ||
|
||
/// <summary> | ||
/// Gets the message consume started event | ||
/// </summary> | ||
IEvent<MessageEventContext> MessageConsumeStarted { get; } | ||
|
||
/// <summary> | ||
/// Gets the message produce completed event | ||
/// </summary> | ||
IEvent<MessageEventContext> MessageProduceCompleted { get; } | ||
|
||
/// <summary> | ||
/// Gets the message produce error event | ||
/// </summary> | ||
IEvent<MessageErrorEventContext> MessageProduceError { get; } | ||
|
||
/// <summary> | ||
/// Gets the message produce started event | ||
/// </summary> | ||
IEvent<MessageEventContext> MessageProduceStarted { get; } | ||
} | ||
} |
This file contains 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 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,32 @@ | ||
namespace KafkaFlow | ||
Check warning on line 1 in src/KafkaFlow.Abstractions/IEvent.cs GitHub Actions / build
|
||
{ | ||
using System; | ||
using System.Threading.Tasks; | ||
|
||
/// <summary> | ||
/// Represents an Event to be subscribed. | ||
/// </summary> | ||
public interface IEvent | ||
{ | ||
/// <summary> | ||
/// Subscribes to the event. | ||
/// </summary> | ||
/// <param name="handler">The handler to be called when the event is fired.</param> | ||
/// <returns>Event subscription reference</returns> | ||
IEventSubscription Subscribe(Func<Task> handler); | ||
} | ||
|
||
/// <summary> | ||
/// Represents an Event to be subscribed. | ||
/// </summary> | ||
/// <typeparam name="TArg">The argument expected by the event.</typeparam> | ||
public interface IEvent<out TArg> | ||
{ | ||
/// <summary> | ||
/// Subscribes to the event. | ||
/// </summary> | ||
/// <param name="handler">The handler to be called when the event is fired.</param> | ||
/// <returns>Event subscription reference</returns> | ||
IEventSubscription Subscribe(Func<TArg, Task> handler); | ||
} | ||
} | ||
This file contains 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,13 @@ | ||
namespace KafkaFlow | ||
{ | ||
/// <summary> | ||
/// Represents an Event subscription. | ||
/// </summary> | ||
public interface IEventSubscription | ||
{ | ||
/// <summary> | ||
/// Cancels the subscription to the event. | ||
/// </summary> | ||
void Cancel(); | ||
} | ||
} |
This file contains 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 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,26 @@ | ||
namespace KafkaFlow | ||
{ | ||
using System; | ||
|
||
/// <summary> | ||
/// Represents the errors in message context used in the events | ||
/// </summary> | ||
public class MessageErrorEventContext : MessageEventContext | ||
{ | ||
/// <summary> | ||
/// Initializes a new instance of the <see cref="MessageErrorEventContext"/> class. | ||
/// </summary> | ||
/// <param name="messageContext">The message context</param> | ||
/// <param name="exception">The event exception</param> | ||
public MessageErrorEventContext(IMessageContext messageContext, Exception exception) | ||
: base(messageContext) | ||
{ | ||
this.Exception = exception; | ||
} | ||
|
||
/// <summary> | ||
/// Gets the exception | ||
/// </summary> | ||
public Exception Exception { get; } | ||
} | ||
} |
This file contains 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,22 @@ | ||
namespace KafkaFlow | ||
{ | ||
/// <summary> | ||
/// Represents a message context used in the events | ||
/// </summary> | ||
public class MessageEventContext | ||
{ | ||
/// <summary> | ||
/// Initializes a new instance of the <see cref="MessageEventContext"/> class. | ||
/// </summary> | ||
/// <param name="messageContext">The message context</param> | ||
public MessageEventContext(IMessageContext messageContext) | ||
{ | ||
this.MessageContext = messageContext; | ||
} | ||
|
||
/// <summary> | ||
/// Gets the message context | ||
/// </summary> | ||
public IMessageContext MessageContext { get; } | ||
} | ||
} |
This file contains 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 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
12 changes: 12 additions & 0 deletions
12
src/KafkaFlow.IntegrationTests/Core/Exceptions/ErrorExecutingMiddlewareException.cs
This file contains 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,12 @@ | ||
namespace KafkaFlow.IntegrationTests.Core.Exceptions | ||
{ | ||
using System; | ||
|
||
public class ErrorExecutingMiddlewareException : Exception | ||
{ | ||
public ErrorExecutingMiddlewareException(string middlewareName) | ||
: base($"Exception thrown executing {middlewareName}") | ||
{ | ||
} | ||
} | ||
} |
14 changes: 14 additions & 0 deletions
14
src/KafkaFlow.IntegrationTests/Core/Exceptions/PartitionAssignmentException.cs
This file contains 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,14 @@ | ||
namespace KafkaFlow.IntegrationTests.Core.Exceptions | ||
{ | ||
using System; | ||
|
||
public class PartitionAssignmentException : Exception | ||
{ | ||
private const string ExceptionMessage = "Partition assignment hasn't occurred yet."; | ||
|
||
public PartitionAssignmentException() | ||
: base(ExceptionMessage) | ||
{ | ||
} | ||
} | ||
} |
6 changes: 6 additions & 0 deletions
6
src/KafkaFlow.IntegrationTests/Core/Producers/JsonProducer2.cs
This file contains 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,6 @@ | ||
namespace KafkaFlow.IntegrationTests.Core.Producers | ||
{ | ||
internal class JsonProducer2 | ||
{ | ||
} | ||
} |
Oops, something went wrong.