-
Notifications
You must be signed in to change notification settings - Fork 9
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
* feature(##72) Improve Logging: Fix Duplicate Entries, Implement High-Performance, Structured #72 * Exposed `HandlerType` in `MessageReceptionBuilder` * v5.1.0 --------- Co-authored-by: Mohamed Amine Bchir <[email protected]> Co-authored-by: Anis Tissaoui <[email protected]> Co-authored-by: Benjamin SPETH <[email protected]>
- Loading branch information
1 parent
42bc53a
commit 96d8322
Showing
25 changed files
with
589 additions
and
136 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
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/Ev.ServiceBus.Abstractions/Listeners/ITransactionManager.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 @@ | ||
using System; | ||
using System.Threading.Tasks; | ||
using Ev.ServiceBus.Abstractions.MessageReception; | ||
|
||
namespace Ev.ServiceBus.Abstractions.Listeners; | ||
|
||
public interface ITransactionManager | ||
{ | ||
public Task RunWithInTransaction( | ||
MessageExecutionContext executionContext, | ||
Func<Task> transaction); | ||
} |
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
15 changes: 15 additions & 0 deletions
15
src/Ev.ServiceBus.Abstractions/MessageReception/MessageExecutionContext.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,15 @@ | ||
namespace Ev.ServiceBus.Abstractions.MessageReception; | ||
|
||
public class MessageExecutionContext | ||
{ | ||
public string? ClientType { get; set; } | ||
public string? ResourceId { get; set; } | ||
public string? PayloadTypeId { get; set; } | ||
public string? MessageId { get; set; } | ||
public string? SessionId { get; set; } | ||
public string? HandlerName { get; set; } | ||
|
||
public string? DiagnosticId { get; set; } | ||
|
||
public string ExecutionName => $"{ClientType}/{ResourceId}/{PayloadTypeId}"; | ||
} |
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,43 @@ | ||
using Elastic.Apm; | ||
using Elastic.Apm.Api; | ||
using Ev.ServiceBus.Abstractions.Listeners; | ||
using Ev.ServiceBus.Abstractions.MessageReception; | ||
|
||
namespace Ev.ServiceBus.Apm; | ||
|
||
public class ApmTransactionManager : ITransactionManager | ||
{ | ||
public async Task RunWithInTransaction(MessageExecutionContext executionContext, Func<Task> transaction) | ||
{ | ||
if (IsTraceEnabled()) | ||
{ | ||
await Agent.Tracer.CaptureTransaction( | ||
executionContext.ExecutionName, | ||
ApiConstants.TypeMessaging, | ||
async () => | ||
{ | ||
Agent.Tracer.CurrentTransaction? | ||
.SetLabel(nameof(executionContext.ClientType), executionContext.ClientType); | ||
Agent.Tracer.CurrentTransaction? | ||
.SetLabel(nameof(executionContext.ResourceId), executionContext.ResourceId); | ||
Agent.Tracer.CurrentTransaction? | ||
.SetLabel(nameof(executionContext.PayloadTypeId), executionContext.PayloadTypeId); | ||
Agent.Tracer.CurrentTransaction? | ||
.SetLabel(nameof(executionContext.HandlerName), executionContext.HandlerName); | ||
Agent.Tracer.CurrentTransaction? | ||
.SetLabel(nameof(executionContext.SessionId), executionContext.SessionId); | ||
Agent.Tracer.CurrentTransaction? | ||
.SetLabel(nameof(executionContext.MessageId), executionContext.MessageId); | ||
await transaction(); | ||
}, | ||
DistributedTracingData.TryDeserializeFromString(executionContext.DiagnosticId)); | ||
} | ||
else | ||
{ | ||
await transaction(); | ||
} | ||
} | ||
|
||
private static bool IsTraceEnabled() | ||
=> Agent.IsConfigured && Agent.Config.Enabled && Agent.Tracer is not null; | ||
} |
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,18 @@ | ||
<Project Sdk="Microsoft.NET.Sdk"> | ||
|
||
<PropertyGroup> | ||
<TargetFrameworks>netstandard2.1;net6.0;net8.0</TargetFrameworks> | ||
<ImplicitUsings>enable</ImplicitUsings> | ||
<Nullable>enable</Nullable> | ||
<RootNamespace>Ev.Servicebus.Apm</RootNamespace> | ||
</PropertyGroup> | ||
|
||
<ItemGroup> | ||
<ProjectReference Include="..\Ev.ServiceBus\Ev.ServiceBus.csproj" /> | ||
</ItemGroup> | ||
|
||
<ItemGroup> | ||
<PackageReference Include="Elastic.Apm" Version="1.19.0" /> | ||
</ItemGroup> | ||
|
||
</Project> |
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,15 @@ | ||
using Ev.ServiceBus.Abstractions.Listeners; | ||
using Microsoft.Extensions.DependencyInjection; | ||
using Microsoft.Extensions.DependencyInjection.Extensions; | ||
|
||
namespace Ev.ServiceBus.Apm; | ||
|
||
public static class ServiceBusBuilderExtensions | ||
{ | ||
public static ServiceBusBuilder UseApm(this ServiceBusBuilder builder) | ||
{ | ||
builder.Services.RemoveAll<ITransactionManager>(); | ||
builder.Services.AddSingleton<ITransactionManager, ApmTransactionManager>(); | ||
return builder; | ||
} | ||
} |
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,20 @@ | ||
using System; | ||
using Microsoft.Extensions.Logging; | ||
|
||
namespace Ev.ServiceBus.HealthChecks; | ||
|
||
public static class LoggingExtensions | ||
{ | ||
public record HealthChecks(); | ||
|
||
private static readonly Action<ILogger, string, string, Exception?> LogAddingHealthCheck = | ||
LoggerMessage.Define<string, string>( | ||
LogLevel.Information, | ||
new EventId(1, nameof(AddingHealthCheck)), | ||
"Adding health check for {EVSB_Client} {EVSB_ResourceId}" | ||
); | ||
|
||
public static void AddingHealthCheck(this ILogger logger, string resourceId, string client) | ||
=> LogAddingHealthCheck(logger,client, resourceId, default); | ||
|
||
} |
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
21 changes: 21 additions & 0 deletions
21
src/Ev.ServiceBus/Exceptions/FailedToProcessMessageException.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,21 @@ | ||
using System; | ||
|
||
namespace Ev.ServiceBus.Exceptions; | ||
|
||
public class FailedToProcessMessageException( | ||
string? clientType, | ||
string? resourceId, | ||
string? messageId, | ||
string? payloadTypeId, | ||
string? sessionId, | ||
string? handlerName, | ||
Exception innerException) | ||
: Exception("Failed to process Message", innerException) | ||
{ | ||
public string? ClientType { get; } = clientType; | ||
public string? ResourceId { get; } = resourceId; | ||
public string? MessageId { get; } = messageId; | ||
public string? PayloadTypeId { get; } = payloadTypeId; | ||
public string? SessionId { get; } = sessionId; | ||
public string? HandlerName { get; } = handlerName; | ||
} |
Oops, something went wrong.